From 90845ad3b52f5ac31e22f41bf423352fc0e48f2e Mon Sep 17 00:00:00 2001 From: Jesse LaRusso Date: Fri, 24 Aug 2018 16:13:09 -0400 Subject: [PATCH] Add feature specs for managing images --- spec/features/user_manages_image_spec.rb | 21 +++++++++++++++++++ spec/features/user_uploads_image_spec.rb | 26 ------------------------ spec/rails_helper.rb | 17 ++++++++++++++-- spec/support/auth_helpers.rb | 9 ++++++++ 4 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 spec/features/user_manages_image_spec.rb delete mode 100644 spec/features/user_uploads_image_spec.rb create mode 100644 spec/support/auth_helpers.rb diff --git a/spec/features/user_manages_image_spec.rb b/spec/features/user_manages_image_spec.rb new file mode 100644 index 0000000..4d88d25 --- /dev/null +++ b/spec/features/user_manages_image_spec.rb @@ -0,0 +1,21 @@ +require "rails_helper" + +describe "user manages images" do + it "uploads the image" do + sign_in + attach_file("Image", "#{Rails.root}/spec/fixtures/spectrum.jpg") + click_on("Create Image") + + expect(page).to have_css(".image") + end + + it "deletes the image" do + user = User.create(uid: 1) + Image.create(user: user, image: "#{Rails.root}/spec/fixtures/spectrum.jpg") + + sign_in + click_on("Delete") + + expect(page).not_to have_css(".image") + end +end diff --git a/spec/features/user_uploads_image_spec.rb b/spec/features/user_uploads_image_spec.rb deleted file mode 100644 index c30a75e..0000000 --- a/spec/features/user_uploads_image_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require "rails_helper" - -OmniAuth.config.test_mode = true - -OmniAuth.config.mock_auth[:twitter] = OmniAuth::AuthHash.new( - provider: "github", - uid: "1", -) - -describe "user uploads image" do - it "uploads the image" do - visit "/" - - sign_in - - save_and_open_page - - attach_file("Image", "#{Rails.root}/spec/fixtures/spectrum.jpg") - end - - def sign_in - within(".centre-stage") do - click_link("Sign in with GitHub") - end - end -end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index bcbc1a5..92feb71 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -8,7 +8,7 @@ if Rails.env.production? end require "rspec/rails" # Add additional requires below this line. Rails is not loaded until this point! - +require "shoulda/matchers" require "capybara/rspec" # Requires supporting ruby files with custom matchers and macros, etc, in @@ -24,7 +24,7 @@ require "capybara/rspec" # directory. Alternatively, in the individual `*_spec.rb` files, manually # require only the support files necessary. # -# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } +Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } # Checks for pending migrations and applies them before tests are run. # If you are not using ActiveRecord, you can remove these lines. @@ -63,6 +63,8 @@ RSpec.configure do |config| config.filter_rails_from_backtrace! # arbitrary gems may also be filtered via: # config.filter_gems_from_backtrace("gem name") + + config.include AuthHelpers, type: :feature end Shoulda::Matchers.configure do |config| @@ -71,3 +73,14 @@ Shoulda::Matchers.configure do |config| with.library :rails end end + +OmniAuth.config.test_mode = true +omniauth_hash = { + provider: "github", + uid: "1", + credentials: { + token: "12345" + } +} + +OmniAuth.config.add_mock(:github, omniauth_hash) diff --git a/spec/support/auth_helpers.rb b/spec/support/auth_helpers.rb new file mode 100644 index 0000000..6a9fb1b --- /dev/null +++ b/spec/support/auth_helpers.rb @@ -0,0 +1,9 @@ +module AuthHelpers + def sign_in + visit "/" + + within(".centre-stage") do + click_link("Sign in with GitHub") + end + end +end