Remove duplication in test setup
This commit is contained in:
parent
2e7696630b
commit
58f96bdfb5
|
@ -836,11 +836,10 @@ describe UsersController do
|
||||||
context 'with authenticated user' do
|
context 'with authenticated user' do
|
||||||
context 'with permission to update' do
|
context 'with permission to update' do
|
||||||
it 'allows the update' do
|
it 'allows the update' do
|
||||||
user = Fabricate(:user, name: 'Billy Bob')
|
user = create_authenticated_user('Billy Bob')
|
||||||
log_in_user(user)
|
stub_guardian(user) do |guardian|
|
||||||
guardian = Guardian.new(user)
|
guardian.stubs(:ensure_can_edit!).with(user)
|
||||||
guardian.stubs(:ensure_can_edit!)
|
end
|
||||||
Guardian.stubs(new: guardian).with(user)
|
|
||||||
|
|
||||||
put :update, username: user.username, name: 'Jim Tom'
|
put :update, username: user.username, name: 'Jim Tom'
|
||||||
|
|
||||||
|
@ -851,11 +850,11 @@ describe UsersController do
|
||||||
|
|
||||||
context 'without permission to update' do
|
context 'without permission to update' do
|
||||||
it 'does not allow the update' do
|
it 'does not allow the update' do
|
||||||
user = Fabricate(:user, name: 'Billy Bob')
|
user = create_authenticated_user('Billy Bob')
|
||||||
log_in_user(user)
|
stub_guardian(user) do |guardian|
|
||||||
guardian = Guardian.new(user)
|
guardian.stubs(:ensure_can_edit!).
|
||||||
guardian.stubs(:ensure_can_edit!).raises(Discourse::InvalidAccess.new)
|
with(user).raises(Discourse::InvalidAccess.new)
|
||||||
Guardian.stubs(new: guardian).with(user)
|
end
|
||||||
|
|
||||||
put :update, username: user.username, name: 'Jim Tom'
|
put :update, username: user.username, name: 'Jim Tom'
|
||||||
|
|
||||||
|
@ -1105,4 +1104,16 @@ describe UsersController do
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def create_authenticated_user(name)
|
||||||
|
log_in_user(Fabricate(:user, name: name))
|
||||||
|
end
|
||||||
|
|
||||||
|
def stub_guardian(user)
|
||||||
|
guardian = Guardian.new(user)
|
||||||
|
yield(guardian)
|
||||||
|
Guardian.stubs(new: guardian).with(user)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue