Skip to content

Commit

Permalink
refactor tests for string filters w/ a predicate (e.g. body_equals)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlinsley committed Jan 12, 2014
1 parent dab3290 commit 9ed87b2
Showing 1 changed file with 11 additions and 32 deletions.
43 changes: 11 additions & 32 deletions spec/unit/filters/filter_form_builder_spec.rb
Expand Up @@ -102,41 +102,20 @@ def filter(name, options = {})

it "should select the option which is currently being filtered"

end

describe "string attribute with sub filters" do
let(:body) { filter :title_contains }

it "should generate a search field for a string attribute with query contains" do
expect(body).to have_tag("input", :attributes => { :name => "q[title_contains]"})
expect(body).to have_tag('label', 'Title contains')
end

it "should NOT generate a select option for contains" do
expect(body).to_not have_tag("option", "Contains", :attributes => { :value => 'title_contains' })
end

context "using starts_with and as" do
let(:body) { filter :title_starts_with }

it "should generate a search field for a string attribute with query starts_with" do
expect(body).to have_tag("input", :attributes => { :name => "q[title_starts_with]" })
end
end

context "using ends_with and as" do
let(:body) { filter :title_ends_with }

it "should generate a search field for a string attribute with query ends_with" do
expect(body).to have_tag("input", :attributes => { :name => "q[title_ends_with]" })
end
end
context "with predicate" do
%w[equals contains starts_with ends_with].each do |predicate|
describe '"'+predicate+'"' do
let(:body) { filter :"title_#{predicate}" }

context "using contains and NO AS defined" do
let(:body) { filter :title_contains }
it "shouldn't include a select field" do
expect(body).not_to have_tag "select"
end

it "should generate a search field for a string attribute with query contains" do
expect(body).to have_tag("input", :attributes => { :name => "q[title_contains]" })
it "should build correctly" do
expect(body).to have_tag("input", attributes: { name: "q[title_#{predicate}]" })
end
end
end
end
end
Expand Down

0 comments on commit 9ed87b2

Please sign in to comment.