Commit 8022da91 by tady

fix rspec and `sign_in`

parent 1e92221c
class MeController < ApplicationController class UsersController < ApplicationController
before_action :set_user, only: [:edit, :update] before_action :set_user, only: [:edit, :update]
def edit def edit
...@@ -6,21 +7,20 @@ class MeController < ApplicationController ...@@ -6,21 +7,20 @@ class MeController < ApplicationController
def update def update
respond_to do |format| respond_to do |format|
if @me.update(user_params) if @user.update(user_params)
format.html { redirect_to edit_me_path, flash: { notice: 'Post was successfully updated.' } } format.html { redirect_to edit_user_path, flash: { notice: 'Post was successfully updated.' } }
format.json { head :no_content } format.json { head :no_content }
else else
format.html { render action: 'edit' } format.html { render action: 'edit' }
format.json { render json: @me.errors, status: :unprocessable_entity } format.json { render json: @user.errors, status: :unprocessable_entity }
end end
end end
end end
private private
# Use callbacks to share common setup or constraints between actions.
def set_user def set_user
@me = current_user @user = current_user
end end
def user_params def user_params
......
# == Schema Information
#
# Table name: notifications
#
# id :integer not null, primary key
# user_id :integer
# read_at :datetime
# is_read :boolean default(FALSE), not null
# detail_path :string(255)
# body :text
# created_at :datetime
# updated_at :datetime
#
class Notification < ActiveRecord::Base class Notification < ActiveRecord::Base
belongs_to :user belongs_to :user
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
# #
# Table name: tags # Table name: tags
# #
# id :integer not null, primary key # id :integer not null, primary key
# name :string(255) # name :string(255)
# created_at :datetime # created_at :datetime
# updated_at :datetime # updated_at :datetime
# ancestry :string(255) # ancestry :string(255)
# body :text # body :text
# posts_count :integer default(0), not null
# #
class Tag < ActiveRecord::Base class Tag < ActiveRecord::Base
......
...@@ -37,7 +37,7 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation" ...@@ -37,7 +37,7 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation"
| 下書き | 下書き
span.badge.pull-right = current_user.decorate.draft_count span.badge.pull-right = current_user.decorate.draft_count
li li
a href=edit_user_registration_path マイページ a href=edit_user_path マイページ
li.divider li.divider
li li
a href=destroy_user_session_path data-method="delete" rel="nofollow" SignOut a href=destroy_user_session_path data-method="delete" rel="nofollow" SignOut
......
#post-form #post-form
= form_for(@me, url: me_path) do |f| = form_for(@user, url: user_path) do |f|
- if @me.errors.any? - if @user.errors.any?
#error_explanation #error_explanation
h2 h2
= pluralize(@me.errors.count, "error") = pluralize(@user.errors.count, "error")
| prohibited this post from being saved: | prohibited this post from being saved:
ul ul
- @me.errors.full_messages.each do |msg| - @user.errors.full_messages.each do |msg|
li= msg li= msg
.row .row
......
...@@ -26,8 +26,16 @@ Rendezvous::Application.routes.draw do ...@@ -26,8 +26,16 @@ Rendezvous::Application.routes.draw do
devise_for :users, devise_for :users,
path_names: { current_user: 'me' }, path_names: { current_user: 'me' },
controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }, controllers: {
skip: [:passwords] omniauth_callbacks: 'users/omniauth_callbacks',
registrations: 'users/registrations'
},
skip: [
:passwords,
:registrations,
]
resource :user
# The priority is based upon order of creation: first created -> highest priority. # The priority is based upon order of creation: first created -> highest priority.
......
require 'spec_helper' require 'spec_helper'
describe ApisController do describe ApisController, type: :controller do
describe "GET 'markdown_preview'" do describe "GET 'markdown_preview'" do
it "returns http redirect" do it "returns http redirect" do
...@@ -10,9 +10,9 @@ describe ApisController do ...@@ -10,9 +10,9 @@ describe ApisController do
end end
describe "GET 'markdown_preview'" do describe "GET 'markdown_preview'" do
login_user
it "returns http success" do it "returns http success" do
sign_in FactoryGirl.create(:alice)
get 'markdown_preview' get 'markdown_preview'
expect(response).to be_success expect(response).to be_success
end end
......
require 'spec_helper' require 'spec_helper'
describe FlowController do describe FlowController, type: :controller do
describe "GET 'show' without login" do describe "GET 'show' without login" do
it "returns http redirect" do it "returns http redirect" do
...@@ -10,9 +10,9 @@ describe FlowController do ...@@ -10,9 +10,9 @@ describe FlowController do
end end
describe "GET 'show' with login" do describe "GET 'show' with login" do
login_user
it "returns http success" do it "returns http success" do
sign_in FactoryGirl.create(:alice)
get 'show' get 'show'
expect(response).to be_success expect(response).to be_success
end end
......
require 'spec_helper' require 'spec_helper'
describe SearchController do describe SearchController, type: :controller do
describe "GET 'show' without login" do describe "GET 'show' without login" do
it "returns http redirect" do it "returns http redirect" do
...@@ -10,9 +10,9 @@ describe SearchController do ...@@ -10,9 +10,9 @@ describe SearchController do
end end
describe "GET 'show' with login" do describe "GET 'show' with login" do
login_user
it "returns http success" do it "returns http success" do
sign_in FactoryGirl.create(:alice)
get 'show' get 'show'
expect(response).to be_success expect(response).to be_success
end end
......
require 'spec_helper' require 'spec_helper'
describe StockController do describe StockController, type: :controller do
describe "GET 'show' without login" do describe "GET 'show' without login" do
it "returns http redirect" do it "returns http redirect" do
...@@ -10,9 +10,9 @@ describe StockController do ...@@ -10,9 +10,9 @@ describe StockController do
end end
describe "GET 'show' with login" do describe "GET 'show' with login" do
login_user
it "returns http success" do it "returns http success" do
sign_in FactoryGirl.create(:alice)
get 'show' get 'show'
expect(response).to be_success expect(response).to be_success
end end
......
require 'spec_helper' require 'spec_helper'
describe TagsController do describe TagsController, type: :controller do
let(:tag) { FactoryGirl.create(:tag_ruby) } let(:tag) { FactoryGirl.create(:tag_ruby) }
...@@ -12,9 +12,9 @@ describe TagsController do ...@@ -12,9 +12,9 @@ describe TagsController do
end end
describe "GET 'show' with login" do describe "GET 'show' with login" do
login_user
it "returns http success" do it "returns http success" do
sign_in FactoryGirl.create(:alice)
get 'show', name: tag.name get 'show', name: tag.name
expect(response).to be_success expect(response).to be_success
end end
......
require 'spec_helper' require 'spec_helper'
describe MeController do describe UsersController, type: :controller do
before do
end
describe "GET 'edit'" do describe "GET 'edit'" do
login_user
it "returns http success" do it "returns http success" do
sign_in FactoryGirl.create(:alice)
get :edit get :edit
response.should be_success response.should be_success
end end
end end
describe "GET 'update'" do describe "GET 'update'" do
login_user
it "returns http success" do it "returns http success" do
sign_in FactoryGirl.create(:alice)
patch :update, user: { nickname: 'bob' } patch :update, user: { nickname: 'bob' }
response.should redirect_to('/me/edit') response.should redirect_to('/user/edit')
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe WelcomeController do describe WelcomeController, type: :controller do
describe "GET 'top'" do describe "GET 'top'" do
it 'should be successful' do it 'should be successful' do
...@@ -12,22 +12,23 @@ describe WelcomeController do ...@@ -12,22 +12,23 @@ describe WelcomeController do
describe 'Login' do describe 'Login' do
before(:each) do let(:user) { FactoryGirl.create(:alice) }
@user = FactoryGirl.create(:login_user_1)
sign_in @user
end
describe "GET 'top'" do describe "GET 'top'" do
it 'should be successful' do it 'should be successful' do
sign_in FactoryGirl.create(:alice)
get :top get :top
expect(subject).to redirect_to controller: 'flow', expect(subject).to redirect_to controller: 'flow',
action: 'show' action: 'show'
end end
it 'should find the right user' do it 'should find the right user' do
sign_in user
get :top get :top
expect(assigns(:current_user)).to eq(@user) expect(assigns(:current_user)).to eq(user)
end end
end end
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
# #
# Table name: tags # Table name: tags
# #
# id :integer not null, primary key # id :integer not null, primary key
# name :string(255) # name :string(255)
# created_at :datetime # created_at :datetime
# updated_at :datetime # updated_at :datetime
# ancestry :string(255) # ancestry :string(255)
# body :text # body :text
# posts_count :integer default(0), not null
# #
# Read about factories at https://github.com/thoughtbot/factory_girl # Read about factories at https://github.com/thoughtbot/factory_girl
......
# == Schema Information
#
# Table name: notifications
#
# id :integer not null, primary key
# user_id :integer
# read_at :datetime
# is_read :boolean default(FALSE), not null
# detail_path :string(255)
# body :text
# created_at :datetime
# updated_at :datetime
#
require 'spec_helper' require 'spec_helper'
describe Notification do describe Notification do
......
...@@ -70,42 +70,42 @@ describe Post do ...@@ -70,42 +70,42 @@ describe Post do
end end
it 'by id' do it 'by id' do
expect(Post.search('id:1001')).to have(1).items expect(Post.search('id:1001').size).to eq(1)
expect(Post.search('id:1001')).to include(@post1) expect(Post.search('id:1001')).to include(@post1)
end end
it 'by title' do it 'by title' do
expect(Post.search('title:ruby')).to have(2).items expect(Post.search('title:ruby').size).to eq(2)
expect(Post.search('title:ruby')).to include(@post1) expect(Post.search('title:ruby')).to include(@post1)
end end
it 'by body' do it 'by body' do
expect(Post.search('body:ruby')).to have(2).items expect(Post.search('body:ruby').size).to eq(2)
expect(Post.search('body:ruby')).to include(@post3) expect(Post.search('body:ruby')).to include(@post3)
end end
it 'by @<author_name>' do it 'by @<author_name>' do
expect(Post.search('@Alice')).to have(1).items expect(Post.search('@Alice').size).to eq(1)
expect(Post.search('@Alice')).to include(@post2) expect(Post.search('@Alice')).to include(@post2)
end end
it 'by #<tag_name>' do it 'by #<tag_name>' do
expect(Post.search('#java')).to have(1).items expect(Post.search('#java').size).to eq(1)
expect(Post.search('#java')).to include(@post3) expect(Post.search('#java')).to include(@post3)
end end
it 'by date' do it 'by date' do
expect(Post.search('date:1989-2-25')).to have(1).items expect(Post.search('date:1989-2-25').size).to eq(1)
expect(Post.search('date:1989-2-25')).to include(@post3) expect(Post.search('date:1989-2-25')).to include(@post3)
end end
it 'by draft' do it 'by draft' do
expect(Post.search('ruby')).to have(3).items expect(Post.search('ruby').size).to eq(3)
expect(Post.search('ruby draft:1')).to have(1).items expect(Post.search('ruby draft:1').size).to eq(1)
end end
it 'by else' do it 'by else' do
expect(Post.search('ruby')).to have(3).items expect(Post.search('ruby').size).to eq(3)
expect(Post.search('ruby')).to include(@post1) expect(Post.search('ruby')).to include(@post1)
expect(Post.search('ruby')).to include(@post3) expect(Post.search('ruby')).to include(@post3)
end end
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
# #
# Table name: tags # Table name: tags
# #
# id :integer not null, primary key # id :integer not null, primary key
# name :string(255) # name :string(255)
# created_at :datetime # created_at :datetime
# updated_at :datetime # updated_at :datetime
# ancestry :string(255) # ancestry :string(255)
# body :text # body :text
# posts_count :integer default(0), not null
# #
require 'spec_helper' require 'spec_helper'
...@@ -23,11 +24,11 @@ describe Tag do ...@@ -23,11 +24,11 @@ describe Tag do
end end
it 'successfully moved' do it 'successfully moved' do
expect(Tag.find_by(name: 'ruby').posts).to have(2).items expect(Tag.find_by(name: 'ruby').posts.size).to eq(2)
expect(Tag.find_by(name: 'java').posts).to have(2).items expect(Tag.find_by(name: 'java').posts.size).to eq(2)
@tag_java.move_all_posts_to!(@tag_ruby) @tag_java.move_all_posts_to!(@tag_ruby)
expect(Tag.find_by(name: 'ruby').posts).to have(3).items expect(Tag.find_by(name: 'ruby').posts.size).to eq(3)
expect(Tag.find_by(name: 'java').posts).to have(0).items expect(Tag.find_by(name: 'java').posts.size).to eq(0)
end end
end end
......
...@@ -35,11 +35,11 @@ describe User do ...@@ -35,11 +35,11 @@ describe User do
describe '#google_oauth_token_expired?' do describe '#google_oauth_token_expired?' do
it 'not expired' do it 'not expired' do
expect(alice.google_oauth_token_expired?).to be_false expect(alice.google_oauth_token_expired?).to be_falsey
end end
it 'expired' do it 'expired' do
expect(bob.google_oauth_token_expired?).to be_true expect(bob.google_oauth_token_expired?).to be_truthy
end end
end end
......
...@@ -95,7 +95,7 @@ RSpec.configure do |config| ...@@ -95,7 +95,7 @@ RSpec.configure do |config|
end end
config.include Devise::TestHelpers, :type => :controller config.include Devise::TestHelpers, :type => :controller
config.extend ControllerMacros, :type => :controller # config.extend ControllerMacros, :type => :controller
# Capybara.app_host = "http://127.0.0.1/" # Capybara.app_host = "http://127.0.0.1/"
register_poltergeist(config) register_poltergeist(config)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment