Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
9e3094b2
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9e3094b2
编写于
6月 17, 2014
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove UsersGroup observer
上级
b3a90aba
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
45 addition
and
42 deletion
+45
-42
app/models/users_group.rb
app/models/users_group.rb
+17
-0
app/observers/users_group_observer.rb
app/observers/users_group_observer.rb
+0
-9
config/application.rb
config/application.rb
+0
-1
spec/models/users_group_spec.rb
spec/models/users_group_spec.rb
+28
-0
spec/observers/users_group_observer_spec.rb
spec/observers/users_group_observer_spec.rb
+0
-32
未找到文件。
app/models/users_group.rb
浏览文件 @
9e3094b2
...
...
@@ -33,6 +33,9 @@ class UsersGroup < ActiveRecord::Base
scope
:with_group
,
->
(
group
)
{
where
(
group_id:
group
.
id
)
}
scope
:with_user
,
->
(
user
)
{
where
(
user_id:
user
.
id
)
}
after_create
:notify_create
after_update
:notify_update
validates
:group_access
,
inclusion:
{
in:
UsersGroup
.
group_access_roles
.
values
},
presence:
true
validates
:user_id
,
presence:
true
validates
:group_id
,
presence:
true
...
...
@@ -43,4 +46,18 @@ class UsersGroup < ActiveRecord::Base
def
access_field
group_access
end
def
notify_create
notification_service
.
new_group_member
(
self
)
end
def
notify_update
if
group_access_changed?
notification_service
.
update_group_member
(
self
)
end
end
def
notification_service
NotificationService
.
new
end
end
app/observers/users_group_observer.rb
已删除
100644 → 0
浏览文件 @
b3a90aba
class
UsersGroupObserver
<
BaseObserver
def
after_create
(
membership
)
notification
.
new_group_member
(
membership
)
end
def
after_update
(
membership
)
notification
.
update_group_member
(
membership
)
if
membership
.
group_access_changed?
end
end
config/application.rb
浏览文件 @
9e3094b2
...
...
@@ -23,7 +23,6 @@ module Gitlab
:project_observer
,
:system_hook_observer
,
:user_observer
,
:users_group_observer
,
:users_project_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
...
...
spec/models/users_group_spec.rb
浏览文件 @
9e3094b2
...
...
@@ -37,4 +37,32 @@ describe UsersGroup do
it
{
should
respond_to
(
:user_name
)
}
it
{
should
respond_to
(
:user_email
)
}
end
context
'notification'
do
describe
"#after_create"
do
it
"should send email to user"
do
membership
=
build
(
:users_group
)
membership
.
stub
(
notification_service:
double
(
'NotificationService'
).
as_null_object
)
membership
.
should_receive
(
:notification_service
)
membership
.
save
end
end
describe
"#after_update"
do
before
do
@membership
=
create
:users_group
@membership
.
stub
(
notification_service:
double
(
'NotificationService'
).
as_null_object
)
end
it
"should send email to user"
do
@membership
.
should_receive
(
:notification_service
)
@membership
.
update_attribute
(
:group_access
,
UsersGroup
::
MASTER
)
end
it
"does not send an email when the access level has not changed"
do
@membership
.
should_not_receive
(
:notification_service
)
@membership
.
update_attribute
(
:group_access
,
UsersGroup
::
OWNER
)
end
end
end
end
spec/observers/users_group_observer_spec.rb
已删除
100644 → 0
浏览文件 @
b3a90aba
require
'spec_helper'
describe
UsersGroupObserver
do
before
(
:each
)
{
enable_observers
}
after
(
:each
)
{
disable_observers
}
subject
{
UsersGroupObserver
.
instance
}
before
{
subject
.
stub
(
notification:
double
(
'NotificationService'
).
as_null_object
)
}
describe
"#after_create"
do
it
"should send email to user"
do
subject
.
should_receive
(
:notification
)
create
(
:users_group
)
end
end
describe
"#after_update"
do
before
do
@membership
=
create
:users_group
end
it
"should send email to user"
do
subject
.
should_receive
(
:notification
)
@membership
.
update_attribute
(
:group_access
,
UsersGroup
::
MASTER
)
end
it
"does not send an email when the access level has not changed"
do
subject
.
should_not_receive
(
:notification
)
@membership
.
update_attribute
(
:group_access
,
UsersGroup
::
OWNER
)
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录