From 3950a0e442c65d65cd39b50cf0692e310d2fb4b5 Mon Sep 17 00:00:00 2001 From: Tobias Bohwalli Date: Sun, 2 Mar 2014 08:33:17 +0100 Subject: [PATCH] Fix engine issues and specs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix assets so feature specs can run. - Refactor test env - Fix 3 of 4 failing specs (the one left id for regression test for spree/spree#1687, probably something with rails4 sessions). The other specs was fixed by bypassing gateway error on checkout. - Refactor syntax for all specs —now they also readable :) - Minor fixes to the engine, noticed issues with devise that needed to be loaded before devise-encryptable. - Bumped devise and cancan + all dev dependencies. --- .gitignore | 1 + .rspec | 1 + .simplecov | 5 - .travis.yml | 1 + Gemfile | 28 +-- LICENSE => LICENSE.md | 2 +- README.md | 23 +- Rakefile | 14 +- Versionfile | 8 +- .../javascripts/spree/backend/spree_auth.js | 2 +- .../javascripts/spree/frontend/spree_auth.js | 2 +- .../stylesheets/spree/backend/spree_auth.css | 4 +- .../stylesheets/spree/frontend/spree_auth.css | 4 +- app/mailers/spree/user_mailer.rb | 2 +- app/models/spree/user.rb | 2 +- .../reset_password_instructions.text.erb | 10 +- lib/spree/auth/engine.rb | 1 + lib/spree_auth_devise.rb | 2 + script/rails | 8 +- .../spree/admin/users_controller_spec.rb | 26 +- .../spree/checkout_controller_spec.rb | 100 ++++---- .../spree/products_controller_spec.rb | 24 +- .../spree/users_controller_spec.rb | 20 +- spec/features/account_spec.rb | 86 ++++--- spec/features/admin/payment_methods_spec.rb | 18 +- spec/features/admin/products_spec.rb | 9 +- spec/features/admin/users_spec.rb | 80 +++---- spec/features/admin_permissions_spec.rb | 37 +-- spec/features/change_email_spec.rb | 22 +- spec/features/checkout_spec.rb | 226 ++++++++++-------- spec/features/order_spec.rb | 57 ++--- spec/features/password_reset_spec.rb | 26 +- spec/features/sign_in_spec.rb | 56 +++-- spec/features/sign_out_spec.rb | 28 +-- spec/features/sign_up_spec.rb | 38 +-- spec/features/user_spec.rb | 42 ++-- spec/mailers/user_mailer_spec.rb | 21 +- spec/models/order_spec.rb | 22 +- spec/models/user_spec.rb | 17 +- spec/spec_helper.rb | 55 ++--- spree_auth_devise.gemspec | 33 ++- 41 files changed, 593 insertions(+), 570 deletions(-) create mode 100644 .rspec delete mode 100644 .simplecov rename LICENSE => LICENSE.md (95%) diff --git a/.gitignore b/.gitignore index 36b6e2f0..1bf1adcf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ spec/dummy coverage Gemfile.lock *.swp +.rvmrc \ No newline at end of file diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..5052887a --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--color \ No newline at end of file diff --git a/.simplecov b/.simplecov deleted file mode 100644 index b6b01a84..00000000 --- a/.simplecov +++ /dev/null @@ -1,5 +0,0 @@ -require 'simplecov' - -# .simplecov -SimpleCov.start 'rails' do -end \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a4111344..5f88cfde 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: ruby rvm: - 1.9.3 - 2.0.0 + - 2.1.0 env: - DB=sqlite - DB=mysql diff --git a/Gemfile b/Gemfile index 0af73c82..dc8d2a73 100644 --- a/Gemfile +++ b/Gemfile @@ -1,31 +1,5 @@ source 'https://rubygems.org' -gem 'json' -gem 'sqlite3' -gem 'mysql2' -gem 'pg' -gem 'multi_json' -# Gems used only for assets and not required -# in production environments by default. -group :assets do - gem 'sass-rails', '~> 4.0.0' - gem 'coffee-rails', '~> 4.0.0' -end - -group :test do - gem 'rspec-rails', '~> 2.13.0' - gem 'factory_girl_rails', '~> 4.2.1' - gem 'email_spec', '~> 1.4.0' - - gem 'ffaker' - gem 'shoulda-matchers', '~> 1.4.2' - gem 'capybara', '~> 2.1' - gem 'database_cleaner', '~> 1.0.1' - gem 'selenium-webdriver', '2.35.1' - gem 'launchy' -end - -gem 'spree', :github => "spree/spree", :branch => "master" -gem 'pry' +gem 'spree', github: 'spree/spree', branch: 'master' gemspec diff --git a/LICENSE b/LICENSE.md similarity index 95% rename from LICENSE rename to LICENSE.md index 74f73e35..a434bf9e 100644 --- a/LICENSE +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2007-2012, Spree Commerce, Inc. and other contributors +Copyright (c) 2014, Spree Commerce, Inc. and other contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/README.md b/README.md index 62163119..d5343f4e 100644 --- a/README.md +++ b/README.md @@ -9,20 +9,22 @@ Provides authentication services for Spree, using the Devise gem. At one stage in the past, this used to be the auth component for Spree. If that's the feature that you're now finding lacking from Spree, that's easy fixed. -Just add this line to your Gemfile: +Just add this line to your `Gemfile`: +```ruby +gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master' +``` - gem "spree_auth_devise", :github => "spree/spree_auth_devise" - -Please ensure you're using the correct branch of spree_auth_devise relative to -your version of Spree. +Please ensure you're using the correct branch of `spree_auth_devise` relative to your version of Spree. Spree 1.3.x or 1-3-stable: - - gem 'spree_auth_devise', :github => "spree/spree_auth_devise", :branch => "1-3-stable" +```ruby +gem 'spree_auth_devise', :github => 'spree/spree_auth_devise', :branch => '1-3-stable' +``` Spree 1.2.x or 1-2-stable: - - gem 'spree_auth_devise', :github => "spree/spree_auth_devise", :branch => "1-2-stable" +```ruby +gem 'spree_auth_devise', :github => 'spree/spree_auth_devise', :branch => '1-2-stable' +``` Then run `bundle install`. Authentication will then work exactly as it did in previous versions of Spree. @@ -46,5 +48,4 @@ Then run the rspec tests. bundle exec rake spec -If everything doesn't pass on your machine (using Ruby (1.9.3 or 2.0.0) and (MySQL or PostgreSQL or SQLite3)) then we would consider that a bug. Please file a bug report on the issues page for this project with your test output -and we will investigate it. +If everything doesn't pass on your machine (using Ruby (1.9.3 or 2.0.0) and (MySQL or PostgreSQL or SQLite3)) then we would consider that a bug. Please file a bug report on the issues page for this project with your test output and we will investigate it. diff --git a/Rakefile b/Rakefile index 33eab64a..b8a1ab48 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,6 @@ -require 'rubygems' -require 'rake' -require 'rake/testtask' -require 'rake/packagetask' -require 'rubygems/package_task' +require 'bundler' +Bundler::GemHelper.install_tasks + require 'rspec/core/rake_task' require 'spree/testing_support/common_rake' @@ -10,12 +8,6 @@ RSpec::Core::RakeTask.new task :default => :spec -spec = eval(File.read('spree_auth_devise.gemspec')) - -Gem::PackageTask.new(spec) do |p| - p.gem_spec = spec -end - desc 'Generates a dummy app for testing' task :test_app do ENV['LIB_NAME'] = 'spree/auth' diff --git a/Versionfile b/Versionfile index 0a2e2f3b..ed3182e5 100644 --- a/Versionfile +++ b/Versionfile @@ -1,7 +1,5 @@ -# This file is used to designate compatibilty with different versions of Spree -# Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details - -"2.1.x" => { :branch => "master" } +"2.2.x" => { :branch => "2-2-stable" } +"2.1.x" => { :branch => "2-1-stable" } "2.0.x" => { :branch => "2-0-stable" } "1.3.x" => { :branch => "1-3-stable" } -"1.2.x" => { :branch => "1-2-stable" } +"1.2.x" => { :branch => "1-2-stable" } \ No newline at end of file diff --git a/app/assets/javascripts/spree/backend/spree_auth.js b/app/assets/javascripts/spree/backend/spree_auth.js index d924442c..f90877f9 100644 --- a/app/assets/javascripts/spree/backend/spree_auth.js +++ b/app/assets/javascripts/spree/backend/spree_auth.js @@ -1 +1 @@ -// Placeholder for backend dummy application \ No newline at end of file +//= require spree/backend \ No newline at end of file diff --git a/app/assets/javascripts/spree/frontend/spree_auth.js b/app/assets/javascripts/spree/frontend/spree_auth.js index d924442c..c9d16164 100644 --- a/app/assets/javascripts/spree/frontend/spree_auth.js +++ b/app/assets/javascripts/spree/frontend/spree_auth.js @@ -1 +1 @@ -// Placeholder for backend dummy application \ No newline at end of file +//= require spree/frontend \ No newline at end of file diff --git a/app/assets/stylesheets/spree/backend/spree_auth.css b/app/assets/stylesheets/spree/backend/spree_auth.css index d3dde966..a5cec986 100644 --- a/app/assets/stylesheets/spree/backend/spree_auth.css +++ b/app/assets/stylesheets/spree/backend/spree_auth.css @@ -1 +1,3 @@ -/* Placeholder for backend dummy app */ \ No newline at end of file +/* + *= require spree/backend +*/ diff --git a/app/assets/stylesheets/spree/frontend/spree_auth.css b/app/assets/stylesheets/spree/frontend/spree_auth.css index d3dde966..ad7db303 100644 --- a/app/assets/stylesheets/spree/frontend/spree_auth.css +++ b/app/assets/stylesheets/spree/frontend/spree_auth.css @@ -1 +1,3 @@ -/* Placeholder for backend dummy app */ \ No newline at end of file +/* + *= require spree/frontend +*/ diff --git a/app/mailers/spree/user_mailer.rb b/app/mailers/spree/user_mailer.rb index 5d19ed86..b4a6c600 100644 --- a/app/mailers/spree/user_mailer.rb +++ b/app/mailers/spree/user_mailer.rb @@ -4,7 +4,7 @@ def reset_password_instructions(user, token, *args) @edit_password_reset_url = spree.edit_spree_user_password_url(:reset_password_token => token) mail(:to => user.email, :from => from_address, - :subject => Spree::Config[:site_name] + ' ' + + :subject => Spree::Config[:site_name] + ' ' + I18n.t(:subject, :scope => [:devise, :mailer, :reset_password_instructions])) end end diff --git a/app/models/spree/user.rb b/app/models/spree/user.rb index 1cb39d90..5ec3f8cf 100644 --- a/app/models/spree/user.rb +++ b/app/models/spree/user.rb @@ -13,7 +13,7 @@ class User < ActiveRecord::Base users_table_name = User.table_name roles_table_name = Role.table_name - scope :admin, lambda { includes(:spree_roles).where("#{roles_table_name}.name" => "admin") } + scope :admin, -> { includes(:spree_roles).where("#{roles_table_name}.name" => "admin") } class DestroyWithOrdersError < StandardError; end diff --git a/app/views/spree/user_mailer/reset_password_instructions.text.erb b/app/views/spree/user_mailer/reset_password_instructions.text.erb index 712d9440..544d377f 100644 --- a/app/views/spree/user_mailer/reset_password_instructions.text.erb +++ b/app/views/spree/user_mailer/reset_password_instructions.text.erb @@ -1,10 +1,10 @@ -A request to reset your password has been made. -If you did not make this request, simply ignore this email. +A request to reset your password has been made. +If you did not make this request, simply ignore this email. If you did make this request just click the link below: - + <%= @edit_password_reset_url %> - -If the above URL does not work try copying and pasting it into your browser. + +If the above URL does not work try copying and pasting it into your browser. If you continue to have problem please feel free to contact us. diff --git a/lib/spree/auth/engine.rb b/lib/spree/auth/engine.rb index 3b33487e..0532e0df 100644 --- a/lib/spree/auth/engine.rb +++ b/lib/spree/auth/engine.rb @@ -1,3 +1,4 @@ +require 'devise' require 'devise-encryptable' module Spree diff --git a/lib/spree_auth_devise.rb b/lib/spree_auth_devise.rb index 34afb8c4..bf8807a6 100644 --- a/lib/spree_auth_devise.rb +++ b/lib/spree_auth_devise.rb @@ -1,2 +1,4 @@ +require 'spree_core' require 'spree/auth/devise' require 'spree/authentication_helpers' +require 'coffee_script' diff --git a/script/rails b/script/rails index 0b5d05e6..b886f236 100755 --- a/script/rails +++ b/script/rails @@ -1,5 +1,7 @@ #!/usr/bin/env ruby -# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. -ENGINE_PATH = File.expand_path('../..', __FILE__) -load File.expand_path('../../spec/dummy/script/rails', __FILE__) +ENGINE_ROOT = File.expand_path('../..', __FILE__) +ENGINE_PATH = File.expand_path('../../lib/spree/auth/engine', __FILE__) + +require 'rails/all' +require 'rails/engine/commands' \ No newline at end of file diff --git a/spec/controllers/spree/admin/users_controller_spec.rb b/spec/controllers/spree/admin/users_controller_spec.rb index 75635157..1a12ed01 100644 --- a/spec/controllers/spree/admin/users_controller_spec.rb +++ b/spec/controllers/spree/admin/users_controller_spec.rb @@ -14,44 +14,44 @@ user.spree_roles.clear end - it 'should grant access to users with an admin role' do + it 'grant access to users with an admin role' do user.spree_roles << Spree::Role.find_or_create_by(name: 'admin') spree_post :index - response.should render_template :index + expect(response).to render_template :index end it "allows admins to update a user's API key" do user.spree_roles << Spree::Role.find_or_create_by(name: 'admin') mock_user.should_receive(:generate_spree_api_key!).and_return(true) - spree_put :generate_api_key, :id => mock_user.id - response.should redirect_to(spree.edit_admin_user_path(mock_user)) + spree_put :generate_api_key, id: mock_user.id + expect(response).to redirect_to(spree.edit_admin_user_path(mock_user)) end it "allows admins to clear a user's API key" do user.spree_roles << Spree::Role.find_or_create_by(name: 'admin') mock_user.should_receive(:clear_spree_api_key!).and_return(true) - spree_put :clear_api_key, :id => mock_user.id - response.should redirect_to(spree.edit_admin_user_path(mock_user)) + spree_put :clear_api_key, id: mock_user.id + expect(response).to redirect_to(spree.edit_admin_user_path(mock_user)) end - it 'should deny access to users with an bar role' do + it 'deny access to users with an bar role' do user.spree_roles << Spree::Role.find_or_create_by(name: 'bar') Spree::Ability.register_ability(BarAbility) spree_post :index - response.should redirect_to('/unauthorized') + expect(response).to redirect_to '/unauthorized' end - it 'should deny access to users with an bar role' do + it 'deny access to users with an bar role' do user.spree_roles << Spree::Role.find_or_create_by(name: 'bar') Spree::Ability.register_ability(BarAbility) - spree_post :update, { :id => '9' } - response.should redirect_to('/unauthorized') + spree_post :update, { id: '9' } + expect(response).to redirect_to '/unauthorized' end - it 'should deny access to users without an admin role' do + it 'deny access to users without an admin role' do user.stub :has_spree_role? => false spree_post :index - response.should redirect_to('/unauthorized') + expect(response).to redirect_to '/unauthorized' end end end diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index 9c6d9657..b586d12f 100644 --- a/spec/controllers/spree/checkout_controller_spec.rb +++ b/spec/controllers/spree/checkout_controller_spec.rb @@ -1,67 +1,65 @@ require 'spec_helper' describe Spree::CheckoutController do - let(:order) { FactoryGirl.create(:order_with_totals, :email => nil, :user => nil) } - let(:user) { mock_model Spree::User, :last_incomplete_spree_order => nil, :has_spree_role? => true, :spree_api_key => 'fake' } + let(:order) { create(:order_with_totals, email: nil, user: nil) } + let(:user) { mock_model Spree::User, last_incomplete_spree_order: nil, has_spree_role?: true, spree_api_key: 'fake' } let(:token) { 'some_token' } before do - controller.stub :current_order => order - order.stub :confirmation_required? => true + controller.stub current_order: order + order.stub confirmation_required?: true end context '#edit' do context 'when registration step enabled' do before do controller.stub :check_authorization - Spree::Auth::Config.set(:registration_step => true) + Spree::Auth::Config.set(registration_step: true) end context 'when authenticated as registered user' do - before { controller.stub :spree_current_user => user } + before { controller.stub spree_current_user: user } - it 'should proceed to the first checkout step' do + it 'proceed to the first checkout step' do user.should_receive(:ship_address) - spree_get :edit, { :state => 'address' } - response.should render_template :edit + spree_get :edit, { state: 'address' } + expect(response).to render_template :edit end end context 'when authenticated as guest' do - it 'should redirect to registration step' do - spree_get :edit, { :state => 'address' } - response.should redirect_to spree.checkout_registration_path + it 'redirect to registration step' do + spree_get :edit, { state: 'address' } + expect(response).to redirect_to spree.checkout_registration_path end end end context 'when registration step disabled' do before do - Spree::Auth::Config.set(:registration_step => false) + Spree::Auth::Config.set(registration_step: false) controller.stub :check_authorization end context 'when authenticated as registered' do - before { controller.stub :spree_current_user => user } + before { controller.stub spree_current_user: user } - it 'should proceed to the first checkout step' do + it 'proceed to the first checkout step' do user.should_receive(:ship_address) - spree_get :edit, { :state => 'address' } - response.should render_template :edit + spree_get :edit, { state: 'address' } + expect(response).to render_template :edit end end context 'when authenticated as guest' do - it 'should proceed to the first checkout step' do - spree_get :edit, { :state => 'address' } - response.should render_template :edit + it 'proceed to the first checkout step' do + spree_get :edit, { state: 'address' } + expect(response).to render_template :edit end end - end - end context '#update' do @@ -71,77 +69,77 @@ order.update_column(:state, 'confirm') # So that the order can transition to complete successfully - order.stub :payment_required? => false + order.stub payment_required?: false end - context "with a token" do + context 'with a token' do before do - order.stub :token => 'ABC' + order.stub token: 'ABC' end - it 'should redirect to the tokenized order view' do - spree_post :update, { :state => 'confirm' }, { :access_token => "ABC" } - response.should redirect_to spree.token_order_path(order, 'ABC') - flash.notice.should == Spree.t(:order_processed_successfully) + it 'redirect to the tokenized order view' do + spree_post :update, { state: 'confirm' }, { access_token: 'ABC' } + expect(response).to redirect_to spree.token_order_path(order, 'ABC') + expect(flash.notice).to eq Spree.t(:order_processed_successfully) end end context 'with a registered user' do before do - controller.stub :spree_current_user => user - order.stub :user => user - order.stub :token => nil + controller.stub spree_current_user: user + order.stub user: user + order.stub token: nil end - it 'should redirect to the standard order view' do + it 'redirect to the standard order view' do spree_post :update, { :state => 'confirm' } - response.should redirect_to spree.order_path(order) + expect(response).to redirect_to spree.order_path(order) end end end end context '#registration' do - it 'should not check registration' do + it 'does not check registration' do controller.stub :check_authorization controller.should_not_receive :check_registration spree_get :registration end - it 'should check if the user is authorized for :edit' do + it 'check if the user is authorized for :edit' do controller.should_receive(:authorize!).with(:edit, order, token) - spree_get :registration, {}, { :access_token => token } + spree_get :registration, {}, { access_token: token } end end context '#update_registration' do let(:user) { user = mock_model Spree::User } - it 'should not check registration' do + it 'does not check registration' do controller.stub :check_authorization - order.stub :update_attributes => true + order.stub update_attributes: true controller.should_not_receive :check_registration - spree_put :update_registration, { :order => { } } + spree_put :update_registration, { order: { } } end - it 'should render the registration view if unable to save' do + it 'render the registration view if unable to save' do controller.stub :check_authorization - spree_put :update_registration, { :order => { :email => 'invalid' } } - flash[:registration_error].should == I18n.t(:email_is_invalid, :scope => [:errors, :messages]) - response.should render_template :registration + spree_put :update_registration, { order: { email: 'invalid' } } + expect(flash[:registration_error]).to eq I18n.t(:email_is_invalid, scope: [:errors, :messages]) + expect(response).to render_template :registration end - it 'should redirect to the checkout_path after saving' do - order.stub :update_attributes => true + it 'redirect to the checkout_path after saving' do + order.stub update_attributes: true controller.stub :check_authorization - spree_put :update_registration, { :order => { :email => 'jobs@spreecommerce.com' } } - response.should redirect_to spree.checkout_path + spree_put :update_registration, { order: { email: 'jobs@spreecommerce.com' } } + expect(response).to redirect_to spree.checkout_path end - it 'should check if the user is authorized for :edit' do - order.stub :update_attributes => true + it 'check if the user is authorized for :edit' do + order.stub update_attributes: true controller.should_receive(:authorize!).with(:edit, order, token) - spree_put :update_registration, { :order => { :email => 'jobs@spreecommerce.com' } }, { :access_token => token } + spree_put :update_registration, { order: { email: 'jobs@spreecommerce.com' } }, { access_token: token } end end end diff --git a/spec/controllers/spree/products_controller_spec.rb b/spec/controllers/spree/products_controller_spec.rb index 9bbc2963..6a0979ec 100644 --- a/spec/controllers/spree/products_controller_spec.rb +++ b/spec/controllers/spree/products_controller_spec.rb @@ -1,22 +1,22 @@ require 'spec_helper' describe Spree::ProductsController do - let!(:product) { create(:product, :available_on => 1.year.from_now) } - let!(:user) { mock_model(Spree::User, :spree_api_key => 'fake', :last_incomplete_spree_order => nil) } + let!(:product) { create(:product, available_on: 1.year.from_now) } + let!(:user) { mock_model(Spree::User, spree_api_key: 'fake', last_incomplete_spree_order: nil) } - it "allows admins to view non-active products" do + it 'allows admins to view non-active products' do controller.stub :before_save_new_order - controller.stub :spree_current_user => user - user.stub :has_spree_role? => true - spree_get :show, :id => product.to_param - response.status.should == 200 + controller.stub spree_current_user: user + user.stub has_spree_role?: true + spree_get :show, id: product.to_param + expect(response.status).to eq(200) end - it "cannot view non-active products" do + it 'cannot view non-active products' do controller.stub :before_save_new_order - controller.stub :spree_current_user => user - user.stub :has_spree_role? => false - spree_get :show, :id => product.to_param - response.status.should == 404 + controller.stub spree_current_user: user + user.stub has_spree_role?: false + spree_get :show, id: product.to_param + expect(response.status).to eq(404) end end diff --git a/spec/controllers/spree/users_controller_spec.rb b/spec/controllers/spree/users_controller_spec.rb index ac4531ee..9cd7f16b 100644 --- a/spec/controllers/spree/users_controller_spec.rb +++ b/spec/controllers/spree/users_controller_spec.rb @@ -6,27 +6,27 @@ let(:role) { create(:role) } before do - controller.stub(:spree_current_user => user) + controller.stub spree_current_user: user end context '#create' do - it 'should create a new user' do - spree_post :create, { :user => { :email => 'foobar@example.com', :password => 'foobar123', :password_confirmation => 'foobar123' } } - assigns[:user].new_record?.should be_false + it 'create a new user' do + spree_post :create, { user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' } } + expect(assigns[:user].new_record?).to be_false end end context '#update' do context 'when updating own account' do - it 'should perform update' do - spree_put :update, { :user => { :email => 'mynew@email-address.com' } } - assigns[:user].email.should == 'mynew@email-address.com' - response.should redirect_to(spree.account_url(:only_path => true)) + it 'perform update' do + spree_put :update, { user: { email: 'mynew@email-address.com' } } + expect(assigns[:user].email).to eq 'mynew@email-address.com' + expect(response).to redirect_to spree.account_url(only_path: true) end end - it 'should not update roles' do - spree_put :update, :user => { :spree_role_ids => [role.id] } + it 'does not update roles' do + spree_put :update, user: { spree_role_ids: [role.id] } expect(assigns[:user].spree_roles).to_not include role end end diff --git a/spec/features/account_spec.rb b/spec/features/account_spec.rb index ec968cd5..4bd172c9 100644 --- a/spec/features/account_spec.rb +++ b/spec/features/account_spec.rb @@ -1,52 +1,60 @@ require 'spec_helper' -describe "Accounts" do - context "editing" do - it "should be able to edit an admin user" do - user = create(:admin_user, :email => "admin@person.com", :password => "password", :password_confirmation => "password") +feature 'Accounts' do + + context 'editing' do + scenario 'can edit an admin user' do + user = create(:admin_user, email: 'admin@person.com', password: 'password', password_confirmation: 'password') visit spree.login_path - fill_in "Email", :with => user.email - fill_in "Password", :with => user.password - click_button "Login" - click_link "My Account" - page.should have_content("admin@person.com") + fill_in 'Email', with: user.email + fill_in 'Password', with: user.password + click_button 'Login' + + click_link 'My Account' + expect(page).to have_text 'admin@person.com' end - it "should be able to edit a new user" do - Spree::Auth::Config.set(:signout_after_password_change => false) + scenario 'can edit a new user' do + Spree::Auth::Config.set(signout_after_password_change: false) visit spree.signup_path - fill_in "Email", :with => "email@person.com" - fill_in "Password", :with => "password" - fill_in "Password Confirmation", :with => "password" - click_button "Create" - - click_link "My Account" - page.should have_content("email@person.com") - click_link "Edit" - fill_in "Password", :with => "foobar" - fill_in "Password Confirmation", :with => "foobar" - click_button "Update" - page.should have_content("email@person.com") - page.should have_content("Account updated") + + fill_in 'Email', with: 'email@person.com' + fill_in 'Password', with: 'password' + fill_in 'Password Confirmation', :with => 'password' + click_button 'Create' + + click_link 'My Account' + expect(page).to have_text 'email@person.com' + click_link 'Edit' + + fill_in 'Password', with: 'foobar' + fill_in 'Password Confirmation', with: 'foobar' + click_button 'Update' + + expect(page).to have_text 'email@person.com' + expect(page).to have_text 'Account updated' end - it "should be able to edit an existing user account" do - Spree::Auth::Config.set(:signout_after_password_change => false) - user = create(:user, :email => "email@person.com", :password => "secret", :password_confirmation => "secret") + scenario 'can edit an existing user account' do + Spree::Auth::Config.set(signout_after_password_change: false) + user = create(:user, email: 'email@person.com', password: 'secret', password_confirmation: 'secret') visit spree.login_path - fill_in "Email", :with => user.email - fill_in "Password", :with => user.password - click_button "Login" - - click_link "My Account" - page.should have_content("email@person.com") - click_link "Edit" - fill_in "Password", :with => "foobar" - fill_in "Password Confirmation", :with => "foobar" - click_button "Update" - page.should have_content("email@person.com") - page.should have_content("Account updated") + + fill_in 'Email', with: user.email + fill_in 'Password', with: user.password + click_button 'Login' + + click_link 'My Account' + expect(page).to have_text 'email@person.com' + click_link 'Edit' + + fill_in 'Password', with: 'foobar' + fill_in 'Password Confirmation', with: 'foobar' + click_button 'Update' + + expect(page).to have_text 'email@person.com' + expect(page).to have_text 'Account updated' end end end diff --git a/spec/features/admin/payment_methods_spec.rb b/spec/features/admin/payment_methods_spec.rb index 76da1517..4d28bef6 100644 --- a/spec/features/admin/payment_methods_spec.rb +++ b/spec/features/admin/payment_methods_spec.rb @@ -1,22 +1,18 @@ require 'spec_helper' -describe "Payment methods" do - before do - sign_in_as!(create(:admin_user)) +feature 'Payment methods' do + background do + sign_in_as! create(:admin_user) visit spree.admin_path - click_link "Configuration" + click_link 'Configuration' end # Regression test for #5 - it "can dismiss the banner" do - Spree::User.any_instance.stub(:dismissed_banner? => false) + scenario 'can dismiss the banner' do + Spree::User.any_instance.stub(dismissed_banner?: false) Spree::PaymentMethod.stub(:production).and_return(payment_methods = [double]) payment_methods.stub(:where).and_return([]) - click_link "Payment Methods" + click_link 'Payment Methods' end - - - - end diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index 8a3ac24b..ea4d79eb 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -1,9 +1,10 @@ require 'spec_helper' -describe "Admin products" do - context "as anonymous user" do + +feature 'Admin products' do + context 'as anonymous user' do # regression test for #1250 - it "is redirected to login page when attempting to access product listing" do - lambda { visit spree.admin_products_path }.should_not raise_error + scenario 'is redirected to login page when attempting to access product listing' do + expect { visit spree.admin_products_path }.not_to raise_error end end end diff --git a/spec/features/admin/users_spec.rb b/spec/features/admin/users_spec.rb index 72a28018..8d1649df 100644 --- a/spec/features/admin/users_spec.rb +++ b/spec/features/admin/users_spec.rb @@ -1,68 +1,68 @@ require 'spec_helper' -describe "Users" do +feature 'Users' do - before(:each) do - create(:user, :email => "a@example.com") - create(:user, :email => "b@example.com") - sign_in_as!(create(:admin_user)) + background do + create(:user, email: 'a@example.com') + create(:user, email: 'b@example.com') + sign_in_as! create(:admin_user) visit spree.admin_path - click_link "Users" + click_link 'Users' end - context "users index page with sorting" do - before(:each) do - click_link "users_email_title" + context 'users index page with sorting' do + background do + click_link 'users_email_title' end - it "should be able to list users with order email asc" do - page.should have_css('table#listing_users') - within("table#listing_users") do - page.should have_content("a@example.com") - page.should have_content("b@example.com") + scenario 'can list users with order email asc' do + expect(page).to have_table 'listing_users' + within_table('listing_users') do + expect(page).to have_text 'a@example.com' + expect(page).to have_text 'b@example.com' end end - it "should be able to list users with order email desc" do - click_link "users_email_title" - within("table#listing_users") do - page.should have_content("a@example.com") - page.should have_content("b@example.com") + scenario 'can list users with order email desc' do + click_link 'users_email_title' + within_table('listing_users') do + expect(page).to have_text 'a@example.com' + expect(page).to have_text 'b@example.com' end end end - context "searching users" do - it "should display the correct results for a user search" do - fill_in "q_email_cont", :with => "a@example.com" - click_button "Search" - within("table#listing_users") do - page.should have_content("a@example.com") - page.should_not have_content("b@example.com") + context 'searching users' do + scenario 'display the correct results for a user search' do + fill_in 'q_email_cont', with: 'a@example.com' + click_button 'Search' + within_table('listing_users') do + expect(page).to have_text 'a@example.com' + expect(page).not_to have_text 'b@example.com' end end end - context "editing users" do - before(:each) do - click_link("a@example.com") - click_link("Edit") + context 'editing users' do + background do + click_link 'a@example.com' + click_link 'Edit' end - it "should let me edit the user email" do - fill_in "user_email", :with => "a@example.com99" - click_button "Update" + scenario 'let me edit the user email' do + fill_in 'user_email', with: 'a@example.com99' + click_button 'Update' - page.should have_content("Account updated") - find_field("user_email").value.should == "a@example.com99" + expect(page).to have_text 'Account updated' + expect(find_field('user_email').value).to eq 'a@example.com99' end - it "should let me edit the user password" do - fill_in "user_password", :with => "welcome" - fill_in "user_password_confirmation", :with => "welcome" - click_button "Update" + scenario 'let me edit the user password' do + fill_in 'user_password', with: 'welcome' + fill_in 'user_password_confirmation', with: 'welcome' + click_button 'Update' - page.should have_content("Account updated") + expect(page).to have_text 'Account updated' end end end diff --git a/spec/features/admin_permissions_spec.rb b/spec/features/admin_permissions_spec.rb index 21d1e253..bb643ce3 100644 --- a/spec/features/admin_permissions_spec.rb +++ b/spec/features/admin_permissions_spec.rb @@ -1,40 +1,41 @@ require 'spec_helper' -describe "Admin Permissions" do +feature 'Admin Permissions' do context 'orders' do - before do - user = create(:admin_user, :email => "admin@person.com", :password => "password", :password_confirmation => "password") + background do + user = create(:admin_user, email: 'admin@person.com', password: 'password', password_confirmation: 'password') Spree::Ability.register_ability(AbilityDecorator) visit spree.login_path - fill_in "Email", :with => user.email - fill_in "Password", :with => user.password - click_button "Login" + + fill_in 'Email', with: user.email + fill_in 'Password', with: user.password + click_button 'Login' end - context "admin is restricted from accessing orders" do - it "should not be able to list orders" do + context 'admin is restricted from accessing orders' do + scenario 'can not list orders' do visit spree.admin_orders_path - page.should have_content("Authorization Failure") + expect(page).to have_text 'Authorization Failure' end - it "should not be able to edit orders" do - create(:order, :number => "R123") - visit spree.edit_admin_order_path("R123") - page.should have_content("Authorization Failure") + scenario 'can not edit orders' do + create(:order, number: 'R123') + visit spree.edit_admin_order_path('R123') + expect(page).to have_text 'Authorization Failure' end end context "admin is restricted from accessing an order's customer details" do - let(:order) { create(:order_with_totals)} + given(:order) { create(:order_with_totals) } - it "should not be able to list customer details for an order" do + scenario 'can not list customer details for an order' do visit spree.admin_order_customer_path(order) - page.should have_content("Authorization Failure") + expect(page).to have_text 'Authorization Failure' end - it "should not be able to edit an order's customer details" do + scenario "can not edit an order's customer details" do visit spree.edit_admin_order_customer_path(order) - page.should have_content("Authorization Failure") + expect(page).to have_text 'Authorization Failure' end end end diff --git a/spec/features/change_email_spec.rb b/spec/features/change_email_spec.rb index d6ee69a0..06452e1a 100644 --- a/spec/features/change_email_spec.rb +++ b/spec/features/change_email_spec.rb @@ -1,24 +1,26 @@ require 'spec_helper' -describe 'Change email' do +feature 'Change email' do - before do + background do user = create(:user) visit spree.root_path click_link 'Login' + fill_in 'spree_user[email]', with: user.email fill_in 'spree_user[password]', with: 'secret' click_button 'Login' + visit spree.edit_account_path end - it "should work with correct password" do - fill_in "user_email", :with => "tests@example.com" - fill_in "user_password", :with => 'password' - fill_in "user_password_confirmation", :with => 'password' - click_button "Update" - page.should have_content("Account updated") - page.should have_content('tests@example.com') - end + scenario 'work with correct password' do + fill_in 'user_email', with: 'tests@example.com' + fill_in 'user_password', with: 'password' + fill_in 'user_password_confirmation', with: 'password' + click_button 'Update' + expect(page).to have_text 'Account updated' + expect(page).to have_text 'tests@example.com' + end end diff --git a/spec/features/checkout_spec.rb b/spec/features/checkout_spec.rb index ee77f655..79d2c126 100644 --- a/spec/features/checkout_spec.rb +++ b/spec/features/checkout_spec.rb @@ -1,102 +1,113 @@ require 'spec_helper' -describe "Checkout", :js => true do - let!(:country) { create(:country, :name => "United States",:states_required => true) } - let!(:state) { create(:state, :name => "Maryland", :country => country) } - let!(:shipping_method) do +feature 'Checkout', js: true do + given!(:country) { create(:country, name: 'United States', states_required: true) } + given!(:state) { create(:state, name: 'Maryland', country: country) } + given!(:shipping_method) do shipping_method = create(:shipping_method) - calculator = Spree::Calculator::Shipping::PerItem.create!(:calculable => shipping_method, :preferred_amount => 10) + calculator = Spree::Calculator::Shipping::PerItem.create!(calculable: shipping_method, preferred_amount: 10) shipping_method.calculator = calculator shipping_method.tap(&:save) end - let!(:zone) { create(:zone) } - let!(:address) { create(:address, :state => state, :country => country) } + given!(:zone) { create(:zone) } + given!(:address) { create(:address, state: state, country: country) } - before do - ActionMailer::Base.default_url_options[:host] = "http://example.com" - @product = create(:product, :name => "RoR Mug") + background do + ActionMailer::Base.default_url_options[:host] = 'http://example.com' + @product = create(:product, name: 'RoR Mug') @product.master.stock_items.first.update_column(:count_on_hand, 1) - ActionMailer::Base.default_url_options[:host] = "http://example.com" + ActionMailer::Base.default_url_options[:host] = 'http://example.com' Spree::Config[:enable_mail_delivery] = true + # Bypass gateway error on checkout | ..or stub a gateway + Spree::Config[:allow_checkout_on_gateway_error] = true + visit spree.root_path end - context "without payment being required" do - before do + context 'without payment being required' do + background do # So that we don't have to setup payment methods just for the sake of it - Spree::Order.any_instance.stub :has_available_payment => true - Spree::Order.any_instance.stub :payment_required? => false + Spree::Order.any_instance.stub has_available_payment: true + Spree::Order.any_instance.stub payment_required?: false end - it "should allow a visitor to checkout as guest, without registration" do - Spree::Auth::Config.set(:registration_step => true) - click_link "RoR Mug" - click_button "Add To Cart" - within('h1') { page.should have_content("Shopping Cart") } - click_button "Checkout" + scenario 'allow a visitor to checkout as guest, without registration' do + Spree::Auth::Config.set(registration_step: true) + click_link 'RoR Mug' + click_button 'Add To Cart' + within('h1') { expect(page).to have_text 'Shopping Cart' } + click_button 'Checkout' + + expect(page).to have_content(/Checkout as a Guest/i) - page.should have_content(/Checkout as a Guest/i) + within('#guest_checkout') { fill_in 'Email', with: 'spree@test.com' } + click_button 'Continue' - within('#guest_checkout') { fill_in "Email", :with => "spree@test.com" } - click_button "Continue" - page.should have_content(/Billing Address/i) - page.should have_content(/Shipping Address/i) + expect(page).to have_text(/Billing Address/i) + expect(page).to have_text(/Shipping Address/i) - str_addr = "bill_address" - select "United States", :from => "order_#{str_addr}_attributes_country_id" - ['firstname', 'lastname', 'address1', 'city', 'zipcode', 'phone'].each do |field| - fill_in "order_#{str_addr}_attributes_#{field}", :with => "#{address.send(field)}" + str_addr = 'bill_address' + select 'United States', from: "order_#{str_addr}_attributes_country_id" + %w(firstname lastname address1 city zipcode phone).each do |field| + fill_in "order_#{str_addr}_attributes_#{field}", with: "#{address.send(field)}" end - select "#{address.state.name}", :from => "order_#{str_addr}_attributes_state_id" + select "#{address.state.name}", from: "order_#{str_addr}_attributes_state_id" + check 'order_use_billing' + + click_button 'Save and Continue' + click_button 'Save and Continue' + # coupon code step + click_button 'Save and Continue' - check "order_use_billing" - click_button "Save and Continue" - click_button "Save and Continue" - page.should have_content("Your order has been processed successfully") + expect(page).to have_text 'Your order has been processed successfully' end - it "should associate an uncompleted guest order with user after logging in" do - user = create(:user, :email => "email@person.com", :password => "password", :password_confirmation => "password") - click_link "RoR Mug" - click_button "Add To Cart" + scenario 'associate an uncompleted guest order with user after logging in' do + user = create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password') + click_link 'RoR Mug' + click_button 'Add To Cart' visit spree.login_path - fill_in "Email", :with => user.email - fill_in "Password", :with => user.password - click_button "Login" - - click_link "Cart" - page.should have_content("RoR Mug") - within('h1') { page.should have_content("Shopping Cart") } - - click_button "Checkout" - str_addr = "bill_address" - select "United States", :from => "order_#{str_addr}_attributes_country_id" - ['firstname', 'lastname', 'address1', 'city', 'zipcode', 'phone'].each do |field| - fill_in "order_#{str_addr}_attributes_#{field}", :with => "#{address.send(field)}" + fill_in 'Email', with: user.email + fill_in 'Password', with: user.password + click_button 'Login' + click_link 'Cart' + + expect(page).to have_text 'RoR Mug' + within('h1') { expect(page).to have_text 'Shopping Cart' } + + click_button 'Checkout' + + str_addr = 'bill_address' + select 'United States', from: "order_#{str_addr}_attributes_country_id" + %w(firstname lastname address1 city zipcode phone).each do |field| + fill_in "order_#{str_addr}_attributes_#{field}", with: "#{address.send(field)}" end - select "#{address.state.name}", :from => "order_#{str_addr}_attributes_state_id" - check "order_use_billing" - click_button "Save and Continue" - click_button "Save and Continue" - page.should have_content("Your order has been processed successfully") + select "#{address.state.name}", from: "order_#{str_addr}_attributes_state_id" + check 'order_use_billing' + + click_button 'Save and Continue' + click_button 'Save and Continue' + # coupon code step + click_button 'Save and Continue' - Spree::Order.first.user.should == user + expect(page).to have_text 'Your order has been processed successfully' + expect(Spree::Order.first.user).to eq user end # Regression test for #890 - it "should associate an incomplete guest order with user after successful password reset" do - user = create(:user, :email => "email@person.com", :password => "password", :password_confirmation => "password") - click_link "RoR Mug" - click_button "Add To Cart" + scenario 'associate an incomplete guest order with user after successful password reset' do + user = create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password') + click_link 'RoR Mug' + click_button 'Add To Cart' visit spree.login_path - click_link "Forgot Password?" - fill_in "spree_user_email", :with => "email@person.com" - click_button "Reset my password" + click_link 'Forgot Password?' + fill_in 'spree_user_email', with: 'email@person.com' + click_button 'Reset my password' # Need to do this now because the token stored in the DB is the encrypted version # The 'plain-text' version is sent in the email and there's one way to get that! @@ -104,49 +115,58 @@ token_url_regex = /^http:\/\/example.com\/user\/spree_user\/password\/edit\?reset_password_token=(.*)$/ token = token_url_regex.match(reset_password_email.body.to_s)[1] - visit spree.edit_spree_user_password_path(:reset_password_token => token) - fill_in "Password", :with => "password" - fill_in "Password Confirmation", :with => "password" - click_button "Update" - - click_link "Cart" - click_button "Checkout" - str_addr = "bill_address" - select "United States", :from => "order_#{str_addr}_attributes_country_id" - ['firstname', 'lastname', 'address1', 'city', 'zipcode', 'phone'].each do |field| - fill_in "order_#{str_addr}_attributes_#{field}", :with => "#{address.send(field)}" + visit spree.edit_spree_user_password_path(reset_password_token: token) + fill_in 'Password', with: 'password' + fill_in 'Password Confirmation', with: 'password' + click_button 'Update' + + click_link 'Cart' + click_button 'Checkout' + + str_addr = 'bill_address' + select 'United States', from: "order_#{str_addr}_attributes_country_id" + %w(firstname lastname address1 city zipcode phone).each do |field| + fill_in "order_#{str_addr}_attributes_#{field}", with: "#{address.send(field)}" end - select "#{address.state.name}", :from => "order_#{str_addr}_attributes_state_id" - check "order_use_billing" - click_button "Save and Continue" - page.should_not have_content("Email is invalid") + select "#{address.state.name}", from: "order_#{str_addr}_attributes_state_id" + check 'order_use_billing' + + click_button 'Save and Continue' + + expect(page).not_to have_text 'Email is invalid' end - it "should allow a user to register during checkout" do - click_link "RoR Mug" - click_button "Add To Cart" - click_button "Checkout" - page.should have_content("Registration") - click_link "Create a new account" - - fill_in "Email", :with => "email@person.com" - fill_in "Password", :with => "spree123" - fill_in "Password Confirmation", :with => "spree123" - click_button "Create" - page.should have_content("You have signed up successfully.") - - str_addr = "bill_address" - select "United States", :from => "order_#{str_addr}_attributes_country_id" - ['firstname', 'lastname', 'address1', 'city', 'zipcode', 'phone'].each do |field| - fill_in "order_#{str_addr}_attributes_#{field}", :with => "#{address.send(field)}" + scenario 'allow a user to register during checkout' do + click_link 'RoR Mug' + click_button 'Add To Cart' + click_button 'Checkout' + + expect(page).to have_text 'Registration' + + click_link 'Create a new account' + + fill_in 'Email', with: 'email@person.com' + fill_in 'Password', with: 'spree123' + fill_in 'Password Confirmation', with: 'spree123' + click_button 'Create' + + expect(page).to have_text 'You have signed up successfully.' + + str_addr = 'bill_address' + select 'United States', from: "order_#{str_addr}_attributes_country_id" + %w(firstname lastname address1 city zipcode phone).each do |field| + fill_in "order_#{str_addr}_attributes_#{field}", with: "#{address.send(field)}" end - select "#{address.state.name}", :from => "order_#{str_addr}_attributes_state_id" - check "order_use_billing" - click_button "Save and Continue" - click_button "Save and Continue" - page.should have_content("Your order has been processed successfully") + select "#{address.state.name}", from: "order_#{str_addr}_attributes_state_id" + check 'order_use_billing' + + click_button 'Save and Continue' + click_button 'Save and Continue' + # coupon code step + click_button 'Save and Continue' - Spree::Order.first.user.should == Spree::User.find_by_email("email@person.com") + expect(page).to have_text 'Your order has been processed successfully' + expect(Spree::Order.first.user).to eq Spree::User.find_by_email('email@person.com') end end end diff --git a/spec/features/order_spec.rb b/spec/features/order_spec.rb index 334b469b..9a4d04b9 100644 --- a/spec/features/order_spec.rb +++ b/spec/features/order_spec.rb @@ -1,58 +1,59 @@ require 'spec_helper' -describe "Orders", :js => true do - it "should allow a user to view their cart at any time" do +feature 'Orders', js: true, focus: true do + + scenario 'allow a user to view their cart at any time' do visit spree.cart_path - page.should have_content("Your cart is empty") + expect(page).to have_text 'Your cart is empty' end # regression test for spree/spree#1687 - it "should merge incomplete orders from different sessions" do - create(:product, :name => "RoR Mug") - create(:product, :name => "RoR Shirt") + scenario 'merge incomplete orders from different sessions' do + create(:product, name: 'RoR Mug') + create(:product, name: 'RoR Shirt') - user = create(:user, :email => "email@person.com", :password => "password", :password_confirmation => "password") + user = create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password') - using_session("first") do + using_session('first') do visit spree.root_path - click_link "RoR Mug" - click_button "Add To Cart" + click_link 'RoR Mug' + click_button 'Add To Cart' visit spree.login_path - fill_in "Email", :with => user.email - fill_in "Password", :with => user.password - click_button "Login" + fill_in 'Email', with: user.email + fill_in 'Password', with: user.password + click_button 'Login' - click_link "Cart" - page.should have_content("RoR Mug") + click_link 'Cart' + expect(page).to have_text 'RoR Mug' end - using_session("second") do + using_session('second') do visit spree.root_path - click_link "RoR Shirt" - click_button "Add To Cart" + click_link 'RoR Shirt' + click_button 'Add To Cart' visit spree.login_path - fill_in "Email", :with => user.email - fill_in "Password", :with => user.password - click_button "Login" + fill_in 'Email', with: user.email + fill_in 'Password', with: user.password + click_button 'Login' # order should have been merged with first session - click_link "Cart" - page.should have_content("RoR Mug") - page.should have_content("RoR Shirt") + click_link 'Cart' + expect(page).to have_text 'RoR Mug' + expect(page).to have_text 'RoR Shirt' end - using_session("first") do + using_session('first') do visit spree.root_path - click_link "Cart" + click_link 'Cart' # order should have been merged with second session - page.should have_content("RoR Mug") - page.should have_content("RoR Shirt") + expect(page).to have_text 'RoR Mug' + expect(page).to have_text 'RoR Shirt' end end end diff --git a/spec/features/password_reset_spec.rb b/spec/features/password_reset_spec.rb index 11c7e198..610e6f94 100644 --- a/spec/features/password_reset_spec.rb +++ b/spec/features/password_reset_spec.rb @@ -1,23 +1,23 @@ require 'spec_helper' -describe "Reset Password" do - before do - ActionMailer::Base.default_url_options[:host] = "http://example.com" +feature 'Reset Password' do + background do + ActionMailer::Base.default_url_options[:host] = 'http://example.com' end - it "should allow a user to supply an email for the password reset" do - user = create(:user, :email => "foobar@example.com", :password => "secret", :password_confirmation => "secret") + scenario 'allow a user to supply an email for the password reset' do + user = create(:user, email: 'foobar@example.com', password: 'secret', password_confirmation: 'secret') visit spree.login_path - click_link "Forgot Password?" - fill_in "Email", :with => "foobar@example.com" - click_button "Reset my password" - page.should have_content("You will receive an email with instructions") + click_link 'Forgot Password?' + fill_in 'Email', with: 'foobar@example.com' + click_button 'Reset my password' + expect(page).to have_text 'You will receive an email with instructions' end - it "shows errors if no email is supplied" do + scenario 'shows errors if no email is supplied' do visit spree.login_path - click_link "Forgot Password?" - click_button "Reset my password" - page.should have_content("Email can't be blank") + click_link 'Forgot Password?' + click_button 'Reset my password' + expect(page).to have_text "Email can't be blank" end end diff --git a/spec/features/sign_in_spec.rb b/spec/features/sign_in_spec.rb index cb3ad0c5..abac3dc0 100644 --- a/spec/features/sign_in_spec.rb +++ b/spec/features/sign_in_spec.rb @@ -1,41 +1,45 @@ require 'spec_helper' -describe "Sign In" do - before(:each) do - @user = create(:user, :email => "email@person.com", :password => "secret", :password_confirmation => "secret") +feature 'Sign In' do + background do + @user = create(:user, email: 'email@person.com', password: 'secret', password_confirmation: 'secret') visit spree.login_path end - it "should ask use to sign in" do + scenario 'ask use to sign in' do visit spree.admin_path - page.should_not have_content("Authorization Failure") + expect(page).not_to have_text 'Authorization Failure' end - it "should let a user sign in successfully" do - fill_in "Email", :with => @user.email - fill_in "Password", :with => @user.password - click_button "Login" - page.should have_content("Logged in successfully") - page.should_not have_content("Login") - page.should have_content("Logout") - current_path.should == "/" + scenario 'let a user sign in successfully' do + fill_in 'Email', with: @user.email + fill_in 'Password', with: @user.password + click_button 'Login' + + expect(page).to have_text 'Logged in successfully' + expect(page).not_to have_text 'Login' + expect(page).to have_text 'Logout' + expect(current_path).to eq '/' end - it "should show validation erros" do - fill_in "Email", :with => @user.email - fill_in "Password", :with => "wrong_password" - click_button "Login" - page.should have_content("Invalid email or password") - page.should have_content("Login") + scenario 'show validation erros' do + fill_in 'Email', with: @user.email + fill_in 'Password', with: 'wrong_password' + click_button 'Login' + + expect(page).to have_text 'Invalid email or password' + expect(page).to have_text 'Login' end - it "should allow a user to access a restricted page after logging in" do - user = create(:admin_user, :email => "admin@person.com", :password => "password", :password_confirmation => "password") + scenario 'allow a user to access a restricted page after logging in' do + user = create(:admin_user, email: 'admin@person.com', password: 'password', password_confirmation: 'password') visit spree.admin_path - fill_in "Email", :with => user.email - fill_in "Password", :with => user.password - click_button "Login" - page.should have_content("Logged in as: admin@person.com") - current_path.should == "/admin" + + fill_in 'Email', with: user.email + fill_in 'Password', with: user.password + click_button 'Login' + + expect(page).to have_text 'Logged in as: admin@person.com' + expect(current_path).to eq '/admin' end end diff --git a/spec/features/sign_out_spec.rb b/spec/features/sign_out_spec.rb index 63702dde..564d206f 100644 --- a/spec/features/sign_out_spec.rb +++ b/spec/features/sign_out_spec.rb @@ -1,26 +1,26 @@ require 'spec_helper' -describe "Sign Out" do - let!(:user) do +feature 'Sign Out' do + given!(:user) do create(:user, - :email => "email@person.com", - :password => "secret", - :password_confirmation => "secret") + email: 'email@person.com', + password: 'secret', + password_confirmation: 'secret') end - before do + background do visit spree.login_path - fill_in "Email", :with => user.email - fill_in "Password", :with => user.password + fill_in 'Email', with: user.email + fill_in 'Password', with: user.password # Regression test for #1257 - check "Remember me" - click_button "Login" + check 'Remember me' + click_button 'Login' end - it "should allow a signed in user to logout" do - click_link "Logout" + scenario 'allow a signed in user to logout' do + click_link 'Logout' visit spree.root_path - page.should have_content("Login") - page.should_not have_content("Logout") + expect(page).to have_text 'Login' + expect(page).not_to have_text 'Logout' end end diff --git a/spec/features/sign_up_spec.rb b/spec/features/sign_up_spec.rb index 96c92bf9..020087c7 100644 --- a/spec/features/sign_up_spec.rb +++ b/spec/features/sign_up_spec.rb @@ -1,27 +1,31 @@ require 'spec_helper' -describe "Sign Up" do - context "with valid data" do - it "should create a new user" do +feature 'Sign Up' do + context 'with valid data' do + scenario 'create a new user' do visit spree.signup_path - fill_in "Email", :with => "email@person.com" - fill_in "Password", :with => "password" - fill_in "Password Confirmation", :with => "password" - click_button "Create" - page.should have_content("You have signed up successfully.") - Spree::User.count.should == 1 + + fill_in 'Email', with: 'email@person.com' + fill_in 'Password', with: 'password' + fill_in 'Password Confirmation', with: 'password' + click_button 'Create' + + expect(page).to have_text 'You have signed up successfully.' + expect(Spree::User.count).to eq(1) end end - context "with invalid data" do - it "should not create a new user" do + context 'with invalid data' do + scenario 'does not create a new user' do visit spree.signup_path - fill_in "Email", :with => "email@person.com" - fill_in "Password", :with => "password" - fill_in "Password Confirmation", :with => "" - click_button "Create" - page.should have_css("#errorExplanation") - Spree::User.count.should == 0 + + fill_in 'Email', with: 'email@person.com' + fill_in 'Password', with: 'password' + fill_in 'Password Confirmation', with: '' + click_button 'Create' + + expect(page).to have_css '#errorExplanation' + expect(Spree::User.count).to eq(0) end end end diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index caa86251..5d226987 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -1,29 +1,31 @@ require 'spec_helper' -describe "Users" do - before(:each) do - Spree::Role.create!(:name => "user") - user = create(:admin_user, :email => "admin@person.com", :password => "password", :password_confirmation => "password") +feature 'Users' do + background do + Spree::Role.create!(name: 'user') + user = create(:admin_user, email: 'admin@person.com', password: 'password', password_confirmation: 'password') visit spree.admin_path - fill_in "Email", :with => user.email - fill_in "Password", :with => user.password - click_button "Login" - click_link "Users" - within('table#listing_users td.user_email') { click_link "admin@person.com" } - click_link "Edit" - page.should have_content("Editing User") + + fill_in 'Email', with: user.email + fill_in 'Password', with: user.password + click_button 'Login' + click_link 'Users' + within('table#listing_users td.user_email') { click_link 'admin@person.com' } + click_link 'Edit' + + expect(page).to have_text 'Editing User' end - it "admin editing email with validation error" do - fill_in "Email", :with => "a" - click_button "Update" - page.should have_content("Email is invalid") + scenario 'admin editing email with validation error' do + fill_in 'Email', with: 'a' + click_button 'Update' + expect(page).to have_text 'Email is invalid' end - it "admin editing roles" do - check "user_spree_role_user" - click_button "Update" - page.should have_content("Account updated") - find_field('user_spree_role_user')['checked'].should be_true + scenario 'admin editing roles' do + check 'user_spree_role_user' + click_button 'Update' + expect(page).to have_text'Account updated' + expect(find_field('user_spree_role_user')['checked']).to be_true end end diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb index c6f05c5d..4c00d43e 100644 --- a/spec/mailers/user_mailer_spec.rb +++ b/spec/mailers/user_mailer_spec.rb @@ -4,7 +4,7 @@ let(:user) { create(:user) } before do - ActionMailer::Base.default_url_options[:host] = "http://example.com" + ActionMailer::Base.default_url_options[:host] = 'http://example.com' user = create(:user) Spree::UserMailer.reset_password_instructions(user, 'token goes here').deliver @message = ActionMailer::Base.deliveries.last @@ -18,31 +18,30 @@ end context 'subject includes' do - it 'translated devise instructions' do - @message.subject.should include( - I18n.t(:subject, :scope => [:devise, :mailer, :reset_password_instructions]) + it 'translated devise instructions' do + expect(@message.subject).to include( + I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions]) ) end - it 'Spree site name' do - @message.subject.should include(Spree::Config[:site_name]) + it 'Spree site name' do + expect(@message.subject).to include Spree::Config[:site_name] end end context 'body includes' do it 'password reset url' do - @message.body.raw_source.should include('http://example.com/user/spree_user/password/edit') + expect(@message.body.raw_source).to include 'http://example.com/user/spree_user/password/edit' end end end describe 'legacy support for User object' do - it 'should send an email' do - lambda { + it 'send an email' do + expect { Spree::UserMailer.reset_password_instructions(user, 'token goes here').deliver - }.should change(ActionMailer::Base.deliveries, :size).by(1) + }.to change(ActionMailer::Base.deliveries, :size).by(1) end end end - end diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb index 879a6456..20943288 100644 --- a/spec/models/order_spec.rb +++ b/spec/models/order_spec.rb @@ -1,34 +1,34 @@ require 'spec_helper' describe Spree::Order do - let(:order) { Spree::Order.new } + let(:order) { described_class.new } context '#associate_user!' do - let(:user) { mock_model Spree::User, :email => 'spree@example.com', :anonymous? => false } - before { order.stub(:save! => true) } + let(:user) { mock_model Spree::User, email: 'spree@example.com', anonymous?: false } + before { order.stub(save!: true) } - it 'should associate the order with the specified user' do + it 'associate the order with the specified user' do order.associate_user! user - order.user.should == user + expect(order.user).to eq user end - it "should set the order's email attribute to that of the specified user" do + it "set the order's email attribute to that of the specified user" do order.associate_user! user - order.email.should == user.email + expect(order.email).to eq user.email end - it 'should destroy any previous association with a guest user' do + it 'destroy any previous association with a guest user' do guest_user = mock_model Spree::User order.user = guest_user order.associate_user! user - order.user.should_not == guest_user + expect(order.user).not_to eq guest_user end end context '#create' do - it 'should create a token permission' do + it 'create a token permission' do order.save - order.token.should_not be_nil + expect(order.token).not_to be_nil end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 18cc5410..7d5bdb0d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,28 +1,27 @@ require 'spec_helper' describe Spree::User do - before(:all) { Spree::Role.create :name => 'admin' } + before(:all) { Spree::Role.create name: 'admin' } it '#admin?' do - create(:admin_user).admin?.should be_true - create(:user).admin?.should be_false + expect(create(:admin_user).admin?).to be_true + expect(create(:user).admin?).to be_false end - it 'should generate the reset password token' do + it 'generate the reset password token' do user = build(:user) - Spree::UserMailer.should_receive(:reset_password_instructions).with(user, anything, {}).and_return(double(:deliver => true)) + Spree::UserMailer.should_receive(:reset_password_instructions).with(user, anything, {}).and_return(double(deliver: true)) user.send_reset_password_instructions - user.reset_password_token.should_not be_nil + expect(user.reset_password_token).not_to be_nil end context '#destroy' do it 'can not delete if it has completed orders' do - order = build(:order, :completed_at => Time.now) + order = build(:order, completed_at: Time.now) order.save user = order.user - lambda { user.destroy }.should raise_exception(Spree::User::DestroyWithOrdersError) + expect { user.destroy }.to raise_exception(Spree::User::DestroyWithOrdersError) end end - end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fec6ba91..490ad708 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,53 +1,43 @@ -# This file is copied to ~/spec when you run 'ruby script/generate rspec' -# from the project root directory. +require 'simplecov' +SimpleCov.start 'rails' + ENV['RAILS_ENV'] ||= 'test' -if ENV["COVERAGE"] - require 'simplecov' -end + require File.expand_path('../dummy/config/environment', __FILE__) + require 'rspec/rails' +require 'capybara/rspec' +require 'capybara/rails' +require 'capybara/poltergeist' +require 'shoulda-matchers' +require 'ffaker' require 'database_cleaner' -require 'spree/testing_support/url_helpers' -# Requires supporting files with custom matchers and macros, etc, -# in ./support/ and its subdirectories. -Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} +Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f } require 'spree/testing_support/factories' +require 'spree/testing_support/url_helpers' require 'spree/testing_support/controller_requests' require 'spree/testing_support/capybara_ext' -require 'ffaker' RSpec.configure do |config| - # == Mock Framework - # - # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: - # - # config.mock_with :mocha - # config.mock_with :flexmock - # config.mock_with :rr config.mock_with :rspec - config.color = true - config.fixture_path = "#{::Rails.root}/spec/fixtures" - - # If you're not using ActiveRecord, or you'd prefer not to run each of your - # examples within a transaction, comment the following line or assign false - # instead of true. config.use_transactional_fixtures = false - config.before(:each) do - if example.metadata[:js] - DatabaseCleaner.strategy = :truncation - else - DatabaseCleaner.strategy = :transaction - end + + # config.filter_run focus: true + + config.before :suite do + DatabaseCleaner.strategy = :transaction + DatabaseCleaner.clean_with :truncation end - config.before(:each) do + config.before do + DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction DatabaseCleaner.start ActionMailer::Base.deliveries.clear end - config.after(:each) do + config.after do DatabaseCleaner.clean Spree::Ability.abilities.delete(AbilityDecorator) if Spree::Ability.abilities.include?(AbilityDecorator) end @@ -57,7 +47,8 @@ config.include Spree::TestingSupport::ControllerRequests, :type => :controller config.include Devise::TestHelpers, :type => :controller config.include Rack::Test::Methods, :type => :feature - config.include Capybara::DSL + + Capybara.javascript_driver = :poltergeist end if defined? CanCan::Ability diff --git a/spree_auth_devise.gemspec b/spree_auth_devise.gemspec index 0187c5f5..d691e038 100644 --- a/spree_auth_devise.gemspec +++ b/spree_auth_devise.gemspec @@ -5,22 +5,47 @@ Gem::Specification.new do |s| s.name = 'spree_auth_devise' s.version = '2.2.0' s.summary = 'Provides authentication and authorization services for use with Spree by using Devise and CanCan.' - s.description = 'Required dependency for Spree' + s.description = s.summary s.required_ruby_version = '>= 1.9.3' s.author = 'Sean Schofield' s.email = 'sean@spreecommerce.com' s.homepage = 'http://spreecommerce.com' + s.license = %q{BSD-3} - s.files = Dir['LICENSE', 'README.md', 'app/**/*', 'config/**/*', 'lib/**/*', 'db/**/*'] + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- spec/*`.split("\n") s.require_path = 'lib' s.requirements << 'none' + s.has_rdoc = true + spree_version = '~> 2.2.0' s.add_dependency 'spree_core', spree_version s.add_dependency 'spree_frontend', spree_version s.add_dependency 'spree_backend', spree_version - s.add_dependency 'devise', '~> 3.2.2' + s.add_dependency 'devise', '~> 3.2.3' s.add_dependency 'devise-encryptable', '0.1.2' - s.add_dependency 'cancan', '~> 1.6.7' + s.add_dependency 'cancan', '~> 1.6.10' + + s.add_dependency 'json' + s.add_dependency 'multi_json' + + s.add_development_dependency 'sqlite3' + s.add_development_dependency 'mysql2' + s.add_development_dependency 'pg' + s.add_development_dependency 'sass-rails', '~> 4.0.0' + s.add_development_dependency 'coffee-rails', '~> 4.0.0' + s.add_development_dependency 'rspec-rails', '~> 2.14' + s.add_development_dependency 'factory_girl', '~> 4.4' + s.add_development_dependency 'email_spec', '~> 1.5.0' + s.add_development_dependency 'ffaker' + s.add_development_dependency 'shoulda-matchers', '~> 1.5' + s.add_development_dependency 'capybara', '~> 2.2.1' + s.add_development_dependency 'database_cleaner', '~> 1.2.0' + s.add_development_dependency 'selenium-webdriver' + s.add_development_dependency 'poltergeist', '~> 1.5.0' + s.add_development_dependency 'launchy' + s.add_development_dependency 'simplecov', '~> 0.7.1' + s.add_development_dependency 'pry' end