Skip to content

Commit

Permalink
Fix Capybara nested blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
marnen committed Sep 21, 2011
1 parent 90034e1 commit d9ccc7c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
4 changes: 2 additions & 2 deletions spec/controllers/permissions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
it 'should show a list of unsubscribed calendars to subscribe to' do
@current_user.permissions.find_by_calendar_id(@three.id).should be_nil
get :index
response.body.should have_selector("table.unsubscribed tr#calendar_#{@three.id}") do |r|
r.should have_selector("a[href=#{subscribe_path(:calendar_id => @three.id)}]")
Capybara.string(response.body).find("table.unsubscribed tr#calendar_#{@three.id}").tap do |r|
r.should have_selector("a[href='#{subscribe_path(:calendar_id => @three.id)}']")
end
[@one, @two].each do |c|
response.body.should_not have_selector("table.unsubscribed tr#calendar_#{c.id}")
Expand Down
40 changes: 16 additions & 24 deletions spec/views/events/index.html.haml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,30 @@ def name_selector(string)
it "should have a date limiting form" do
render :file => 'events/index'
form = "form[action='#{url_for(params.merge :escape => false)}'][method=get]"
rendered.should have_selector("#{form}") do |e|
e.should have_selector('input') do |inputs|
inputs.should have_selector('[type=radio]') do |radios|
radios.should have_selector(name_selector('search[from_date_preset]')) do |from_date|
from_date.should have_selector('[value=today][checked]')
from_date.should have_selector('[value=earliest]')
from_date.should have_selector('[value=other]')
end
radios.should have_selector(name_selector 'search[to_date_preset]') do |to_date|
to_date.should have_selector('[value=latest][checked]')
to_date.should have_selector('[value=other]')
end
end
inputs.should have_selector(HTML::Selector.new('[type=submit]:not([name])'))
end
e.should have_selector('select') do |selects|
(1..3).each do |x|
selects.should have_selector(name_selector "search[from_date(#{x}i)]")
selects.should have_selector(name_selector "search[to_date(#{x}i)]")
selects.should_not have_selector(name_selector "search[calendar_id]")
end
Capybara.string(rendered).find("#{form}").tap do |e|
from_date_selector = "input[type='radio']#{name_selector('search[from_date_preset]')}"
e.should have_selector("#{from_date_selector}[value='today'][checked]")
e.should have_selector("#{from_date_selector}[value='earliest']")
e.should have_selector("#{from_date_selector}[value='other']")

to_date_selector = "input[type='radio']#{name_selector 'search[to_date_preset]'}"
e.should have_selector("#{to_date_selector}[value='latest'][checked]")
e.should have_selector("#{to_date_selector}[value='other']")
e.should have_selector("input[type='submit']:not([name])")

(1..3).each do |x|
e.should have_selector("select#{name_selector "search[from_date(#{x}i)]"}")
e.should have_selector("select#{name_selector "search[to_date(#{x}i)]"}")
end
e.should_not have_selector("select#{name_selector "search[calendar_id]"}")
end
end

it "should have a calendar option on the limiting form iff user has multiple calendars" do
User.current_user.stub!(:calendars).and_return((1..2).map{ Factory :calendar })
render :file => 'events/index'
form = "form[action='#{url_for(params.merge :escape => false)}'][method=get]"
rendered.should have_selector("#{form} select") do |selects|
selects.should have_selector(name_selector "search[calendar_id]")
end
rendered.should have_selector("#{form} select #{name_selector "search[calendar_id]"}")
end

it "should show a sort link in date and event column header" do
Expand Down

0 comments on commit d9ccc7c

Please sign in to comment.