Created
September 18, 2013 08:05
-
-
Save robbl/6606069 to your computer and use it in GitHub Desktop.
Compare controller specs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe My::Profiles::PostsController do | |
let(:user) { stub_model(User) } | |
let(:profile) { stub_model(Profile) } | |
let(:post) { stub_model(Post) } | |
describe "PUT 'update'" do | |
before do | |
request.env['warden'].stub :authenticate! => user | |
controller.stub :current_user => user | |
User.any_instance.stub_chain(:profiles, :find).and_return(profile) | |
Profile.any_instance.stub_chain(:posts, :find_by_id).and_return(post) | |
post.stub(:update_attributes).and_return(success) | |
put :update, profile_id: profile.id, id: post.id, post: { title: 'changedTitle' } | |
end | |
context 'on success' do | |
let(:success) { true } | |
it { should assign(profile).to(:profile) } | |
it { should assign(post).to(:post) } | |
it { should respond_with(:redirect) } | |
it { should redirect_to(my_profile_post_path(profile, post)) } | |
it { should set_the_flash[:notice].now } | |
end | |
context 'on failure' do | |
let(:success) { false } | |
it { should assign(profile).to(:profile) } | |
it { should assign(post).to(:post) } | |
it { should respond_with(:success) } | |
it { should set_the_flash[:error].now } | |
it { should render_template(:edit) } | |
end | |
end | |
end | |
describe My::Profiles::PostsController do | |
include_context 'given a user is chief of a profile' | |
context 'when logged in' do | |
include_context 'given the user is logged in' | |
context 'with a existing post' do | |
include_context 'given the profile has a post' | |
describe "PUT 'update'" do | |
before { put :update, profile_id: profile.id, id: post.id, post: post_attributes } | |
context 'on success' do | |
let(:post_attributes) { { title: 'changedTitle' } } | |
it { should assign(profile).to(:profile) } | |
it { should assign(post).to(:post) } | |
it { should update(post, :title).with('changedTitle') } | |
it { should respond_with(:redirect) } | |
it { should redirect_to(my_profile_post_path(profile, post)) } | |
it { should set_the_flash[:notice].now } | |
end | |
context 'on failure' do | |
let(:post_attributes) { { title: '' } } | |
it { should assign(profile).to(:profile) } | |
it { should assign(post).to(:post) } | |
it { should_not update(post, :updated_at) } | |
it { should respond_with(:success) } | |
it { should set_the_flash[:error].now } | |
it { should render_template(:edit) } | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment