Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
OHR Support
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
97
Issues
97
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
OHR Support
Commits
46f66add
Commit
46f66add
authored
May 27, 2011
by
Eric Davis
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'schmidt/f/416-redo-watcher-links-unstable' into unstable
parents
ce8bb652
3893ef9f
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
152 additions
and
47 deletions
+152
-47
watchers_controller.rb
app/controllers/watchers_controller.rb
+11
-12
watchers_helper.rb
app/helpers/watchers_helper.rb
+27
-18
show.rhtml
app/views/boards/show.rhtml
+1
-1
_action_menu.rhtml
app/views/issues/_action_menu.rhtml
+1
-2
show.rhtml
app/views/issues/show.rhtml
+1
-1
show.rhtml
app/views/messages/show.rhtml
+1
-1
show.rhtml
app/views/news/show.rhtml
+1
-1
replace_selectors.rjs
app/views/watchers/replace_selectors.rjs
+22
-0
date_index.html.erb
app/views/wiki/date_index.html.erb
+1
-1
index.html.erb
app/views/wiki/index.html.erb
+1
-1
show.rhtml
app/views/wiki/show.rhtml
+1
-1
watchers_controller_test.rb
test/functional/watchers_controller_test.rb
+35
-8
watchers_helpers_test.rb
test/unit/helpers/watchers_helpers_test.rb
+49
-0
No files found.
app/controllers/watchers_controller.rb
View file @
46f66add
...
@@ -76,23 +76,22 @@ private
...
@@ -76,23 +76,22 @@ private
def
set_watcher
(
user
,
watching
)
def
set_watcher
(
user
,
watching
)
@watched
.
set_watcher
(
user
,
watching
)
@watched
.
set_watcher
(
user
,
watching
)
respond_to
do
|
format
|
format
.
html
{
redirect_to
:back
}
format
.
js
do
if
params
[
:replace
].
present?
if
params
[
:replace
].
present?
if
params
[
:replace
].
is_a?
Array
if
params
[
:replace
].
is_a?
Array
replace_id
s
=
params
[
:replace
]
@replace_selector
s
=
params
[
:replace
]
else
else
replace_ids
=
[
params
[
:replace
]]
@replace_selectors
=
params
[
:replace
].
split
(
','
).
map
(
&
:strip
)
end
end
else
else
replace_ids
=
[
'watcher'
]
@replace_selectors
=
[
'#watcher'
]
end
respond_to
do
|
format
|
format
.
html
{
redirect_to
:back
}
format
.
js
do
render
(
:update
)
do
|
page
|
replace_ids
.
each
do
|
replace_id
|
page
.
replace_html
replace_id
,
watcher_link
(
@watched
,
user
,
:replace
=>
replace_ids
)
end
end
end
@user
=
user
render
:action
=>
'replace_selectors'
end
end
end
end
rescue
::
ActionController
::
RedirectBackError
rescue
::
ActionController
::
RedirectBackError
...
...
app/helpers/watchers_helper.rb
View file @
46f66add
...
@@ -17,32 +17,41 @@
...
@@ -17,32 +17,41 @@
module
WatchersHelper
module
WatchersHelper
# Valid options
# Deprecated method. Use watcher_link instead
# * :id - the element id
#
# * :replace - a string or array of element ids that will be
# This method will be removed in ChiliProject 3.0 or later
# replaced
def
watcher_tag
(
object
,
user
,
options
=
{
:replace
=>
'watcher'
})
def
watcher_tag
(
object
,
user
,
options
=
{
:replace
=>
'watcher'
})
id
=
options
[
:id
]
ActiveSupport
::
Deprecation
.
warn
"The WatchersHelper#watcher_tag is deprecated and will be removed in ChiliProject 3.0. Please use WatchersHelper#watcher_link instead. Please also note the differences between the APIs."
,
caller
id
||=
options
[
:replace
]
if
options
[
:replace
].
is_a?
String
content_tag
(
"span"
,
watcher_link
(
object
,
user
,
options
),
:id
=>
id
)
options
[
:id
]
||=
options
[
:replace
]
if
options
[
:replace
].
is_a?
String
options
[
:replace
]
=
Array
(
options
[
:replace
]).
map
{
|
id
|
"#
#{
id
}
"
}
watcher_link
(
object
,
user
,
options
)
end
end
# Valid options
# Create a link to watch/unwatch object
# * :replace - a string or array of element ids that will be
#
# replaced
# * :replace - a string or array of strings with css selectors that will be updated, whenever the watcher status is changed
def
watcher_link
(
object
,
user
,
options
=
{
:replace
=>
'watcher'
})
def
watcher_link
(
object
,
user
,
options
=
{
:replace
=>
'.watcher_link'
,
:class
=>
'watcher_link'
})
options
=
options
.
with_indifferent_access
raise
ArgumentError
,
'Missing :replace option in options hash'
if
options
[
'replace'
].
blank?
return
''
unless
user
&&
user
.
logged?
&&
object
.
respond_to?
(
'watched_by?'
)
return
''
unless
user
&&
user
.
logged?
&&
object
.
respond_to?
(
'watched_by?'
)
watched
=
object
.
watched_by?
(
user
)
watched
=
object
.
watched_by?
(
user
)
url
=
{
:controller
=>
'watchers'
,
url
=
{
:controller
=>
'watchers'
,
:action
=>
(
watched
?
'unwatch'
:
'watch'
),
:action
=>
(
watched
?
'unwatch'
:
'watch'
),
:object_type
=>
object
.
class
.
to_s
.
underscore
,
:object_type
=>
object
.
class
.
to_s
.
underscore
,
:object_id
=>
object
.
id
,
:object_id
=>
object
.
id
,
:replace
=>
options
[
:replace
]}
:replace
=>
options
.
delete
(
'replace'
)}
link_to_remote
((
watched
?
l
(:
button_unwatch
)
:
l
(
:button_watch
)),
{
:url
=>
url
},
url_options
=
{
:url
=>
url
}
:href
=>
url_for
(
url
),
:class
=>
(
watched
?
'icon icon-fav'
:
'icon icon-fav-off'
))
html_options
=
options
.
merge
(
:href
=>
url_for
(
url
))
html_options
[
:class
]
=
html_options
[
:class
].
to_s
+
(
watched
?
' icon icon-fav'
:
' icon icon-fav-off'
)
link_to_remote
((
watched
?
l
(:
button_unwatch
)
:
l
(
:button_watch
)),
url_options
,
html_options
)
end
end
# Returns a comma separated list of users watching the given object
# Returns a comma separated list of users watching the given object
...
...
app/views/boards/show.rhtml
View file @
46f66add
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
{
:controller
=>
'messages'
,
:action
=>
'new'
,
:board_id
=>
@board
},
{
:controller
=>
'messages'
,
:action
=>
'new'
,
:board_id
=>
@board
},
:class
=>
'icon icon-add'
,
:class
=>
'icon icon-add'
,
:onclick
=>
'Element.show("add-message"); Form.Element.focus("message_subject"); return false;'
%>
:onclick
=>
'Element.show("add-message"); Form.Element.focus("message_subject"); return false;'
%>
<%=
watcher_tag
(
@board
,
User
.
current
)
%>
<%=
watcher_link
(
@board
,
User
.
current
)
%>
</div>
</div>
<div
id=
"add-message"
style=
"display:none;"
>
<div
id=
"add-message"
style=
"display:none;"
>
...
...
app/views/issues/_action_menu.rhtml
View file @
46f66add
<div
class=
"contextual"
>
<div
class=
"contextual"
>
<%=
link_to_if_authorized
(
l
(
:button_update
),
{
:controller
=>
'issues'
,
:action
=>
'edit'
,
:id
=>
@issue
},
:onclick
=>
'showAndScrollTo("update", "notes"); return false;'
,
:class
=>
'icon icon-edit'
,
:accesskey
=>
accesskey
(
:edit
))
%>
<%=
link_to_if_authorized
(
l
(
:button_update
),
{
:controller
=>
'issues'
,
:action
=>
'edit'
,
:id
=>
@issue
},
:onclick
=>
'showAndScrollTo("update", "notes"); return false;'
,
:class
=>
'icon icon-edit'
,
:accesskey
=>
accesskey
(
:edit
))
%>
<%=
link_to_if_authorized
l
(
:button_log_time
),
{
:controller
=>
'timelog'
,
:action
=>
'new'
,
:issue_id
=>
@issue
},
:class
=>
'icon icon-time-add'
%>
<%=
link_to_if_authorized
l
(
:button_log_time
),
{
:controller
=>
'timelog'
,
:action
=>
'new'
,
:issue_id
=>
@issue
},
:class
=>
'icon icon-time-add'
%>
<%
replace_watcher
||=
'watcher'
%>
<%=
watcher_link
(
@issue
,
User
.
current
,
{
:class
=>
'watcher_link'
,
:replace
=>
[
'#watchers'
,
'.watcher_link'
]})
%>
<%=
watcher_tag
(
@issue
,
User
.
current
,
{
:id
=>
replace_watcher
,
:replace
=>
[
'watcher'
,
'watcher2'
]})
%>
<%=
link_to_if_authorized
l
(
:button_duplicate
),
{
:controller
=>
'issues'
,
:action
=>
'new'
,
:project_id
=>
@project
,
:copy_from
=>
@issue
},
:class
=>
'icon icon-duplicate'
%>
<%=
link_to_if_authorized
l
(
:button_duplicate
),
{
:controller
=>
'issues'
,
:action
=>
'new'
,
:project_id
=>
@project
,
:copy_from
=>
@issue
},
:class
=>
'icon icon-duplicate'
%>
<%=
link_to_if_authorized
l
(
:button_copy
),
{
:controller
=>
'issue_moves'
,
:action
=>
'new'
,
:id
=>
@issue
,
:copy_options
=>
{
:copy
=>
't'
}},
:class
=>
'icon icon-copy'
%>
<%=
link_to_if_authorized
l
(
:button_copy
),
{
:controller
=>
'issue_moves'
,
:action
=>
'new'
,
:id
=>
@issue
,
:copy_options
=>
{
:copy
=>
't'
}},
:class
=>
'icon icon-copy'
%>
<%=
link_to_if_authorized
l
(
:button_move
),
{
:controller
=>
'issue_moves'
,
:action
=>
'new'
,
:id
=>
@issue
},
:class
=>
'icon icon-move'
%>
<%=
link_to_if_authorized
l
(
:button_move
),
{
:controller
=>
'issue_moves'
,
:action
=>
'new'
,
:id
=>
@issue
},
:class
=>
'icon icon-move'
%>
...
...
app/views/issues/show.rhtml
View file @
46f66add
...
@@ -98,7 +98,7 @@
...
@@ -98,7 +98,7 @@
<div
style=
"clear: both;"
></div>
<div
style=
"clear: both;"
></div>
<%=
render
:partial
=>
'action_menu'
,
:locals
=>
{
:replace_watcher
=>
'watcher2'
}
%>
<%=
render
:partial
=>
'action_menu'
%>
<div
style=
"clear: both;"
></div>
<div
style=
"clear: both;"
></div>
<%
if
authorize_for
(
'issues'
,
'edit'
)
%>
<%
if
authorize_for
(
'issues'
,
'edit'
)
%>
...
...
app/views/messages/show.rhtml
View file @
46f66add
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
link_to
(
h
(
@board
.
name
),
{
:controller
=>
'boards'
,
:action
=>
'show'
,
:project_id
=>
@project
,
:id
=>
@board
})
%>
link_to
(
h
(
@board
.
name
),
{
:controller
=>
'boards'
,
:action
=>
'show'
,
:project_id
=>
@project
,
:id
=>
@board
})
%>
<div
class=
"contextual"
>
<div
class=
"contextual"
>
<%=
watcher_
tag
(
@topic
,
User
.
current
)
%>
<%=
watcher_
link
(
@topic
,
User
.
current
)
%>
<%=
link_to_remote_if_authorized
(
l
(
:button_quote
),
{
:url
=>
{
:action
=>
'quote'
,
:id
=>
@topic
}
},
:class
=>
'icon icon-comment'
)
unless
@topic
.
locked?
%>
<%=
link_to_remote_if_authorized
(
l
(
:button_quote
),
{
:url
=>
{
:action
=>
'quote'
,
:id
=>
@topic
}
},
:class
=>
'icon icon-comment'
)
unless
@topic
.
locked?
%>
<%=
link_to
(
l
(
:button_edit
),
{
:action
=>
'edit'
,
:id
=>
@topic
},
:class
=>
'icon icon-edit'
)
if
@message
.
editable_by?
(
User
.
current
)
%>
<%=
link_to
(
l
(
:button_edit
),
{
:action
=>
'edit'
,
:id
=>
@topic
},
:class
=>
'icon icon-edit'
)
if
@message
.
editable_by?
(
User
.
current
)
%>
<%=
link_to
(
l
(
:button_delete
),
{
:action
=>
'destroy'
,
:id
=>
@topic
},
:method
=>
:post
,
:confirm
=>
l
(
:text_are_you_sure
),
:class
=>
'icon icon-del'
)
if
@message
.
destroyable_by?
(
User
.
current
)
%>
<%=
link_to
(
l
(
:button_delete
),
{
:action
=>
'destroy'
,
:id
=>
@topic
},
:method
=>
:post
,
:confirm
=>
l
(
:text_are_you_sure
),
:class
=>
'icon icon-del'
)
if
@message
.
destroyable_by?
(
User
.
current
)
%>
...
...
app/views/news/show.rhtml
View file @
46f66add
<div
class=
"contextual"
>
<div
class=
"contextual"
>
<%=
watcher_
tag
(
@news
,
User
.
current
)
%>
<%=
watcher_
link
(
@news
,
User
.
current
)
%>
<%=
link_to
(
l
(
:button_edit
),
<%=
link_to
(
l
(
:button_edit
),
edit_news_path
(
@news
),
edit_news_path
(
@news
),
:class
=>
'icon icon-edit'
,
:class
=>
'icon icon-edit'
,
...
...
app/views/watchers/replace_selectors.rjs
0 → 100644
View file @
46f66add
@replace_selectors.each do |selector|
next if selector.blank?
case selector
when '#watchers'
page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched}
else
page.select(selector).each do |node|
options = {:replace => @replace_selectors}
last_selector = selector.split(' ').last
if last_selector.starts_with? '.'
options[:class] = last_selector[1..-1]
elsif last_selector.starts_with? '#'
options[:id] = last_selector[1..-1]
end
node.replace watcher_link(@watched, @user, options)
end
end
end
app/views/wiki/date_index.html.erb
View file @
46f66add
<div
class=
"contextual"
>
<div
class=
"contextual"
>
<%=
watcher_tag
(
@wiki
,
User
.
current
)
%>
<%=
watcher_link
(
@wiki
,
User
.
current
)
%>
</div>
</div>
<h2>
<%=
l
(
:label_index_by_date
)
%>
</h2>
<h2>
<%=
l
(
:label_index_by_date
)
%>
</h2>
...
...
app/views/wiki/index.html.erb
View file @
46f66add
<div
class=
"contextual"
>
<div
class=
"contextual"
>
<%=
watcher_tag
(
@wiki
,
User
.
current
)
%>
<%=
watcher_link
(
@wiki
,
User
.
current
)
%>
</div>
</div>
<h2>
<%=
l
(
:label_index_by_title
)
%>
</h2>
<h2>
<%=
l
(
:label_index_by_title
)
%>
</h2>
...
...
app/views/wiki/show.rhtml
View file @
46f66add
<div
class=
"contextual"
>
<div
class=
"contextual"
>
<%
if
@editable
%>
<%
if
@editable
%>
<%=
link_to_if_authorized
(
l
(
:button_edit
),
{
:action
=>
'edit'
,
:id
=>
@page
.
title
},
:class
=>
'icon icon-edit'
,
:accesskey
=>
accesskey
(
:edit
))
if
@content
.
version
==
@page
.
content
.
version
%>
<%=
link_to_if_authorized
(
l
(
:button_edit
),
{
:action
=>
'edit'
,
:id
=>
@page
.
title
},
:class
=>
'icon icon-edit'
,
:accesskey
=>
accesskey
(
:edit
))
if
@content
.
version
==
@page
.
content
.
version
%>
<%=
watcher_
tag
(
@page
,
User
.
current
)
%>
<%=
watcher_
link
(
@page
,
User
.
current
)
%>
<%=
link_to_if_authorized
(
l
(
:button_lock
),
{
:action
=>
'protect'
,
:id
=>
@page
.
title
,
:protected
=>
1
},
:method
=>
:post
,
:class
=>
'icon icon-lock'
)
if
!
@page
.
protected?
%>
<%=
link_to_if_authorized
(
l
(
:button_lock
),
{
:action
=>
'protect'
,
:id
=>
@page
.
title
,
:protected
=>
1
},
:method
=>
:post
,
:class
=>
'icon icon-lock'
)
if
!
@page
.
protected?
%>
<%=
link_to_if_authorized
(
l
(
:button_unlock
),
{
:action
=>
'protect'
,
:id
=>
@page
.
title
,
:protected
=>
0
},
:method
=>
:post
,
:class
=>
'icon icon-unlock'
)
if
@page
.
protected?
%>
<%=
link_to_if_authorized
(
l
(
:button_unlock
),
{
:action
=>
'protect'
,
:id
=>
@page
.
title
,
:protected
=>
0
},
:method
=>
:post
,
:class
=>
'icon icon-unlock'
)
if
@page
.
protected?
%>
<%=
link_to_if_authorized
(
l
(
:button_rename
),
{
:action
=>
'rename'
,
:id
=>
@page
.
title
},
:class
=>
'icon icon-move'
)
if
@content
.
version
==
@page
.
content
.
version
%>
<%=
link_to_if_authorized
(
l
(
:button_rename
),
{
:action
=>
'rename'
,
:id
=>
@page
.
title
},
:class
=>
'icon icon-move'
)
if
@content
.
version
==
@page
.
content
.
version
%>
...
...
test/functional/watchers_controller_test.rb
View file @
46f66add
...
@@ -43,7 +43,8 @@ class WatchersControllerTest < ActionController::TestCase
...
@@ -43,7 +43,8 @@ class WatchersControllerTest < ActionController::TestCase
assert_difference
(
'Watcher.count'
)
do
assert_difference
(
'Watcher.count'
)
do
xhr
:post
,
:watch
,
:object_type
=>
'issue'
,
:object_id
=>
'1'
xhr
:post
,
:watch
,
:object_type
=>
'issue'
,
:object_id
=>
'1'
assert_response
:success
assert_response
:success
assert_select_rjs
:replace_html
,
'watcher'
assert
@response
.
body
.
include?
"$$(
\"
#watcher
\"
).each"
assert
@response
.
body
.
include?
"value.replace"
end
end
assert
Issue
.
find
(
1
).
watched_by?
(
User
.
find
(
3
))
assert
Issue
.
find
(
1
).
watched_by?
(
User
.
find
(
3
))
end
end
...
@@ -60,10 +61,22 @@ class WatchersControllerTest < ActionController::TestCase
...
@@ -60,10 +61,22 @@ class WatchersControllerTest < ActionController::TestCase
def
test_watch_with_multiple_replacements
def
test_watch_with_multiple_replacements
@request
.
session
[
:user_id
]
=
3
@request
.
session
[
:user_id
]
=
3
assert_difference
(
'Watcher.count'
)
do
assert_difference
(
'Watcher.count'
)
do
xhr
:post
,
:watch
,
:object_type
=>
'issue'
,
:object_id
=>
'1'
,
:replace
=>
[
'
watch_item_1'
,
'
watch_item_2'
]
xhr
:post
,
:watch
,
:object_type
=>
'issue'
,
:object_id
=>
'1'
,
:replace
=>
[
'
#watch_item_1'
,
'.
watch_item_2'
]
assert_response
:success
assert_response
:success
assert_select_rjs
:replace_html
,
'watch_item_1'
assert
@response
.
body
.
include?
"$$(
\"
#watch_item_1
\"
).each"
assert_select_rjs
:replace_html
,
'watch_item_2'
assert
@response
.
body
.
include?
"$$(
\"
.watch_item_2
\"
).each"
assert
@response
.
body
.
include?
"value.replace"
end
end
def
test_watch_with_watchers_special_logic
@request
.
session
[
:user_id
]
=
3
assert_difference
(
'Watcher.count'
)
do
xhr
:post
,
:watch
,
:object_type
=>
'issue'
,
:object_id
=>
'1'
,
:replace
=>
[
'#watchers'
,
'.watcher'
]
assert_response
:success
assert_select_rjs
:replace_html
,
'watchers'
assert
@response
.
body
.
include?
"$$(
\"
.watcher
\"
).each"
assert
@response
.
body
.
include?
"value.replace"
end
end
end
end
...
@@ -72,7 +85,8 @@ class WatchersControllerTest < ActionController::TestCase
...
@@ -72,7 +85,8 @@ class WatchersControllerTest < ActionController::TestCase
assert_difference
(
'Watcher.count'
,
-
1
)
do
assert_difference
(
'Watcher.count'
,
-
1
)
do
xhr
:post
,
:unwatch
,
:object_type
=>
'issue'
,
:object_id
=>
'2'
xhr
:post
,
:unwatch
,
:object_type
=>
'issue'
,
:object_id
=>
'2'
assert_response
:success
assert_response
:success
assert_select_rjs
:replace_html
,
'watcher'
assert
@response
.
body
.
include?
"$$(
\"
#watcher
\"
).each"
assert
@response
.
body
.
include?
"value.replace"
end
end
assert
!
Issue
.
find
(
1
).
watched_by?
(
User
.
find
(
3
))
assert
!
Issue
.
find
(
1
).
watched_by?
(
User
.
find
(
3
))
end
end
...
@@ -80,10 +94,23 @@ class WatchersControllerTest < ActionController::TestCase
...
@@ -80,10 +94,23 @@ class WatchersControllerTest < ActionController::TestCase
def
test_unwatch_with_multiple_replacements
def
test_unwatch_with_multiple_replacements
@request
.
session
[
:user_id
]
=
3
@request
.
session
[
:user_id
]
=
3
assert_difference
(
'Watcher.count'
,
-
1
)
do
assert_difference
(
'Watcher.count'
,
-
1
)
do
xhr
:post
,
:unwatch
,
:object_type
=>
'issue'
,
:object_id
=>
'2'
,
:replace
=>
[
'
watch_item_1'
,
'
watch_item_2'
]
xhr
:post
,
:unwatch
,
:object_type
=>
'issue'
,
:object_id
=>
'2'
,
:replace
=>
[
'
#watch_item_1'
,
'.
watch_item_2'
]
assert_response
:success
assert_response
:success
assert_select_rjs
:replace_html
,
'watch_item_1'
assert
@response
.
body
.
include?
"$$(
\"
#watch_item_1
\"
).each"
assert_select_rjs
:replace_html
,
'watch_item_2'
assert
@response
.
body
.
include?
"$$(
\"
.watch_item_2
\"
).each"
assert
@response
.
body
.
include?
"value.replace"
end
assert
!
Issue
.
find
(
1
).
watched_by?
(
User
.
find
(
3
))
end
def
test_unwatch_with_watchers_special_logic
@request
.
session
[
:user_id
]
=
3
assert_difference
(
'Watcher.count'
,
-
1
)
do
xhr
:post
,
:unwatch
,
:object_type
=>
'issue'
,
:object_id
=>
'2'
,
:replace
=>
[
'#watchers'
,
'.watcher'
]
assert_response
:success
assert_select_rjs
:replace_html
,
'watchers'
assert
@response
.
body
.
include?
"$$(
\"
.watcher
\"
).each"
assert
@response
.
body
.
include?
"value.replace"
end
end
assert
!
Issue
.
find
(
1
).
watched_by?
(
User
.
find
(
3
))
assert
!
Issue
.
find
(
1
).
watched_by?
(
User
.
find
(
3
))
end
end
...
...
test/unit/helpers/watchers_helpers_test.rb
0 → 100644
View file @
46f66add
require
File
.
expand_path
(
'../../../test_helper'
,
__FILE__
)
class
WatchersHelperTest
<
HelperTestCase
include
WatchersHelper
# tested for backwards compatibility
context
'#watcher_tag'
do
setup
do
# mocking watcher_link to make sure, that new API is properly called from
# the old one.
def
self
.
watcher_link
(
*
args
)
@watcher_link_args
=
args
nil
end
# silencing deprecation warnings while testing the deprecated behavior
def
self
.
watcher_tag
(
*
args
)
ActiveSupport
::
Deprecation
.
silence
{
super
}
end
end
context
'without options'
do
should
"call watcher_link with object, user and {:id => 'watcher', :replace => '#watcher'}"
do
watcher_tag
(
:object
,
:user
)
assert_equal
:object
,
@watcher_link_args
.
first
assert_equal
:user
,
@watcher_link_args
.
second
assert_equal
({
:id
=>
'watcher'
,
:replace
=>
[
'#watcher'
]},
@watcher_link_args
.
third
)
end
end
context
'with replace, without id option'
do
should
"set id to replace value and prefix replace with a # to make it a valid css selectors"
do
watcher_tag
(
:object
,
:user
,
:replace
=>
'abc'
)
assert_equal
:object
,
@watcher_link_args
.
first
assert_equal
:user
,
@watcher_link_args
.
second
assert_equal
({
:id
=>
'abc'
,
:replace
=>
[
'#abc'
]},
@watcher_link_args
.
third
)
end
end
context
'with all options'
do
should
"prefix all elements in replace with a # to make them valid css selectors"
do
watcher_tag
(
:object
,
:user
,
:id
=>
'abc'
,
:replace
=>
[
'abc'
,
'def'
])
assert_equal
:object
,
@watcher_link_args
.
first
assert_equal
:user
,
@watcher_link_args
.
second
assert_equal
({
:id
=>
'abc'
,
:replace
=>
[
'#abc'
,
'#def'
]},
@watcher_link_args
.
third
)
end
end
end
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