Created
February 13, 2011 11:25
-
-
Save RStankov/824609 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Accounts::ProjectsController < Accounts::BaseController | |
def show | |
@project = find_project | |
end | |
def update | |
@project = find_project | |
if @project.update_attributes(params[:project]) | |
redirect_to [@account, @project], :notice => 'Project updated!' | |
else | |
render "edit" | |
end | |
end | |
def destroy | |
@project = find_project | |
redirect_to [@account, :projects] | |
end | |
private | |
def find_project | |
@account.projects.find(params[:id]) | |
end | |
end |
This file contains hidden or 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 Accounts::ProjectsController do | |
before { sign_up_and_mock_account } | |
let(:current_user){ @current_user } | |
let(:account){ mock_account(:projects => projects) } | |
let(:project){ mock_project } | |
let(:projects){ [project].tap { |projects| projects.stub :find => project } } | |
describe "with admin user" do | |
before { account.should_receive(:admin?).with(current_user).and_return true } | |
describe "PUT update" do | |
describe "with valid params" do | |
before { project.should_receive(:update_attributes).with({'these' => 'params'}).and_return true } | |
before { put :update, :account_id => "1", :id => "2", :project => {:these => 'params'} } | |
it { should assign_to(:project).with(project) } | |
it { should set_the_flash } | |
it { should redirect_to(account_project_url(account, project)) } | |
end | |
describe "with invalid params" do | |
before { project.should_receive(:update_attributes).with({'these' => 'params'}).and_return false } | |
before { put :update, :account_id => "1", :id => "2", :project => {:these => 'params'} } | |
it { should assign_to(:project).with(project) } | |
it { should render_template("edit") } | |
end | |
end | |
describe "GET show" do | |
before { get :show, :account_id => "1", :id => "2" } | |
it { should assign_to(:project).with(project) } | |
it { should render_template(:show) } | |
end | |
describe "DELETE destroy" do | |
before { project.should_receive(:destroy) } | |
before { delete :destroy, :account_id => "1", :id => "2" } | |
it { should redirect_to(account_projects_url(account)) } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment