mirror of
https://github.com/danbee/my-images
synced 2025-03-04 08:49:05 +00:00
Add feature specs for managing images
This commit is contained in:
parent
9eadfebe1c
commit
90845ad3b5
21
spec/features/user_manages_image_spec.rb
Normal file
21
spec/features/user_manages_image_spec.rb
Normal file
@ -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
|
||||
@ -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
|
||||
@ -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)
|
||||
|
||||
9
spec/support/auth_helpers.rb
Normal file
9
spec/support/auth_helpers.rb
Normal file
@ -0,0 +1,9 @@
|
||||
module AuthHelpers
|
||||
def sign_in
|
||||
visit "/"
|
||||
|
||||
within(".centre-stage") do
|
||||
click_link("Sign in with GitHub")
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user