add spec for admins_controller#add_invites
This commit is contained in:
parent
0ee41b3be5
commit
a060acffeb
2 changed files with 42 additions and 8 deletions
|
|
@ -9,16 +9,15 @@ class AdminsController < ApplicationController
|
|||
end
|
||||
|
||||
def add_invites
|
||||
u = User.find(params[:user_id])
|
||||
user = User.find(params[:user_id])
|
||||
|
||||
if u
|
||||
notice = "Great Job!"
|
||||
u.update_attributes(:invites => (u.invites += 10))
|
||||
if user.increment(:invites, 10).save
|
||||
flash[:notice] = "Great Job!"
|
||||
else
|
||||
notice = "there was a problem adding invites"
|
||||
flash[:alert] = "there was a problem adding invites"
|
||||
end
|
||||
|
||||
redirect_to :back, :notice => notice, :user => {:id => u.id}
|
||||
redirect_to user_search_path(:user => { :id => user.id })
|
||||
end
|
||||
|
||||
def admin_inviter
|
||||
|
|
@ -27,6 +26,6 @@ class AdminsController < ApplicationController
|
|||
opts.merge!(:existing_user => existing_user) if existing_user
|
||||
Invitation.create_invitee(opts)
|
||||
flash[:notice] = "invitation sent to #{params[:identifier]}"
|
||||
redirect_to '/admins/user_search'
|
||||
redirect_to user_search_path
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -60,7 +60,41 @@ describe AdminsController do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#add_invites' do
|
||||
context 'admin not signed in' do
|
||||
it 'is behind redirect_unless_admin' do
|
||||
get :add_invites
|
||||
response.should redirect_to root_url
|
||||
end
|
||||
end
|
||||
|
||||
context 'admin signed in' do
|
||||
before do
|
||||
AppConfig[:admins] = [@user.username]
|
||||
end
|
||||
|
||||
it "redirects to :back with user id" do
|
||||
get :add_invites, :user_id => @user.id
|
||||
response.should redirect_to user_search_path(:user => { :id => @user.id })
|
||||
end
|
||||
|
||||
it "increases user's invite by 10" do
|
||||
expect {
|
||||
get :add_invites, :user_id => @user.id
|
||||
}.to change { @user.reload.invites }.by(10)
|
||||
flash.notice.should include('Great Job')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#admin_inviter' do
|
||||
context 'admin not signed in' do
|
||||
it 'is behind redirect_unless_admin' do
|
||||
get :admin_inviter
|
||||
response.should redirect_to root_url
|
||||
end
|
||||
end
|
||||
|
||||
context 'admin signed in' do
|
||||
before do
|
||||
AppConfig[:admins] = [@user.username]
|
||||
|
|
@ -69,7 +103,8 @@ describe AdminsController do
|
|||
it 'invites a new user' do
|
||||
Invitation.should_receive(:create_invitee).with(:service => 'email', :identifier => 'bob@moms.com')
|
||||
get :admin_inviter, :identifier => 'bob@moms.com'
|
||||
response.should be_redirect
|
||||
response.should redirect_to user_search_path
|
||||
flash.notice.should include("invitation sent")
|
||||
end
|
||||
|
||||
it 'passes an existing user to create_invitee' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue