Use new "strong parameters" from rails4

This commit is contained in:
Thibault Jouan
2014-04-03 02:20:37 +00:00
parent 1b5055d0a6
commit 4c6adc6927
13 changed files with 41 additions and 23 deletions

View File

@@ -1,28 +1,34 @@
require 'spec_helper'
describe UsersController do
let(:attributes) { FactoryGirl.attributes_for(:user) }
describe 'GET new' do
it 'assigns a new user as @user' do
get :new
expect(assigns[:user]).to be_a_new(User)
expect(assigns[:user]).to be_a_new User
end
end
describe 'POST create' do
def do_post(params = {})
post :create, user: attributes.merge(params)
end
context 'whith valid params' do
it 'creates a new user' do
expect {
post :create, user: FactoryGirl.attributes_for(:user)
do_post
}.to change(User, :count).by(1)
end
it 'signs the user in' do
post :create, user: FactoryGirl.attributes_for(:user)
do_post
expect(controller.current_user).not_to be_nil
end
it 'redirects to the home page' do
post :create, user: FactoryGirl.attributes_for(:user)
do_post
expect(response).to redirect_to :root
end
end
@@ -31,12 +37,12 @@ describe UsersController do
before { allow_any_instance_of(User).to receive(:save) { false } }
it 'assigns the user as @user' do
post :create, user: {}
do_post
expect(assigns[:user]).to be_a_new User
end
it 'renders the new template' do
post :create, user: {}
do_post
expect(response).to render_template 'new'
end
end

View File

@@ -8,5 +8,4 @@ describe Playlist do
it { should belong_to :user }
it { should validate_presence_of :user }
it { should validate_presence_of :name }
it { should_not allow_mass_assignment_of :user }
end

View File

@@ -8,7 +8,6 @@ describe Track do
it { should be_valid }
it { should have_many :sounds }
it { should validate_presence_of :name }
it { should_not allow_mass_assignment_of :sounds }
context 'with a file' do
before { track.file = file }

View File

@@ -9,7 +9,6 @@ describe User do
it { should validate_presence_of :email }
it { should validate_presence_of :password }
it { should validate_presence_of :password_hash }
it { should_not allow_mass_assignment_of :password_hash }
context 'when a user with the same email address already exists' do
let(:old_user) { FactoryGirl.create(:user, email: 'unique@example.net') }