require 'rails_helper'

describe Dunlop::UserFilter do
  let(:time) { '1981-03-09T13:33:04Z'.to_time }
  let(:model) { User }
  before { Timecop.freeze time }
  after  { Timecop.return      }
  subject { create :user }

  describe 'is_default' do
    it "creates" do
      user1 = create :user
      user2 = create :user
      filter1 = create 'dunlop/user_filter', user: user1, scope_key: 'dunlop:test1', filters: {a: 3, b: 8}, is_default: true
      filter2 = create 'dunlop/user_filter', user: user1, scope_key: 'dunlop:test2', filters: {a: 3, b: 8}, is_default: true
      filter3 = create 'dunlop/user_filter', user: user1, scope_key: 'dunlop:test1', filters: {a: 3, b: 8}, is_default: true
      filter4 = create 'dunlop/user_filter', user: user2, scope_key: 'dunlop:test1', filters: {a: 3, b: 8}, is_default: true

      filter1.reload.is_default.should be false # there can be only one
      filter2.reload.is_default.should be true # different scope key
      filter3.reload.is_default.should be true # there can only be the last one
      filter4.reload.is_default.should be true # different user
    end

  end
end
