Commit 8022da91 by tady

fix rspec and `sign_in`

parent 1e92221c
class MeController < ApplicationController
class UsersController < ApplicationController
before_action :set_user, only: [:edit, :update]
def edit
......@@ -6,21 +7,20 @@ class MeController < ApplicationController
def update
respond_to do |format|
if @me.update(user_params)
format.html { redirect_to edit_me_path, flash: { notice: 'Post was successfully updated.' } }
if @user.update(user_params)
format.html { redirect_to edit_user_path, flash: { notice: 'Post was successfully updated.' } }
format.json { head :no_content }
else
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
private
# Use callbacks to share common setup or constraints between actions.
def set_user
@me = current_user
@user = current_user
end
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
belongs_to :user
......
......@@ -8,6 +8,7 @@
# updated_at :datetime
# ancestry :string(255)
# body :text
# posts_count :integer default(0), not null
#
class Tag < ActiveRecord::Base
......
......@@ -37,7 +37,7 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation"
| 下書き
span.badge.pull-right = current_user.decorate.draft_count
li
a href=edit_user_registration_path マイページ
a href=edit_user_path マイページ
li.divider
li
a href=destroy_user_session_path data-method="delete" rel="nofollow" SignOut
......
#post-form
= form_for(@me, url: me_path) do |f|
- if @me.errors.any?
= form_for(@user, url: user_path) do |f|
- if @user.errors.any?
#error_explanation
h2
= pluralize(@me.errors.count, "error")
= pluralize(@user.errors.count, "error")
| prohibited this post from being saved:
ul
- @me.errors.full_messages.each do |msg|
- @user.errors.full_messages.each do |msg|
li= msg
.row
......
......@@ -26,8 +26,16 @@ Rendezvous::Application.routes.draw do
devise_for :users,
path_names: { current_user: 'me' },
controllers: { omniauth_callbacks: 'users/omniauth_callbacks' },
skip: [:passwords]
controllers: {
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.
......
require 'spec_helper'
describe ApisController do
describe ApisController, type: :controller do
describe "GET 'markdown_preview'" do
it "returns http redirect" do
......@@ -10,9 +10,9 @@ describe ApisController do
end
describe "GET 'markdown_preview'" do
login_user
it "returns http success" do
sign_in FactoryGirl.create(:alice)
get 'markdown_preview'
expect(response).to be_success
end
......
require 'spec_helper'
describe FlowController do
describe FlowController, type: :controller do
describe "GET 'show' without login" do
it "returns http redirect" do
......@@ -10,9 +10,9 @@ describe FlowController do
end
describe "GET 'show' with login" do
login_user
it "returns http success" do
sign_in FactoryGirl.create(:alice)
get 'show'
expect(response).to be_success
end
......
require 'spec_helper'
describe SearchController do
describe SearchController, type: :controller do
describe "GET 'show' without login" do
it "returns http redirect" do
......@@ -10,9 +10,9 @@ describe SearchController do
end
describe "GET 'show' with login" do
login_user
it "returns http success" do
sign_in FactoryGirl.create(:alice)
get 'show'
expect(response).to be_success
end
......
require 'spec_helper'
describe StockController do
describe StockController, type: :controller do
describe "GET 'show' without login" do
it "returns http redirect" do
......@@ -10,9 +10,9 @@ describe StockController do
end
describe "GET 'show' with login" do
login_user
it "returns http success" do
sign_in FactoryGirl.create(:alice)
get 'show'
expect(response).to be_success
end
......
require 'spec_helper'
describe TagsController do
describe TagsController, type: :controller do
let(:tag) { FactoryGirl.create(:tag_ruby) }
......@@ -12,9 +12,9 @@ describe TagsController do
end
describe "GET 'show' with login" do
login_user
it "returns http success" do
sign_in FactoryGirl.create(:alice)
get 'show', name: tag.name
expect(response).to be_success
end
......
require 'spec_helper'
describe MeController do
before do
end
describe UsersController, type: :controller do
describe "GET 'edit'" do
login_user
it "returns http success" do
sign_in FactoryGirl.create(:alice)
get :edit
response.should be_success
end
end
describe "GET 'update'" do
login_user
it "returns http success" do
sign_in FactoryGirl.create(:alice)
patch :update, user: { nickname: 'bob' }
response.should redirect_to('/me/edit')
response.should redirect_to('/user/edit')
end
end
......
require 'spec_helper'
describe WelcomeController do
describe WelcomeController, type: :controller do
describe "GET 'top'" do
it 'should be successful' do
......@@ -12,22 +12,23 @@ describe WelcomeController do
describe 'Login' do
before(:each) do
@user = FactoryGirl.create(:login_user_1)
sign_in @user
end
let(:user) { FactoryGirl.create(:alice) }
describe "GET 'top'" do
it 'should be successful' do
sign_in FactoryGirl.create(:alice)
get :top
expect(subject).to redirect_to controller: 'flow',
action: 'show'
end
it 'should find the right user' do
sign_in user
get :top
expect(assigns(:current_user)).to eq(@user)
expect(assigns(:current_user)).to eq(user)
end
end
......
......@@ -8,6 +8,7 @@
# updated_at :datetime
# ancestry :string(255)
# body :text
# posts_count :integer default(0), not null
#
# 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'
describe Notification do
......
......@@ -70,42 +70,42 @@ describe Post do
end
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)
end
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)
end
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)
end
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)
end
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)
end
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)
end
it 'by draft' do
expect(Post.search('ruby')).to have(3).items
expect(Post.search('ruby draft:1')).to have(1).items
expect(Post.search('ruby').size).to eq(3)
expect(Post.search('ruby draft:1').size).to eq(1)
end
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(@post3)
end
......
......@@ -8,6 +8,7 @@
# updated_at :datetime
# ancestry :string(255)
# body :text
# posts_count :integer default(0), not null
#
require 'spec_helper'
......@@ -23,11 +24,11 @@ describe Tag do
end
it 'successfully moved' do
expect(Tag.find_by(name: 'ruby').posts).to have(2).items
expect(Tag.find_by(name: 'java').posts).to have(2).items
expect(Tag.find_by(name: 'ruby').posts.size).to eq(2)
expect(Tag.find_by(name: 'java').posts.size).to eq(2)
@tag_java.move_all_posts_to!(@tag_ruby)
expect(Tag.find_by(name: 'ruby').posts).to have(3).items
expect(Tag.find_by(name: 'java').posts).to have(0).items
expect(Tag.find_by(name: 'ruby').posts.size).to eq(3)
expect(Tag.find_by(name: 'java').posts.size).to eq(0)
end
end
......
......@@ -35,11 +35,11 @@ describe User do
describe '#google_oauth_token_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
it 'expired' do
expect(bob.google_oauth_token_expired?).to be_true
expect(bob.google_oauth_token_expired?).to be_truthy
end
end
......
......@@ -95,7 +95,7 @@ RSpec.configure do |config|
end
config.include Devise::TestHelpers, :type => :controller
config.extend ControllerMacros, :type => :controller
# config.extend ControllerMacros, :type => :controller
# Capybara.app_host = "http://127.0.0.1/"
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