commenteux 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +19 -1
  3. data/app/assets/javascripts/commenteux/application.js.coffee +18 -16
  4. data/app/controllers/commenteux/notes_controller.rb +66 -18
  5. data/app/helpers/commenteux/notes_helper.rb +5 -3
  6. data/app/helpers/commenteux/users_helper.rb +11 -0
  7. data/app/views/commenteux/notes/index.html.erb +13 -4
  8. data/app/views/commenteux/notes/new.html.erb +11 -2
  9. data/config/cucumber.yml +2 -0
  10. data/lib/commenteux/version.rb +1 -1
  11. data/spec/controllers/commenteux/notes_controller_spec.rb +135 -25
  12. data/spec/dummy/app/models/dummy_model.rb +1 -1
  13. data/spec/dummy/app/models/dummy_no_role_model.rb +3 -0
  14. data/spec/dummy/config/locales/en.yml +2 -0
  15. data/spec/dummy/db/migrate/20150612102101_create_dummy_no_role_models.rb +10 -0
  16. data/spec/dummy/db/schema.rb +7 -1
  17. data/spec/dummy/log/development.log +14 -1142
  18. data/spec/dummy/log/test.log +2334 -47
  19. data/spec/dummy/tmp/cache/assets/test/sprockets/{af00b28760a09c0a6fd6fe584cbb839d → 0ea5157d06860900da5e91e9e9e5c5ae} +0 -0
  20. data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  21. data/spec/dummy/tmp/cache/assets/test/sprockets/1961e9a889917e26f9b92f7e3678b9d8 +0 -0
  22. data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  23. data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  24. data/spec/dummy/tmp/cache/assets/test/sprockets/{6e1da15bffb0094059fbe56ddb206c07 → 4c0092a53cfc0cf92b75c45eea8e0c9c} +0 -0
  25. data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  26. data/spec/dummy/tmp/cache/assets/test/sprockets/{1957ff8c0d834428d5beca5bf51669b2 → d47c40f60d1e15e0c67f7f18a27a34e2} +0 -0
  27. data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  28. data/spec/dummy/tmp/cache/assets/test/sprockets/db2a42fb4a2ea58dddbe086ea7cbd8c3 +0 -0
  29. data/spec/dummy/tmp/cache/assets/test/sprockets/{9fbd3d6762f09cbefd55f6775cf9bebe → e8a6cef31bf116819ca4efd46d92cf23} +0 -0
  30. data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  31. data/spec/dummy/tmp/capybara/capybara-201506160848572837541916.html +50 -0
  32. data/spec/dummy/tmp/capybara/capybara-201506160849002657266256.html +1 -0
  33. data/spec/dummy/tmp/capybara/capybara-201506160849005456490075.html +1 -0
  34. data/spec/dummy/tmp/capybara/capybara-201506160849006051257852.html +50 -0
  35. data/spec/dummy/tmp/capybara/capybara-201506160849009617311507.html +1 -0
  36. data/spec/dummy/tmp/capybara/capybara-201506160851032943006672.html +49 -0
  37. data/spec/dummy/tmp/capybara/capybara-201506160851033032648231.html +0 -0
  38. data/spec/dummy/tmp/capybara/capybara-201506160851033315623084.html +0 -0
  39. data/spec/dummy/tmp/capybara/capybara-201506160851038790165986.html +0 -0
  40. data/spec/dummy/tmp/capybara/capybara-201506160855125750188512.html +49 -0
  41. data/spec/dummy/tmp/capybara/capybara-20150616085514290901703.html +46 -0
  42. data/spec/dummy/tmp/capybara/capybara-201506160902299004854094.html +50 -0
  43. data/spec/dummy/tmp/capybara/capybara-201506160903467053840829.html +50 -0
  44. data/spec/dummy/tmp/capybara/capybara-201506160908177506055011.html +0 -0
  45. data/spec/dummy/tmp/capybara/capybara-201506160908405071238114.html +1 -0
  46. data/spec/dummy/tmp/capybara/capybara-201506160912457681959819.html +50 -0
  47. data/spec/dummy/tmp/capybara/capybara-201506160914361347465054.html +50 -0
  48. data/spec/dummy/tmp/capybara/capybara-201506160919206069916380.html +50 -0
  49. data/spec/dummy/tmp/capybara/capybara-201506160919495766672705.html +50 -0
  50. data/spec/dummy/tmp/capybara/capybara-201506160921512325089167.html +50 -0
  51. data/spec/dummy/tmp/capybara/capybara-201506160925246853939548.html +50 -0
  52. data/spec/dummy/tmp/capybara/capybara-20150616092631910193376.html +0 -0
  53. data/spec/dummy/tmp/capybara/capybara-201506160927256081238729.html +50 -0
  54. data/spec/dummy/tmp/capybara/capybara-201506160929587747316609.html +50 -0
  55. data/spec/dummy/tmp/capybara/capybara-201506160932376393920368.html +50 -0
  56. data/spec/dummy/tmp/capybara/capybara-201506160949097224889578.html +1 -0
  57. data/spec/dummy/tmp/capybara/capybara-201506161015165425533754.html +0 -0
  58. data/spec/dummy/tmp/capybara/capybara-201506161017005963312932.html +50 -0
  59. data/spec/dummy/tmp/capybara/capybara-201506161018087481300351.html +50 -0
  60. data/spec/dummy/tmp/capybara/capybara-201506161018585177596998.html +50 -0
  61. data/spec/dummy/tmp/capybara/capybara-201506161021234628016602.html +0 -0
  62. data/spec/dummy/tmp/capybara/capybara-201506161021316159221359.html +1 -0
  63. data/spec/dummy/tmp/capybara/capybara-201506161022216700801596.html +50 -0
  64. data/spec/dummy/tmp/capybara/capybara-201506161028066297282377.html +1 -0
  65. data/spec/dummy/tmp/capybara/capybara-201506161028161304521095.html +50 -0
  66. data/spec/dummy/tmp/capybara/capybara-201506161029222052955082.html +50 -0
  67. data/spec/dummy/tmp/capybara/capybara-201506161030551952925736.html +50 -0
  68. data/spec/dummy/tmp/capybara/capybara-201506170925205207947945.html +0 -0
  69. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-08-48-57.908.html +50 -0
  70. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-08-48-57.908.png +0 -0
  71. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-08-49-00.472.html +50 -0
  72. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-08-49-00.472.png +0 -0
  73. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-08-51-03.616.html +49 -0
  74. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-08-51-03.616.png +0 -0
  75. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-08-55-12.417.html +49 -0
  76. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-08-55-12.417.png +0 -0
  77. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-08-55-14.688.html +46 -0
  78. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-08-55-14.688.png +0 -0
  79. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-02-29.270.html +50 -0
  80. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-02-29.270.png +0 -0
  81. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-03-46.063.html +50 -0
  82. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-03-46.063.png +0 -0
  83. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-12-46.560.html +50 -0
  84. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-12-46.560.png +0 -0
  85. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-14-36.456.html +50 -0
  86. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-14-36.456.png +0 -0
  87. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-19-20.502.html +50 -0
  88. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-19-20.502.png +0 -0
  89. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-19-49.861.html +50 -0
  90. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-19-49.861.png +0 -0
  91. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-21-51.126.html +50 -0
  92. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-21-51.126.png +0 -0
  93. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-25-24.066.html +50 -0
  94. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-25-24.066.png +0 -0
  95. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-27-25.369.html +50 -0
  96. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-27-25.369.png +0 -0
  97. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-29-58.010.html +50 -0
  98. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-29-58.010.png +0 -0
  99. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-32-37.472.html +50 -0
  100. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-09-32-37.472.png +0 -0
  101. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-10-17-00.415.html +50 -0
  102. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-10-17-00.415.png +0 -0
  103. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-10-18-08.307.html +50 -0
  104. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-10-18-08.307.png +0 -0
  105. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-10-18-58.249.html +50 -0
  106. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-10-18-58.249.png +0 -0
  107. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-10-22-21.961.html +50 -0
  108. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-10-22-21.961.png +0 -0
  109. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-10-28-16.319.html +50 -0
  110. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-10-28-16.319.png +0 -0
  111. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-10-29-22.339.html +50 -0
  112. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-10-29-22.339.png +0 -0
  113. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-10-30-55.591.html +50 -0
  114. data/spec/dummy/tmp/capybara/screenshot_2015-06-16-10-30-55.591.png +0 -0
  115. data/spec/fabricators/comments_frabricator.rb +2 -0
  116. data/spec/fabricators/dummy_no_role_models_fabricator.rb +3 -0
  117. data/spec/helpers/commenteux/notes_helper_spec.rb +13 -5
  118. data/spec/helpers/commenteux/users_helper_spec.rb +14 -0
  119. metadata +189 -42
  120. data/spec/dummy/tmp/cache/assets/development/sprockets/078e8a1b7bb61498dbae0070239e8f4c +0 -0
  121. data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  122. data/spec/dummy/tmp/cache/assets/development/sprockets/1957ff8c0d834428d5beca5bf51669b2 +0 -0
  123. data/spec/dummy/tmp/cache/assets/development/sprockets/1961e9a889917e26f9b92f7e3678b9d8 +0 -0
  124. data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  125. data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  126. data/spec/dummy/tmp/cache/assets/development/sprockets/6e1da15bffb0094059fbe56ddb206c07 +0 -0
  127. data/spec/dummy/tmp/cache/assets/development/sprockets/9fbd3d6762f09cbefd55f6775cf9bebe +0 -0
  128. data/spec/dummy/tmp/cache/assets/development/sprockets/af00b28760a09c0a6fd6fe584cbb839d +0 -0
  129. data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  130. data/spec/dummy/tmp/cache/assets/development/sprockets/d72f8bdb1dcb7ea80d1869cb2c6ebbd3 +0 -0
  131. data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  132. data/spec/dummy/tmp/cache/assets/development/sprockets/db2a42fb4a2ea58dddbe086ea7cbd8c3 +0 -0
  133. data/spec/dummy/tmp/cache/assets/development/sprockets/ec516d6bcfdc219883f1ddb03b5a635b +0 -0
  134. data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  135. data/spec/dummy/tmp/cache/assets/test/sprockets/d72f8bdb1dcb7ea80d1869cb2c6ebbd3 +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 672bf6210823405d610640f2dc6eccb8f553852c
4
- data.tar.gz: 32ce16e77690438a15feaf95b9b75ffb099821cf
3
+ metadata.gz: f1e671df55b878d7fbe5a58b5f44de2a38142503
4
+ data.tar.gz: 030a6567a0510f321234ab9a424f58244eea358c
5
5
  SHA512:
6
- metadata.gz: e568cdf055aad06b329395df460d416b05318f2210299a0e12c02bc31c0692fb8da1fa7ae02afd7a69587fd1f4c30d17c78dd06c9d8dc445608da62db774ed1c
7
- data.tar.gz: 89380d5ac96129f8131bf35ce917c62312924e25be0e364e7e810a7e5fa8c5d60fe00d438acfcfc1bd7d2fe00f3f5f999bcb784ec77b35fed5e98f1bdd409219
6
+ metadata.gz: e5ef9c7633f91ad572074481bb8f9e0f28a10cca5e82eed9776ece971bf5c2f410d1727c2cb2395e389f05346d5ee196b9e619e9c20f0ed9476992bf73bc5da6
7
+ data.tar.gz: 8917b3a7be7a7c277c30193a870fcc9e81aa825a3f8fe179e9764debe52a2977ad2ec73c5330f5790b522e446830561d9e2141e4ba3ec47d725492d83ad8f887
data/README.rdoc CHANGED
@@ -33,6 +33,13 @@ The routes that will be available are :
33
33
  where :resource is the name of your model (you can use namespace)
34
34
 
35
35
 
36
+ ==== Model
37
+ Add acts_as_commentable in your model who will have comments
38
+
39
+ acts_as_commentable :private, :public
40
+
41
+ :private, :public are a example if specific role needed.
42
+
36
43
  ====Include the needed javascript file in your application.js or application.js.coffee
37
44
 
38
45
  ==== Javascript
@@ -43,9 +50,11 @@ where :resource is the name of your model (you can use namespace)
43
50
  Call url of commenteux screens, for exemple, like that:
44
51
 
45
52
  <%= link_to "<i class='icon-file-text text-blue'></i> Notes".html_safe,
46
- "/commenteux/client::contract/#{@contract.id}?parent_div=ajax_target",
53
+ "/commenteux/client::contract/#{@contract.id}?parent_div=ajax_target&roles=public,private",
47
54
  :id => "notes_tab", :data => {:remote => true} %>
48
55
 
56
+ where roles is obligated when specific roles are declared in the model.
57
+
49
58
  With a binding like that in your application.js
50
59
 
51
60
  $(document).delegate '#notes_tab', 'ajax:success', (e, data, status, xhr) ->
@@ -53,6 +62,13 @@ With a binding like that in your application.js
53
62
  $('#notes_tab_header').addClass('active')
54
63
  $('#ajax_target').html(xhr.responseText)
55
64
 
65
+ ==== Rails Internationalization (en.yml)
66
+ If specific roles of acts_as_commentable are declared in model, declare their labels under en: like that:
67
+
68
+ en:
69
+ public: "Administrator"
70
+ private: "Delivery man"
71
+
56
72
 
57
73
  == Credits
58
74
 
@@ -64,6 +80,8 @@ With a binding like that in your application.js
64
80
 
65
81
  {Rémi Gagnon}[http://github.com/rgagnon]
66
82
 
83
+ {Nicolas Demers}[http://github.com/nickdemers]
84
+
67
85
  == More
68
86
 
69
87
  http://www.groupefungo.ca
@@ -1,13 +1,12 @@
1
-
2
1
  $ () ->
3
-
4
2
  $(document).delegate '#new_notes_link', 'click', (e) ->
5
3
  #console.log('new_notes_link click')
6
- event.stopPropagation()
7
- event.preventDefault()
8
- parent= $(@).data('parent')
9
- resource = $(@).data('resource')
4
+ e.stopPropagation()
5
+ e.preventDefault()
6
+ parent = $(@).data('parent')
7
+ resource = $(@).data('resource')
10
8
  id = $(@).data('id')
9
+ roles = $(@).data('roles')
11
10
  #console.log('parent_div = ' + parent)
12
11
  #console.log('resource = ' + resource)
13
12
  #console.log('resource_id = ' + id)
@@ -17,12 +16,13 @@ $ () ->
17
16
  dataType: "html"
18
17
  data:
19
18
  "parent_div": parent
19
+ "roles": roles
20
20
  success: (returnData) ->
21
21
  #console.log('success')
22
22
  #console.log("#" + parent)
23
23
  #console.log(returnData)
24
- if parent
25
- $("#" + parent ).html(returnData)
24
+ if parent and parent != 'null'
25
+ $("#" + parent).html(returnData)
26
26
  else
27
27
  #console.log('no parent')
28
28
  $('body').html(returnData)
@@ -33,22 +33,23 @@ $ () ->
33
33
  @
34
34
 
35
35
  $(document).delegate '#new_comments', 'ajax:success', (e, data, status, xhr) ->
36
- event.stopPropagation()
37
- event.preventDefault()
36
+ e.stopPropagation()
37
+ e.preventDefault()
38
38
  #console.log('new_comments ajax success')
39
39
  parent = $('#new_comments').attr('data-parent')
40
- if parent
40
+ if parent and parent != 'null'
41
41
  $('#' + parent).html(xhr.responseText)
42
42
  else
43
43
  $('body').html(xhr.responseText)
44
44
 
45
45
  $(document).delegate '#new_notes_cancelled', 'click', (e) ->
46
46
  #console.log('new_notes_cancelled click')
47
- event.stopPropagation()
48
- event.preventDefault()
49
- parent= $(@).data('parent')
50
- resource = $(@).data('resource')
47
+ e.stopPropagation()
48
+ e.preventDefault()
49
+ parent = $(@).data('parent')
50
+ resource = $(@).data('resource')
51
51
  id = $(@).data('id')
52
+ roles = $(@).data('roles')
52
53
  #console.log('parent_div = ' + parent)
53
54
  #console.log('resource = ' + resource)
54
55
  #console.log('resource_id = ' + id)
@@ -58,12 +59,13 @@ $ () ->
58
59
  dataType: "html"
59
60
  data:
60
61
  "parent_div": parent
62
+ "roles": roles
61
63
  success: (returnData) ->
62
64
  #console.log('success')
63
65
  #console.log("#" + parent)
64
66
  #console.log(returnData)
65
67
  if parent
66
- $("#" + parent ).html(returnData)
68
+ $("#" + parent).html(returnData)
67
69
  else
68
70
  #console.log('no parent')
69
71
  $('body').html(returnData)
@@ -2,16 +2,30 @@ require_dependency "commenteux/application_controller"
2
2
 
3
3
  module Commenteux
4
4
  class NotesController < ApplicationController
5
+ helper UsersHelper
6
+
7
+ def index
8
+ resource = fetch_resource
9
+ @roles = params[:roles]
10
+ list_roles = manage_roles_parameter(params[:roles])
11
+ @comments = get_comments(resource, list_roles)
12
+ @parent_div = params[:parent_div]
13
+
14
+ if request.xhr?
15
+ render :layout => false
16
+ end
5
17
 
6
- def comments_params
7
- comments_permit_fields = [:title, :comment, :user_id]
8
- params.require(:comments).permit(
9
- comments_permit_fields)
10
18
  end
11
19
 
12
- def index
20
+ def new
13
21
  resource = fetch_resource
14
- @comments = resource.comments.all
22
+ @roles = params[:roles]
23
+ @list_roles = manage_roles_parameter(params[:roles])
24
+ role = nil
25
+ if @list_roles and @list_roles.length > 0
26
+ role = @list_roles[0][0]
27
+ end
28
+ @comments = get_comment_model_method(resource, role).new
15
29
  @parent_div = params[:parent_div]
16
30
 
17
31
  if request.xhr?
@@ -20,6 +34,25 @@ module Commenteux
20
34
 
21
35
  end
22
36
 
37
+ def create
38
+ resource = fetch_resource
39
+ comments_params
40
+ get_comment_model_method(resource, params[:comments][:role]).create(comments_params)
41
+ @parent_div = params[:parent_div]
42
+ roles = ''
43
+ if params[:roles]
44
+ roles = '&roles=' + params[:roles]
45
+ end
46
+ redirect_to "/commenteux/#{@resource.downcase}/#{@resource_id}?parent_div=" + @parent_div + roles
47
+ end
48
+
49
+ protected
50
+ def comments_params
51
+ comments_permit_fields = [:title, :comment, :user_id, :role, :roles]
52
+ params.require(:comments).permit(
53
+ comments_permit_fields)
54
+ end
55
+
23
56
  def fetch_resource
24
57
  @resource = params[:resource]
25
58
  @class_name = classify_namespace(params[:resource])
@@ -41,22 +74,37 @@ module Commenteux
41
74
  const
42
75
  end
43
76
 
44
- def new
45
- resource = fetch_resource
46
- @comments = resource.comments.new
47
- @parent_div = params[:parent_div]
48
-
49
- if request.xhr?
50
- render :layout => false
77
+ def get_comments(resource, roles)
78
+ comments = []
79
+ if roles and roles.length > 0
80
+ roles.each do |role|
81
+ comments += get_comment_model_method(resource, role[0]).all
82
+ end
83
+ else
84
+ comments = get_comment_model_method(resource, nil).all
51
85
  end
86
+ comments
87
+ end
52
88
 
89
+ def get_comment_model_method(resource, role)
90
+ if role
91
+ role_comments = role + "_comments"
92
+ else
93
+ role_comments = "comments"
94
+ end
95
+ resource.send(role_comments)
53
96
  end
54
97
 
55
- def create
56
- resource = fetch_resource
57
- resource.comments.create(comments_params)
58
- @parent_div = params[:parent_div]
59
- redirect_to "/commenteux/#{@resource.downcase}/#{@resource_id}?parent_div=" + @parent_div
98
+ def manage_roles_parameter(roles_parameter)
99
+ roles = []
100
+ if roles_parameter and roles_parameter.include?(',')
101
+ splitted = roles_parameter.split(',')
102
+ for str in splitted do
103
+ values = [str, I18n.t(str)]
104
+ roles << values
105
+ end
106
+ end
107
+ roles
60
108
  end
61
109
 
62
110
  end
@@ -1,9 +1,11 @@
1
1
  module Commenteux
2
2
  module NotesHelper
3
3
 
4
- def user_lookup(user_id)
5
- if user_id
6
- User.find(user_id).name
4
+ def display_role?(roles)
5
+ if roles and roles.length > 0
6
+ true
7
+ else
8
+ false
7
9
  end
8
10
  end
9
11
 
@@ -0,0 +1,11 @@
1
+ module Commenteux
2
+ module UsersHelper
3
+
4
+ def user_lookup(user_id)
5
+ if user_id
6
+ User.find(user_id).name
7
+ end
8
+ end
9
+
10
+ end
11
+ end
@@ -2,9 +2,12 @@
2
2
  <table class="table">
3
3
  <thead>
4
4
  <tr>
5
- <th>Commentaire</th>
6
- <th>Fait par</th>
7
- <th>Date</th>
5
+ <th class="col-md-6">Commentaire</th>
6
+ <th class="col-md-2">Fait par</th>
7
+ <th class="col-md-2">Date</th>
8
+ <% if display_role?(@roles) %>
9
+ <th class="col-md-2">Rôle</th>
10
+ <% end %>
8
11
  </tr>
9
12
  </thead>
10
13
 
@@ -19,6 +22,11 @@
19
22
  <td>
20
23
  <%= comment.created_at.in_time_zone('Eastern Time (US & Canada)').strftime("%Y-%m-%d %H:%M:%S") %>
21
24
  </td>
25
+ <% if display_role?(@roles) %>
26
+ <td>
27
+ <%= I18n.t(comment.role) %>
28
+ </td>
29
+ <% end %>
22
30
  </tr>
23
31
  <% end %>
24
32
  </table>
@@ -27,4 +35,5 @@
27
35
  <%= link_to "Nouveau", "#", :id => "new_notes_link", :class => 'btn btn-primary',
28
36
  :data => {:parent => @parent_div,
29
37
  :resource => @resource.downcase,
30
- :id => @resource_id } %>
38
+ :id => @resource_id,
39
+ :roles => @roles} %>
@@ -1,4 +1,4 @@
1
- <%= simple_form_for @comments, as: 'comments', url: "/commenteux/#{@resource.downcase}/#{@resource_id}?parent_div=#{@parent_div}",
1
+ <%= simple_form_for @comments, as: 'comments', url: "/commenteux/#{@resource.downcase}/#{@resource_id}?parent_div=#{@parent_div}&roles=#{@roles.blank? ? '' : @roles}",
2
2
  :remote => true, :data => {:parent => @parent_div}, wrapper: :bootstrap do |c| %>
3
3
 
4
4
  <div style="display:none">
@@ -11,6 +11,14 @@
11
11
  </div>
12
12
  <% end %>
13
13
 
14
+ <% unless @list_roles.blank? %>
15
+
16
+ <%= c.input :role, collection: @list_roles, as: :radio_buttons, :label_method => :last, :value_method => :first,
17
+ :input_html => {:data => {:required => true}}, label: 'Rôle',
18
+ :item_wrapper_class => 'inline' %>
19
+
20
+ <% end %>
21
+
14
22
  <div class="form-actions form-actions-padding-sm">
15
23
  <div class="row">
16
24
  <div class="col-md-10 col-md-offset-5">
@@ -22,7 +30,8 @@
22
30
  <%= link_to "Annuler", "#", :id => "new_notes_cancelled", :class => 'btn',
23
31
  :data => {:parent => @parent_div,
24
32
  :resource => @resource.downcase,
25
- :id => @resource_id } %>
33
+ :id => @resource_id,
34
+ :roles => @roles} %>
26
35
 
27
36
  </div>
28
37
  </div>
data/config/cucumber.yml CHANGED
@@ -2,7 +2,9 @@
2
2
  rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
3
  rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4
4
  std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
5
+ #std_opts = "-r features/support/ -r features/step_definitions --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
5
6
  %>
6
7
  default: <%= std_opts %> features
7
8
  wip: --tags @wip:3 --wip features
8
9
  rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
10
+
@@ -1,3 +1,3 @@
1
1
  module Commenteux
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
@@ -1,7 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
+
3
4
  module Commenteux
4
- describe NotesController do
5
+ describe Commenteux::NotesController do
5
6
  routes { Commenteux::Engine.routes }
6
7
 
7
8
  before(:each) do
@@ -11,22 +12,40 @@ module Commenteux
11
12
 
12
13
  describe "GET 'index'" do
13
14
 
14
- it "doit fetché la ressource passé en paramètre, le layout de l'application hôte sera utilisé" do
15
+ it "doit fetché la ressource passé en paramètre, le layout de l'application hôte sera utilisé, avec le paramètre rôle" do
16
+ comment_comments = double("comment_comments")
17
+ delivery_man_comments = double("delivery_man_comments")
18
+ list_roles = [comment_comments, delivery_man_comments]
19
+
20
+ expect(DummyModel).to receive(:find).with('1') {@dummy_model}
15
21
 
16
- DummyModel.should_receive(:find).with('1').and_return(@dummy_model)
17
- @dummy_model.stub(:comments) { @comments }
18
- @comments.stub(:all) { [] }
19
- get 'index', 'resource' => 'dummy_model', 'resource_id' => '1'
22
+ expect(subject).to receive(:manage_roles_parameter).with('comments,delivery_man') {list_roles}
23
+ expect(subject).to receive(:get_comments).with(@dummy_model, list_roles) {[comment_comments, delivery_man_comments]}
24
+
25
+ get 'index', resource: 'dummy_model', resource_id: '1', roles: 'comments,delivery_man'
20
26
 
21
27
  assert_template layout: 'application'
28
+ end
29
+
30
+ it "doit fetché la ressource passé en paramètre, le layout de l'application hôte sera utilisé, sans le paramètre rôle" do
31
+ comment_comments = double("comment_comments")
32
+ delivery_man_comments = double("delivery_man_comments")
33
+
34
+ expect(DummyModel).to receive(:find).with('1') {@dummy_model}
35
+
36
+ expect(subject).to receive(:manage_roles_parameter).with(nil) {[]}
37
+ expect(subject).to receive(:get_comments).with(@dummy_model, []) {[comment_comments, delivery_man_comments]}
22
38
 
39
+ get 'index', resource: 'dummy_model', resource_id: '1'
40
+
41
+ assert_template layout: 'application'
23
42
  end
24
43
 
25
44
  it "si l'appel provient d'un call Ajax, on n'affiche pas de layout" do
26
45
 
27
- DummyModel.should_receive(:find).with('1').and_return(@dummy_model)
28
- @dummy_model.stub(:comments) { @comments }
29
- @comments.stub(:all) { [] }
46
+ expect(DummyModel).to receive(:find).with('1') {@dummy_model}
47
+ expect(@dummy_model).to receive(:comments) {@comments}
48
+ expect(@comments).to receive(:all) {[]}
30
49
  xhr :get, 'index', 'resource' => 'dummy_model', 'resource_id' => '1'
31
50
 
32
51
  assert_template layout: false
@@ -37,11 +56,11 @@ module Commenteux
37
56
 
38
57
  describe "GET 'new'" do
39
58
 
40
- it "doit fetché la ressource en paramètre et préparé le nouveau commentaire a saisir, le layout de l'application hôte sera utilisé" do
59
+ it "doit fetché la ressource en paramètre et préparé le nouveau commentaire a saisir, le layout de l'application hôte sera utilisé, sans le paramètre rôle" do
41
60
 
42
- subject.should_receive(:fetch_resource).and_return(@dummy_model)
43
- @dummy_model.stub(:comments) { @comments }
44
- @comments.should_receive(:new)
61
+ expect(subject).to receive(:fetch_resource) {@dummy_model}
62
+ expect(@dummy_model).to receive(:send).with('comments') {@comments}
63
+ expect(@comments).to receive(:new)
45
64
 
46
65
  get 'new', 'resource' => 'dummy_model', 'resource_id' => '1'
47
66
 
@@ -49,11 +68,23 @@ module Commenteux
49
68
 
50
69
  end
51
70
 
71
+ it "doit fetché la ressource en paramètre et préparé le nouveau commentaire a saisir, le layout de l'application hôte sera utilisé, avec le paramètre rôle" do
72
+
73
+ expect(subject).to receive(:fetch_resource) {@dummy_model}
74
+ expect(@dummy_model).to receive(:send).with('comments_comments') {@comments}
75
+ expect(@comments).to receive(:new)
76
+
77
+ get 'new', 'resource' => 'dummy_model', 'resource_id' => '1', 'roles' => 'comments,delivery_man'
78
+
79
+ assert_template layout: 'application'
80
+
81
+ end
82
+
52
83
  it "si l'appel provient d'un call Ajax, on n'affiche pas de layout" do
53
84
 
54
- subject.should_receive(:fetch_resource).and_return(@dummy_model)
55
- @dummy_model.stub(:comments) { @comments }
56
- @comments.should_receive(:new)
85
+ expect(subject).to receive(:fetch_resource) {@dummy_model}
86
+ expect(@dummy_model).to receive(:send).with('comments') {@comments}
87
+ expect(@comments).to receive(:new)
57
88
 
58
89
  xhr :get, 'new', 'resource' => 'dummy_model', 'resource_id' => '1'
59
90
 
@@ -65,30 +96,109 @@ module Commenteux
65
96
 
66
97
  describe "POST 'create'" do
67
98
 
68
- it "Doit créer le commentaire saisi sur la ressource en paramètre" do
99
+ it "Doit créer le commentaire saisi sur la ressource en paramètre, rôle spécifié en paramètre" do
100
+
101
+ expect(DummyModel).to receive(:find).with('1') {@dummy_model}
102
+ expect(@dummy_model).to receive(:send).with('delivery_man_comments') {@comments}
103
+ expect(@comments).to receive(:create).with({ 'title' => 'Titre', 'comment' => 'Commentaire', 'role' => 'delivery_man'})
69
104
 
70
- DummyModel.should_receive(:find).with('1').and_return(@dummy_model)
71
- @dummy_model.stub(:comments) { @comments }
72
- @comments.should_receive(:create).with( { 'title' => 'Titre', 'comment' => 'Commentaire'} )
105
+ post 'create', 'resource' => 'dummy_model', 'resource_id' => '1', 'parent_div' => 'parent_div', 'comments' => { 'title' => 'Titre', 'comment' => 'Commentaire', 'role' => 'delivery_man'}, 'roles' => 'comments,delivery_man'
73
106
 
74
- post 'create', 'resource' => 'dummy_model', 'resource_id' => '1', 'parent_div' => 'parent_div', :comments => { :title => 'Titre', :comment => 'Commentaire'}
107
+ expect(subject).to redirect_to("/commenteux/dummy_model/1?parent_div=parent_div&roles=comments,delivery_man")
75
108
 
76
109
  end
77
110
 
111
+ it "Doit créer le commentaire saisi sur la ressource en paramètre, rôle non spécifié en paramètre" do
112
+
113
+ expect(DummyModel).to receive(:find).with('1') {@dummy_model}
114
+ expect(@dummy_model).to receive(:send).with('comments') {@comments}
115
+ expect(@comments).to receive(:create).with({ 'title' => 'Titre', 'comment' => 'Commentaire'})
116
+
117
+ post 'create', 'resource' => 'dummy_model', 'resource_id' => '1', 'parent_div' => 'parent_div', 'comments' => { 'title' => 'Titre', 'comment' => 'Commentaire'}
118
+
119
+ expect(subject).to redirect_to("/commenteux/dummy_model/1?parent_div=parent_div")
120
+ end
78
121
  end
79
122
 
80
123
  describe "Comportement de la méthode 'classify_namespace'" do
81
124
 
82
125
  it "s'il n'y a pas de namespace, on fait un simple classify" do
83
- subject.classify_namespace('dummy_model').should eq 'DummyModel'
84
- subject.classify_namespace('customer').should eq 'Customer'
126
+ dummyModel = controller.send(:classify_namespace, 'dummy_model')
127
+ expect(dummyModel).to eq 'DummyModel'
128
+
129
+ customer = controller.send(:classify_namespace, 'customer')
130
+ expect(customer).to eq 'Customer'
85
131
  end
86
132
 
87
133
  it "s'il y a un namespace, on fait un classify sur tous les éléments" do
88
- subject.classify_namespace('client::customers').should eq 'Client::Customer'
89
- subject.classify_namespace('namespace::dummy_model').should eq 'Namespace::DummyModel'
134
+ customer = controller.send(:classify_namespace, 'client::customers')
135
+ expect(customer).to eq 'Client::Customer'
136
+
137
+ dummyModel = controller.send(:classify_namespace, 'namespace::dummy_model')
138
+ expect(dummyModel).to eq 'Namespace::DummyModel'
139
+ end
140
+
141
+ end
142
+
143
+ describe "Comportement de la méthode 'get_comments'" do
144
+
145
+ it "s'il y a plusieurs roles de spécifiés" do
146
+ comments1 = double("comments1")
147
+ comments2 = double("comments2")
148
+
149
+ expect(@dummy_model).to receive(:send).with('comments_comments') {comments1}
150
+ expect(comments1).to receive(:all) {[comments1]}
151
+
152
+ expect(@dummy_model).to receive(:send).with('delivery_man_comments') {comments2}
153
+ expect(comments2).to receive(:all) {[comments2]}
154
+
155
+ comments = controller.send(:get_comments, @dummy_model, [['comments','Admin'],['delivery_man','Livreur']])
156
+
157
+ expect(comments[0]).to eq comments1
158
+ expect(comments[1]).to eq comments2
159
+ end
160
+
161
+ it "s'il y a aucun role de spécifié" do
162
+ comments1 = double("comments1")
163
+
164
+ expect(@dummy_model).to receive(:comments) {comments1}
165
+ expect(comments1).to receive(:all) {[comments1]}
166
+
167
+ comments = controller.send(:get_comments, @dummy_model, nil)
168
+
169
+ expect(comments[0]).to eq comments1
170
+ end
171
+
172
+ end
173
+
174
+ describe "Comportement de la méthode 'get_comment_method'" do
175
+
176
+ it "s'il y a un rôle spécifié" do
177
+ expect(@dummy_model).to receive(:send).with("delivery_man_comments") {@comments}
178
+ controller.send(:get_comment_model_method, @dummy_model, "delivery_man")
90
179
  end
91
180
 
181
+ it "s'il n'y a pas de rôle spécifié" do
182
+ expect(@dummy_model).to receive(:send).with("comments") {@comments}
183
+ controller.send(:get_comment_model_method, @dummy_model, nil)
184
+ end
185
+
186
+ end
187
+
188
+ describe "Comportement de la méthode 'manage_roles_parameter'" do
189
+ it "avec paramètres" do
190
+ list_roles = controller.send(:manage_roles_parameter, 'comments,delivery_man')
191
+
192
+ expect(list_roles).to eq [['comments','Administrateur'],['delivery_man','Livreur']]
193
+ end
194
+ end
195
+
196
+ describe "Comportement de la méthode 'manage_roles_parameter'" do
197
+ it "sans paramètre" do
198
+ list_roles = controller.send(:manage_roles_parameter, nil)
199
+
200
+ expect(list_roles).to eq []
201
+ end
92
202
  end
93
203
 
94
204
  end
@@ -1,3 +1,3 @@
1
1
  class DummyModel < ActiveRecord::Base
2
- acts_as_commentable
2
+ acts_as_commentable :delivery_man, :comments
3
3
  end
@@ -0,0 +1,3 @@
1
+ class DummyNoRoleModel < ActiveRecord::Base
2
+ acts_as_commentable
3
+ end
@@ -21,3 +21,5 @@
21
21
 
22
22
  en:
23
23
  hello: "Hello world"
24
+ comments: "Administrateur"
25
+ delivery_man: "Livreur"
@@ -0,0 +1,10 @@
1
+ class CreateDummyNoRoleModels < ActiveRecord::Migration
2
+ def change
3
+ create_table :dummy_no_role_models do |t|
4
+
5
+ t.text :text
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20140312000846) do
14
+ ActiveRecord::Schema.define(version: 20150612102101) do
15
15
 
16
16
  create_table "comments", force: true do |t|
17
17
  t.string "title", limit: 50, default: ""
@@ -34,4 +34,10 @@ ActiveRecord::Schema.define(version: 20140312000846) do
34
34
  t.datetime "updated_at"
35
35
  end
36
36
 
37
+ create_table "dummy_no_role_models", force: true do |t|
38
+ t.text "text"
39
+ t.datetime "created_at"
40
+ t.datetime "updated_at"
41
+ end
42
+
37
43
  end