I do "my" project, with an eye on http://railstutorial.ru/
When running tests, I encounter the following error:
1) Authentication authorization for non-signed-in users in the Users controller submitting to the update action Failure/Error: before { patch user_path(user) } NoMethodError: undefined method `patch' for #<RSpec::ExampleGroups::Authentication::Authorization::ForNonSignedInUsers::InTheUsersController::SubmittingToTheUpdateAction:0x000000046ee408> # ./spec/requests/authentication_pages_spec.rb:63:in `block (6 levels) in <top (required)>'
My spec / requests / authentication_pages_spec.rb
require 'spec_helper' describe "Authentication" do subject { page } describe "signin page" do before { visit signin_path } it { should have_content('Sign in') } it { should have_title('Sign in') } end describe "signin" do before { visit signin_path } describe "with invalid information" do before { click_button "Sign in" } it { should have_title('Sign in') } it { should have_selector('div.alert.alert-error') } describe "after visiting another page" do before { click_link "Home" } it { should_not have_selector('div.alert.alert-error') } end end describe "with valid information" do let(:user) { FactoryGirl.create(:user) } before do fill_in "Email", with: user.email.upcase fill_in "Password", with: user.password click_button "Sign in" end it { should have_title(user.name) } it { should have_link('Profile', href: user_path(user)) } it { should have_link('Sign out', href: signout_path) } it { should_not have_link('Sign in', href: signin_path) } it { should have_link('Settings', href: edit_user_path(user)) } describe "followed by signout" do before { click_link "Sign out" } it { should have_link('Sign in') } end end end describe "authorization" do describe "for non-signed-in users" do let(:user) { FactoryGirl.create(:user) } describe "in the Users controller" do describe "visiting the edit page" do before { visit edit_user_path(user) } it { should have_title('Sign in') } end describe "submitting to the update action" do before { patch user_path(user) } specify { expect(response).to redirect_to(signin_path) } end end end end end
utilities.rb:
def full_title(page_title) base_title = "Callboard" if page_title.empty? base_title else "#{base_title} | #{page_title}" end end def sign_in(user, options={}) if options[:no_capybara] # Sign in when not using Capybara. remember_token = User.new_remember_token cookies[:remember_token] = remember_token user.update_attribute(:remember_token, User.encrypt(remember_token)) else visit signin_path fill_in "Email", with: user.email fill_in "Password", with: user.password click_button "Sign in" end end
Gemfile:
source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.2' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.1.0' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem 'turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc gem 'bcrypt-ruby' gem 'bootstrap-sass' gem 'validates_timeliness' gem 'factory_girl_rails' # Покрытие тестами gem 'simplecov', :require => false, :group => :test group :development, :test do gem 'rspec-rails' gem 'capybara' # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' end group :test do gem 'selenium-webdriver', '2.35.1' end group :production do gem 'pg', '0.15.1' gem 'rails_12factor', '0.0.2' end
routes.rb:
Rails.application.routes.draw do resources :users resources :sessions, only: [:new, :create, :destroy] root 'static_pages#home' match '/help', to: 'static_pages#help', via: 'get' match '/about', to: 'static_pages#about', via: 'get' match '/signup', to: 'users#new', via: 'get' match '/signin', to: 'sessions#new', via: 'get' match '/signout', to: 'sessions#destroy', via: 'delete' end
Link to the rest of the code https://bitbucket.org/Tiazar/callboard