diff options
| author | mo <mokha@cisco.com> | 2017-08-31 19:33:08 -0600 |
|---|---|---|
| committer | mo <mokha@cisco.com> | 2017-08-31 19:33:08 -0600 |
| commit | e5e38f1f1bcc7d7e3d616c4cef37e8453a3c6dde (patch) | |
| tree | 7d161f4475f24efca91aa92266c25c2fdcf63932 /spec | |
| parent | 63183ed8d366f80b58d7021af310cf60560d9123 (diff) | |
fix feature specs.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/features/add_to_favorites_spec.rb | 13 | ||||
| -rw-r--r-- | spec/features/change_password_spec.rb | 20 | ||||
| -rw-r--r-- | spec/features/change_profile_settings_spec.rb | 23 | ||||
| -rw-r--r-- | spec/features/upload_avatar_spec.rb | 15 | ||||
| -rw-r--r-- | spec/rails_helper.rb | 1 | ||||
| -rw-r--r-- | spec/support/authentication.rb | 6 |
6 files changed, 28 insertions, 50 deletions
diff --git a/spec/features/add_to_favorites_spec.rb b/spec/features/add_to_favorites_spec.rb index 42f7bb31..4ec6ac4a 100644 --- a/spec/features/add_to_favorites_spec.rb +++ b/spec/features/add_to_favorites_spec.rb @@ -4,19 +4,12 @@ describe "adding a cake to your favorites" do let!(:creation) { create(:creation, user: create(:user), photos: [create(:photo)]) } let!(:me) { create(:user, password: "password") } - before :each do - visit login_path - within('.form-inline') do - fill_in('session_username', with: me.email) - fill_in('session_password', with: "password") - end - click_button("Sign In") + before { http_login(me) } + + it "redirects you to the cake after" do visit root_path click_link(creation.name[0...12]) click_link_or_button("add-to-favorites-button") - end - - it "redirects you to the cake after" do expect(page).to have_content("This has been added to your favorites") end end diff --git a/spec/features/change_password_spec.rb b/spec/features/change_password_spec.rb index 1ba10715..b2fd2b3e 100644 --- a/spec/features/change_password_spec.rb +++ b/spec/features/change_password_spec.rb @@ -4,25 +4,17 @@ describe "changing my password", js: true do context "when changing my password" do let(:user) { create(:user, password: "password") } - before :each do - visit login_path - within(".form-inline") do - fill_in("session_username", with: user.email) - fill_in("session_password", with: "password") - end - click_button("Sign In") + before { http_login(user) } + + it "displays a confirmation message" do visit my_dashboard_path click_link("Account") within(".form-horizontal") do - fill_in("user_password", with: "mopass") - fill_in("user_password_confirmation", with: "mopass") + fill_in("user_password", with: "secret") + fill_in("user_password_confirmation", with: "secret") end click_button "Update password" - end - - it "displays a confirmation message" do - confirmation_message = I18n.translate("my.passwords.updated") - expect(page).to have_content(confirmation_message) + expect(page).to have_content(I18n.translate("my.passwords.updated")) end end end diff --git a/spec/features/change_profile_settings_spec.rb b/spec/features/change_profile_settings_spec.rb index 32e55860..5da192e7 100644 --- a/spec/features/change_profile_settings_spec.rb +++ b/spec/features/change_profile_settings_spec.rb @@ -1,26 +1,19 @@ require "rails_helper" describe "Change settings", js: true do - let(:user) { create(:user, :password => "password") } + let(:user) { create(:user, password: "password") } - before :each do - visit login_path - within('.form-inline') do - fill_in('session_username', :with => user.email) - fill_in('session_password', :with => "password") - end - click_button("Sign In") + before { http_login(user) } + + it "saves the changes properly" do visit my_settings_path within(".form-horizontal") do - fill_in('user_city', :with => "Calgary, Alberta, Canada") - fill_in('user_website', :with => "http://mokhan.ca/") - fill_in('user_twitter', :with => "mocheen") - fill_in('user_facebook', :with => "yeah right!") + fill_in('user_city', with: "Calgary, Alberta, Canada") + fill_in('user_website', with: "https://www.cakeside.com/") + fill_in('user_twitter', with: "cakeside") + fill_in('user_facebook', with: "cakeside") end click_button "Save changes" - end - - it "should save the changes properly" do expect(page).to have_content(I18n.translate(:profile_saved)) end end diff --git a/spec/features/upload_avatar_spec.rb b/spec/features/upload_avatar_spec.rb index 176c7aed..ad5c1f9d 100644 --- a/spec/features/upload_avatar_spec.rb +++ b/spec/features/upload_avatar_spec.rb @@ -2,23 +2,16 @@ require "rails_helper" describe "uploading an avatar", js: true do let(:user) { create(:user, :password => "password") } + let(:file) { File.expand_path(File.join(Rails.root, '/spec/fixtures/images/gorilla.jpg')) } - before :each do - visit login_path - within('.form-inline') do - fill_in('session_username', :with => user.email) - fill_in('session_password', :with => "password") - end - click_button("Sign In") + before { http_login(user) } + + it "displays a success message" do visit new_my_avatar_path - file = File.expand_path(File.join(Rails.root, '/spec/fixtures/images/gorilla.jpg')) within(".new_photo") do attach_file('photo_image', file) end click_button "Upload picture" - end - - it "should display a success message" do expect(page).to have_content(I18n.t(:avatar_uploaded)) end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c8862bdc..9f54576c 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -50,6 +50,7 @@ RSpec.configure do |config| # https://relishapp.com/rspec/rspec-rails/docs config.infer_spec_type_from_file_location! config.include Authentication, type: :controller + config.include Authentication::Capybara, type: :feature config.include WaitForAjax, type: :feature config.include FactoryGirl::Syntax::Methods diff --git a/spec/support/authentication.rb b/spec/support/authentication.rb index c56c027d..1145db3c 100644 --- a/spec/support/authentication.rb +++ b/spec/support/authentication.rb @@ -11,4 +11,10 @@ module Authentication encode_credentials(user.authentication_token) request.env["HTTP_AUTHORIZATION"] = encoded_credentials end + + module Capybara + def http_login(user) + LoginPage.new.visit_page.login_with(email: user.email, password: "password") + end + end end |
