Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
88964132
Commit
88964132
authored
Jun 20, 2012
by
Robb Kidd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract observation of User to a UserObserver
parent
97ca4f5d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
10 deletions
+37
-10
app/models/mailer_observer.rb
app/models/mailer_observer.rb
+1
-6
app/models/user_observer.rb
app/models/user_observer.rb
+5
-0
config/application.rb
config/application.rb
+1
-1
spec/models/user_observer_spec.rb
spec/models/user_observer_spec.rb
+26
-0
spec/requests/admin/admin_users_spec.rb
spec/requests/admin/admin_users_spec.rb
+4
-3
No files found.
app/models/mailer_observer.rb
View file @
88964132
class
MailerObserver
<
ActiveRecord
::
Observer
observe
:issue
,
:
user
,
:
note
,
:merge_request
observe
:issue
,
:note
,
:merge_request
cattr_accessor
:current_user
def
after_create
(
model
)
new_user
(
model
)
if
model
.
kind_of?
(
User
)
new_note
(
model
)
if
model
.
kind_of?
(
Note
)
new_merge_request
(
model
)
if
model
.
kind_of?
(
MergeRequest
)
end
...
...
@@ -14,10 +13,6 @@ class MailerObserver < ActiveRecord::Observer
protected
def
new_user
(
user
)
Notify
.
new_user_email
(
user
.
id
,
user
.
password
).
deliver
end
def
new_note
(
note
)
if
note
.
notify
# Notify whole team except author of note
...
...
app/models/user_observer.rb
0 → 100644
View file @
88964132
class
UserObserver
<
ActiveRecord
::
Observer
def
after_create
(
user
)
Notify
.
new_user_email
(
user
.
id
,
user
.
password
).
deliver
end
end
config/application.rb
View file @
88964132
...
...
@@ -23,7 +23,7 @@ module Gitlab
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
config
.
active_record
.
observers
=
:mailer_observer
,
:activity_observer
,
:project_observer
,
:key_observer
,
:issue_observer
config
.
active_record
.
observers
=
:mailer_observer
,
:activity_observer
,
:project_observer
,
:key_observer
,
:issue_observer
,
:user_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
...
...
spec/models/user_observer_spec.rb
0 → 100644
View file @
88964132
require
'spec_helper'
describe
UserObserver
do
subject
{
UserObserver
.
instance
}
it
'calls #after_create when new users are created'
do
new_user
=
Factory
.
new
(
:user
)
subject
.
should_receive
(
:after_create
).
with
(
new_user
)
User
.
observers
.
enable
:user_observer
do
new_user
.
save
end
end
context
'when a new user is created'
do
let
(
:user
)
{
double
(
:user
,
id:
42
,
password:
'P@ssword!'
)
}
let
(
:notification
)
{
double
:notification
}
it
'sends an email'
do
notification
.
should_receive
(
:deliver
)
Notify
.
should_receive
(
:new_user_email
).
with
(
user
.
id
,
user
.
password
).
and_return
(
notification
)
subject
.
after_create
(
user
)
end
end
end
spec/requests/admin/admin_users_spec.rb
View file @
88964132
...
...
@@ -40,14 +40,15 @@ describe "Admin::Users" do
end
it
"should call send mail"
do
User
.
observers
.
enable
:mailer_observer
do
Notify
.
should_receive
(
:new_user_email
).
and_return
(
stub
(
:deliver
=>
true
))
User
.
observers
.
enable
:user_observer
do
click_button
"Save"
end
end
it
"should send valid email to user with email & password"
do
User
.
observers
.
enable
:
mail
er_observer
do
User
.
observers
.
enable
:
us
er_observer
do
with_resque
do
click_button
"Save"
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment