Skip to content

Commit

Permalink
created have_filter_value matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
dubadub committed Jun 6, 2019
1 parent 4b5aa63 commit e9b09a3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ IFS=$'\n\t'
set -vx

bundle install

bundle exec appraisal install
# Do any other automated setup that you need to do here
2 changes: 1 addition & 1 deletion spec/active_record_intergration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Child < ActiveRecord::Base
end

it "doesn't modify query if filter has no values" do
filter = filter_class.new({})
filter = filter_class.new

expect(Parent.all.merge(filter).to_sql).to eq("SELECT \"parents\".* FROM \"parents\"")
end
Expand Down
29 changes: 13 additions & 16 deletions spec/filtered_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MyFilter < Filtered::Base

filter = MyFilter.new(status: "pending")

expect(filter.to_hash).to eq(status: "pending")
expect(filter).to have_filter_value(status: "pending")
end

it "works when no value present" do
Expand All @@ -47,7 +47,7 @@ class MyFilter < Filtered::Base

filter = MyFilter.new(status: "")

expect(filter.to_hash).to eq({})
expect(filter).to have_filter_value({})
end
end

Expand All @@ -61,7 +61,7 @@ class MyFilter < Filtered::Base

filter = MyFilter.new(status: "pending")

expect(filter.to_hash).to eq(status: "pending")
expect(filter).to have_filter_value(status: "pending")
end

it "gives access to filter instance" do
Expand All @@ -77,7 +77,7 @@ def prefixed(value)

filter = MyFilter.new(status: "pending")

expect(filter.to_hash).to eq(status: "pending")
expect(filter).to have_filter_value(status: "pending")
end

xit "raises an error if field definition doesn't return lambda" do
Expand Down Expand Up @@ -105,7 +105,7 @@ def use_field?

filter = MyFilter.new(status: "pending")

expect(filter.to_hash).to eq({})
expect(filter).to have_filter_value({})
end

xit "supports 'unless: :method_name'" do
Expand All @@ -119,7 +119,7 @@ def skip_field?

filter = MyFilter.new(status: "pending")

expect(filter.to_hash).to eq({})
expect(filter).to have_filter_value({})
end

it "supports 'if: ->() {...}'" do
Expand All @@ -129,7 +129,7 @@ class MyFilter < Filtered::Base

filter = MyFilter.new(status: "pending")

expect(filter.to_hash).to eq({})
expect(filter).to have_filter_value({})
end

it "supports 'if: ->() {...}'" do
Expand All @@ -139,7 +139,7 @@ class MyFilter < Filtered::Base

filter = MyFilter.new(status: "pending")

expect(filter.to_hash).to eq(status: "pending")
expect(filter).to have_filter_value(status: "pending")
end
end

Expand All @@ -153,7 +153,7 @@ class MyFilter < Filtered::Base

filter = MyFilter.new(status: "")

expect(filter.to_hash).to eq(status: "")
expect(filter).to have_filter_value(status: "")
end
end
end
Expand All @@ -167,7 +167,7 @@ class MyFilter < Filtered::Base

filter = MyFilter.new(status: nil)

expect(filter.to_hash).to eq(status: nil)
expect(filter).to have_filter_value(status: nil)
end
end
end
Expand All @@ -180,7 +180,7 @@ class MyNewFilter < Filtered::Base

filter = MyNewFilter.new

expect(filter.to_hash).to eq(year: 2019)
expect(filter).to have_filter_value(year: 2019)
end

it "supports 'default' as proc" do
Expand All @@ -194,7 +194,7 @@ class MyNewFilter < Filtered::Base
f.default_year = 2019
end

expect(filter.to_hash).to eq(year: 2019)
expect(filter).to have_filter_value(year: 2019)
end

it "supports 'default' as method name" do
Expand All @@ -208,14 +208,11 @@ def default_year

filter = MyNewFilter.new

expect(filter.to_hash).to eq(year: 2019)
expect(filter).to have_filter_value(year: 2019)
end
end

end



end
end
end
6 changes: 6 additions & 0 deletions spec/support/matchers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RSpec::Matchers.define :have_filter_value do |expected|
match do |actual|
actual.to_hash == expected
end

end

0 comments on commit e9b09a3

Please sign in to comment.