require 'spec_helper' describe PermissionsController, "routes" do it { should route(:get, "/accounts/abc/users/def/permissions/edit"). to(:action => :edit, :account_id => 'abc', :user_id => 'def') } it { should route(:put, "/accounts/abc/users/def/permissions"). to(:action => :update, :account_id => 'abc', :user_id => 'def') } end describe PermissionsController, "permissions", :as => :account_member do let(:user) { Factory.stub(:user) } it { should deny_access. on(:get, :edit, :account_id => account.to_param, :user_id => user.to_param). flash(/admin/) } end describe PermissionsController, "edit", :as => :account_admin do let(:edited_user) { Factory.stub(:user) } let(:projects) { [Factory.stub(:project)] } before do Account.stubs(:find_by_url! => account) User.stubs(:find => edited_user) account.stubs(:projects_by_name => projects) get :edit, :account_id => account.to_param, :user_id => edited_user.to_param end it "renders the edit template" do should respond_with(:success) should render_template(:edit) end it "assigns projects by name" do account.should have_received(:projects_by_name) should assign_to(:projects).with(projects) end it "assigns the user being edited" do should assign_to(:user).with(edited_user) end end describe PermissionsController, "update", :as => :account_admin do let(:edited_user) { Factory.stub(:user) } let(:project_ids) { [1, 2, 3] } before do Account.stubs(:find_by_url! => account) User.stubs(:find => edited_user) edited_user.stubs(:update_permissions_for) put :update, :account_id => account.to_param, :user_id => edited_user.to_param, :permissions => { :project_ids => project_ids } end it "redirects to the memberships index" do should redirect_to(account_memberships_url(account)) end it "update permissions" do edited_user.should have_received(:update_permissions_for).with(account, project_ids) end it "sets a flash message" do should set_the_flash.to(/update/i) end end