I have a nested form that has 4 checkboxes. Everything currently works in the browser, but I cannot get the capybara tests to uncheck and save.
Using Rails 4.2.2 and the latest versions of capaybara-webkit and rspec
settings.html.erb
<%= f.fields_for :preferences do |f| %> <div class="email-notifications-holder"> <div class="email-holder"> <%= f.label :new_match, "Getting a new match each week" %> <%= f.check_box :new_match, class: "checkbox new_match_email" %> </div> <div class="email-holder"> <%= f.label :match_reminder, "New matches Thursday reminder", class: "match_reminder_email" %> <%= f.check_box :match_reminder, default: true, class: "checkbox" %> </div> <div class="email-holder"> <%= f.label :accepted_match, "A Glassbreakers accepted a match", class: "accepted_match_email" %> <%= f.check_box :accepted_match, default: true, class: "checkbox" %> </div> <div class="email-holder"> <%= f.label :new_message, "Received a new message", class: "new_message_email" %> <%= f.check_box :new_message, default: true, class: "checkbox" %> </div> </div> <% end %>
edit_account_spec.rb
it "allows the user to opt out of new match email", :js do user = create(:user) preferences = create(:preference, user: user) sign_in(user) visit edit_user_path(user) click_tab(t("edit_user.tabs.settings")) find(:css, "#user_preferences_attributes_0_new_match").set(false) within "#button-container" do page.find('.save.main-save-button-edit').trigger('click') end visit edit_user_path(user) click_tab(t("edit_user.tabs.settings")) user.preferences.reload new_match_email_checkbox = find(".new_match_email") expect(new_match_email_checkbox.checked?).to be_falsey end
I tried to click it, unchecking it, checking it, clicking on it, wrapping it around the block, reloading db, etc.
new_match_email_checkbox = find(".new_match_email") within(".email-notifications-holder") do page.uncheck('Getting a new match each week') end new_match_email_checkbox.set(false)
source share