From 1af153e45f2700ab0785da810ea447415f844a41 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Wed, 30 Oct 2013 15:29:47 +0100 Subject: [PATCH] Working and specced supplier signup --- app/assets/javascripts/application.js | 2 +- app/controllers/confirmations_controller.rb | 10 ++++++ app/models/supplier.rb | 4 +-- app/views/devise/registrations/new.html.slim | 19 ++++++++++ config/initializers/devise.rb | 2 ++ config/routes.rb | 2 +- spec/acceptance/suppliers/settings.feature | 2 ++ spec/acceptance/suppliers/signup.feature | 11 ++++++ .../suppliers/navigation_steps.rb | 5 +++ .../suppliers/signup_steps.rb | 36 +++++++++++++++++++ spec/spec_helper.rb | 2 +- 11 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 app/controllers/confirmations_controller.rb create mode 100644 app/views/devise/registrations/new.html.slim create mode 100644 spec/acceptance/suppliers/settings.feature create mode 100644 spec/acceptance/suppliers/signup.feature create mode 100644 spec/acceptance_steps/suppliers/signup_steps.rb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index dc34e5fd..13d11e8c 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,7 +12,7 @@ // //= require jquery //= require jquery_ujs -//= require jquery-ui +//= require jquery.ui.all //= require bootstrap //= require_directory . //= require_self diff --git a/app/controllers/confirmations_controller.rb b/app/controllers/confirmations_controller.rb new file mode 100644 index 00000000..ad7a1506 --- /dev/null +++ b/app/controllers/confirmations_controller.rb @@ -0,0 +1,10 @@ +class ConfirmationsController < Devise::ConfirmationsController + private + + def after_confirmation_path_for(resource_name, resource) + case resource_name + when :supplier then supplier_settings_path + else root_path + end + end +end diff --git a/app/models/supplier.rb b/app/models/supplier.rb index 4306764c..252ef20c 100644 --- a/app/models/supplier.rb +++ b/app/models/supplier.rb @@ -104,12 +104,12 @@ class Supplier end # Send confirmation instructions by email - def send_confirmation_instructions + def send_confirmation_instructions(*args) self.confirmation_token = nil if reconfirmation_required? @reconfirmation_required = false @bypass_postpone = true and generate_confirmation_token! if self.confirmation_token.blank? - self.devise_mailer.confirmation_instructions(self).deliver + self.devise_mailer.confirmation_instructions(self, confirmation_token).deliver end def find_order(id) diff --git a/app/views/devise/registrations/new.html.slim b/app/views/devise/registrations/new.html.slim new file mode 100644 index 00000000..7e4d99ef --- /dev/null +++ b/app/views/devise/registrations/new.html.slim @@ -0,0 +1,19 @@ +h2= t('devise.registrations.title') += form_for(resource, :as => resource_name, :url => registration_path(resource_name), html: {class: 'form-horizontal'}) do |f| + = devise_error_messages! + .control-group + = f.label :name, class: 'control-label' + .controls= f.text_field :name + .control-group + = f.label :email, class: 'control-label' + .controls= f.email_field :email + .control-group + = f.label :password, class: 'control-label' + .controls= f.password_field :password + .control-group + = f.label :password_confirmation, class: 'control-label' + .controls= f.password_field :password_confirmation + .control-group + .controls + = f.submit t('devise.registrations.button'), class: 'btn btn-primary' += render "devise_links" diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 46ce5a06..3be6173a 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -48,6 +48,8 @@ Devise.setup do |config| # modifying a user and when used to authenticate or find a user. Default is :email. config.strip_whitespace_keys = [ :email ] + config.allow_insecure_sign_in_after_confirmation = true + # Tell if authentication through request.params is enabled. True by default. # It can be set to an array that will enable params authentication only for the # given strategies, for example, `config.params_authenticatable = [:database]` will diff --git a/config/routes.rb b/config/routes.rb index acf666d9..b6911b7b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Qwaiter::Application.routes.draw do devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" } - devise_for :suppliers + devise_for :suppliers, controllers: { confirmations: 'confirmations' } devise_for :administrators namespace :admin do resources :users diff --git a/spec/acceptance/suppliers/settings.feature b/spec/acceptance/suppliers/settings.feature new file mode 100644 index 00000000..78ff07bb --- /dev/null +++ b/spec/acceptance/suppliers/settings.feature @@ -0,0 +1,2 @@ +Feature: Manage settings + Scenario: Changing the supplier email diff --git a/spec/acceptance/suppliers/signup.feature b/spec/acceptance/suppliers/signup.feature new file mode 100644 index 00000000..d0ed5544 --- /dev/null +++ b/spec/acceptance/suppliers/signup.feature @@ -0,0 +1,11 @@ +Feature: A supplier can sign up + Scenario: It works + When I visit the supplier signup path + And fill in the supplier signup form with new credentials + And click on the supplier signup submit button + Then a new unconfirmed supplier with the new signup credentials should be created + And a supplier signup confirmation mail should be sent containing a link to the token + When I visit the supplier signup confirmation path with the correct token + Then the new signup supplier should be confirmed + And I should be redirected to the supplier settings page + diff --git a/spec/acceptance_steps/suppliers/navigation_steps.rb b/spec/acceptance_steps/suppliers/navigation_steps.rb index 9696e795..c7838d30 100644 --- a/spec/acceptance_steps/suppliers/navigation_steps.rb +++ b/spec/acceptance_steps/suppliers/navigation_steps.rb @@ -9,3 +9,8 @@ end step "I visit the supplier section path" do visit "/supplier/sections/#{@section.id}" end + + +step "I should be redirected to the supplier settings page" do + page.current_path.should == supplier_settings_path +end diff --git a/spec/acceptance_steps/suppliers/signup_steps.rb b/spec/acceptance_steps/suppliers/signup_steps.rb new file mode 100644 index 00000000..539874f6 --- /dev/null +++ b/spec/acceptance_steps/suppliers/signup_steps.rb @@ -0,0 +1,36 @@ + +step "I visit the supplier signup path" do + visit new_supplier_registration_path +end + +step "fill in the supplier signup form with new credentials" do + find('#supplier_name').set 'Signup Supplier' + find('#supplier_email').set 'signup_supplier@example.com' + find('#supplier_password').set 'SignupSupplier' + find('#supplier_password_confirmation').set 'SignupSupplier' +end + +step "click on the supplier signup submit button" do + find('[name="commit"]').click +end + +step "a new unconfirmed supplier with the new signup credentials should be created" do + @signup_supplier = Supplier.find_by_email('signup_supplier@example.com') + @signup_supplier.should be_present + @signup_supplier.should_not be_confirmed +end + +step "a supplier signup confirmation mail should be sent containing a link to the token" do + mail = ActionMailer::Base.deliveries.last + mail.should be_present + mail.body.should match /confirmation_token=#{@signup_supplier.confirmation_token}/ +end + +step "I visit the supplier signup confirmation path with the correct token" do + visit supplier_confirmation_path(confirmation_token: @signup_supplier.confirmation_token) +end + +step "the new signup supplier should be confirmed" do + @signup_supplier.reload + @signup_supplier.should be_confirmed +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d98c41af..0764bafb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -64,7 +64,7 @@ RSpec.configure do |config| end config.before :each, type: :feature do - Supplier.any_instance.stub send_confirmation_instructions: true + #Supplier.any_instance.stub send_confirmation_instructions: true end # If true, the base class of anonymous controllers will be inferred