discuss 0.0.1

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 (151) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +153 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/discuss/application.js +3 -0
  6. data/app/assets/javascripts/discuss/chosen.jquery.js +1104 -0
  7. data/app/assets/javascripts/discuss/compose.coffee +21 -0
  8. data/app/assets/javascripts/discuss/discuss.chosen.coffee +2 -0
  9. data/app/assets/javascripts/discuss/discuss.coffee +2 -0
  10. data/app/assets/javascripts/discuss/messages.coffee +0 -0
  11. data/app/assets/stylesheets/discuss/application.css +13 -0
  12. data/app/assets/stylesheets/discuss/chosen.css +439 -0
  13. data/app/controllers/discuss/application_controller.rb +11 -0
  14. data/app/controllers/discuss/mailboxes_controller.rb +30 -0
  15. data/app/controllers/discuss/messages_controller.rb +85 -0
  16. data/app/helpers/discuss/application_helper.rb +7 -0
  17. data/app/models/discuss/conversation.rb +29 -0
  18. data/app/models/discuss/mailbox.rb +33 -0
  19. data/app/models/discuss/message.rb +135 -0
  20. data/app/services/discuss/message_sender.rb +33 -0
  21. data/app/views/discuss/mailboxes/show.html.haml +24 -0
  22. data/app/views/discuss/messages/_form.html.haml +18 -0
  23. data/app/views/discuss/messages/edit.html.haml +1 -0
  24. data/app/views/discuss/messages/new.html.haml +1 -0
  25. data/app/views/discuss/messages/show.html.haml +28 -0
  26. data/app/views/discuss/shared/_nav.haml +8 -0
  27. data/config/routes.rb +15 -0
  28. data/db/migrate/20130419055252_setup_discuss.rb +22 -0
  29. data/lib/discuss.rb +4 -0
  30. data/lib/discuss/engine.rb +9 -0
  31. data/lib/discuss/models/discussable.rb +29 -0
  32. data/lib/discuss/version.rb +3 -0
  33. data/lib/generators/discuss/views_generator.rb +8 -0
  34. data/lib/tasks/discuss_tasks.rake +4 -0
  35. data/test/discuss_test.rb +7 -0
  36. data/test/dummy/README.rdoc +28 -0
  37. data/test/dummy/Rakefile +6 -0
  38. data/test/dummy/app/assets/javascripts/application.js +5 -0
  39. data/test/dummy/app/assets/javascripts/chosen.jquery.js +1104 -0
  40. data/test/dummy/app/assets/javascripts/compose.coffee +21 -0
  41. data/test/dummy/app/assets/javascripts/discuss.chosen.coffee +2 -0
  42. data/test/dummy/app/assets/javascripts/discuss.coffee +2 -0
  43. data/test/dummy/app/assets/javascripts/messages.coffee +0 -0
  44. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  45. data/test/dummy/app/assets/stylesheets/chosen.css +439 -0
  46. data/test/dummy/app/assets/stylesheets/discuss.css +41 -0
  47. data/test/dummy/app/controllers/application_controller.rb +5 -0
  48. data/test/dummy/app/helpers/application_helper.rb +2 -0
  49. data/test/dummy/app/models/user.rb +22 -0
  50. data/test/dummy/app/views/layouts/application.html.erb +17 -0
  51. data/test/dummy/bin/bundle +3 -0
  52. data/test/dummy/bin/rails +4 -0
  53. data/test/dummy/bin/rake +4 -0
  54. data/test/dummy/config.ru +4 -0
  55. data/test/dummy/config/application.rb +23 -0
  56. data/test/dummy/config/boot.rb +9 -0
  57. data/test/dummy/config/database.yml +25 -0
  58. data/test/dummy/config/environment.rb +5 -0
  59. data/test/dummy/config/environments/development.rb +27 -0
  60. data/test/dummy/config/environments/production.rb +80 -0
  61. data/test/dummy/config/environments/test.rb +36 -0
  62. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  63. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  64. data/test/dummy/config/initializers/inflections.rb +16 -0
  65. data/test/dummy/config/initializers/mime_types.rb +5 -0
  66. data/test/dummy/config/initializers/secret_token.rb +12 -0
  67. data/test/dummy/config/initializers/session_store.rb +3 -0
  68. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  69. data/test/dummy/config/locales/en.yml +23 -0
  70. data/test/dummy/config/routes.rb +4 -0
  71. data/test/dummy/db/development.sqlite3 +0 -0
  72. data/test/dummy/db/migrate/20130428235128_create_users.rb +11 -0
  73. data/test/dummy/db/schema.rb +24 -0
  74. data/test/dummy/db/test.sqlite3 +0 -0
  75. data/test/dummy/log/development.log +16219 -0
  76. data/test/dummy/log/test.log +191354 -0
  77. data/test/dummy/public/404.html +27 -0
  78. data/test/dummy/public/422.html +26 -0
  79. data/test/dummy/public/500.html +26 -0
  80. data/test/dummy/public/favicon.ico +0 -0
  81. data/test/dummy/tmp/cache/assets/development/sprockets/0a28667732e1be8938cde061b6f996df +0 -0
  82. data/test/dummy/tmp/cache/assets/development/sprockets/0ddd7cc29057a69bd29fde03bf0f4c00 +0 -0
  83. data/test/dummy/tmp/cache/assets/development/sprockets/0de2f69502366965bb7fae2623bc190c +0 -0
  84. data/test/dummy/tmp/cache/assets/development/sprockets/0ee691067e6ec8f03df58bc94badd25d +0 -0
  85. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  86. data/test/dummy/tmp/cache/assets/development/sprockets/1b77abb6bee52fa8d68ee7e81077ff20 +0 -0
  87. data/test/dummy/tmp/cache/assets/development/sprockets/271bb8f72971af6089be8d1b85788bec +0 -0
  88. data/test/dummy/tmp/cache/assets/development/sprockets/2a499e57eb2664f139ab0e74571faa77 +0 -0
  89. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  90. data/test/dummy/tmp/cache/assets/development/sprockets/32b6af14546cb11e773fb3799f041132 +0 -0
  91. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  92. data/test/dummy/tmp/cache/assets/development/sprockets/4728f8b9616c35f685674fbeecaa3c47 +0 -0
  93. data/test/dummy/tmp/cache/assets/development/sprockets/4e9a3e121da30d3a85273a5c283da214 +0 -0
  94. data/test/dummy/tmp/cache/assets/development/sprockets/5620ff4659033b350ea3031ecaeb5127 +0 -0
  95. data/test/dummy/tmp/cache/assets/development/sprockets/596293af7e4dcfa45880435ae753f876 +0 -0
  96. data/test/dummy/tmp/cache/assets/development/sprockets/614995c5e7b1b4f5b12ce060404706cc +0 -0
  97. data/test/dummy/tmp/cache/assets/development/sprockets/6b9e24a8aad25948823e1a93c8be731e +0 -0
  98. data/test/dummy/tmp/cache/assets/development/sprockets/78a00003621b318a297e05cfedb0d1fd +0 -0
  99. data/test/dummy/tmp/cache/assets/development/sprockets/794654d117cd2ec6a9a00e485d9f4485 +0 -0
  100. data/test/dummy/tmp/cache/assets/development/sprockets/79ae3a9f48e9b9e8ef2922c844b1895f +0 -0
  101. data/test/dummy/tmp/cache/assets/development/sprockets/9b5889bea21f2af8068646890752932c +0 -0
  102. data/test/dummy/tmp/cache/assets/development/sprockets/9fd02d20091838d6411df2d23a5364d5 +0 -0
  103. data/test/dummy/tmp/cache/assets/development/sprockets/a02345b542298f25d3f701ee680c44c0 +0 -0
  104. data/test/dummy/tmp/cache/assets/development/sprockets/a80359c0e09ddf510ce63de09a368d4c +0 -0
  105. data/test/dummy/tmp/cache/assets/development/sprockets/ad2a9bfe4169e0a5bc66efd35c83fe38 +0 -0
  106. data/test/dummy/tmp/cache/assets/development/sprockets/b1794788ec8ce362aceaffa31c7381e9 +0 -0
  107. data/test/dummy/tmp/cache/assets/development/sprockets/b284f477944d67f25c0672dba1a2dab4 +0 -0
  108. data/test/dummy/tmp/cache/assets/development/sprockets/b2b1f16cf54d69c151ca7f42fb2f8381 +0 -0
  109. data/test/dummy/tmp/cache/assets/development/sprockets/b4767dfdb540517d26dc8c5365736f53 +0 -0
  110. data/test/dummy/tmp/cache/assets/development/sprockets/bab78b46d2a6282e5df747dd8b6d5abf +0 -0
  111. data/test/dummy/tmp/cache/assets/development/sprockets/c9a09977565da30179ad7fdb9f79ae0d +0 -0
  112. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  113. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  114. data/test/dummy/tmp/cache/assets/development/sprockets/d9c8047218dc90a46a6725543638de45 +0 -0
  115. data/test/dummy/tmp/cache/assets/development/sprockets/e5b181eb056bbd6ffad37ed146b0342e +0 -0
  116. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  117. data/test/dummy/tmp/cache/assets/test/sprockets/0a28667732e1be8938cde061b6f996df +0 -0
  118. data/test/dummy/tmp/cache/assets/test/sprockets/0ddd7cc29057a69bd29fde03bf0f4c00 +0 -0
  119. data/test/dummy/tmp/cache/assets/test/sprockets/0de2f69502366965bb7fae2623bc190c +0 -0
  120. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  121. data/test/dummy/tmp/cache/assets/test/sprockets/1b77abb6bee52fa8d68ee7e81077ff20 +0 -0
  122. data/test/dummy/tmp/cache/assets/test/sprockets/271bb8f72971af6089be8d1b85788bec +0 -0
  123. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  124. data/test/dummy/tmp/cache/assets/test/sprockets/32b6af14546cb11e773fb3799f041132 +0 -0
  125. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  126. data/test/dummy/tmp/cache/assets/test/sprockets/4728f8b9616c35f685674fbeecaa3c47 +0 -0
  127. data/test/dummy/tmp/cache/assets/test/sprockets/5620ff4659033b350ea3031ecaeb5127 +0 -0
  128. data/test/dummy/tmp/cache/assets/test/sprockets/596293af7e4dcfa45880435ae753f876 +0 -0
  129. data/test/dummy/tmp/cache/assets/test/sprockets/78a00003621b318a297e05cfedb0d1fd +0 -0
  130. data/test/dummy/tmp/cache/assets/test/sprockets/794654d117cd2ec6a9a00e485d9f4485 +0 -0
  131. data/test/dummy/tmp/cache/assets/test/sprockets/79ae3a9f48e9b9e8ef2922c844b1895f +0 -0
  132. data/test/dummy/tmp/cache/assets/test/sprockets/9b5889bea21f2af8068646890752932c +0 -0
  133. data/test/dummy/tmp/cache/assets/test/sprockets/9fd02d20091838d6411df2d23a5364d5 +0 -0
  134. data/test/dummy/tmp/cache/assets/test/sprockets/a02345b542298f25d3f701ee680c44c0 +0 -0
  135. data/test/dummy/tmp/cache/assets/test/sprockets/a80359c0e09ddf510ce63de09a368d4c +0 -0
  136. data/test/dummy/tmp/cache/assets/test/sprockets/ad2a9bfe4169e0a5bc66efd35c83fe38 +0 -0
  137. data/test/dummy/tmp/cache/assets/test/sprockets/bab78b46d2a6282e5df747dd8b6d5abf +0 -0
  138. data/test/dummy/tmp/cache/assets/test/sprockets/c9a09977565da30179ad7fdb9f79ae0d +0 -0
  139. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  140. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  141. data/test/dummy/tmp/cache/assets/test/sprockets/d9c8047218dc90a46a6725543638de45 +0 -0
  142. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  143. data/test/features/workflow_test.rb +182 -0
  144. data/test/test_helper.rb +68 -0
  145. data/test/unit/discuss/conversation_test.rb +79 -0
  146. data/test/unit/discuss/mailbox_test.rb +72 -0
  147. data/test/unit/discuss/message_test.rb +73 -0
  148. data/test/unit/discuss/recipient_test.rb +56 -0
  149. data/test/unit/discuss/sender_test.rb +106 -0
  150. data/test/unit/helpers/discuss/messages_helper_test.rb +6 -0
  151. metadata +422 -0
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ <p>If you are the application owner check the logs for more information.</p>
26
+ </body>
27
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ <p>If you are the application owner check the logs for more information.</p>
25
+ </body>
26
+ </html>
File without changes
@@ -0,0 +1,182 @@
1
+ require 'test_helper'
2
+
3
+ class WorkFlowTest< FeatureTest
4
+
5
+ it 'seeing an empty inbox' do
6
+ visit "/discuss/mailbox/inbox" # discuss.mailbox_path(:inbox)
7
+ assert page.has_content?('Inbox')
8
+ assert page.has_content?('0 messages')
9
+ end
10
+
11
+ context 'new message' do
12
+ it 'composes a draft' do
13
+ visit '/discuss/message/compose'
14
+ select 'bart simpsons', from: 'Recipients'
15
+ fill_in 'Subject', with: 'camping trip'
16
+ fill_in 'Your message', with: "who's bringing what?"
17
+ check 'Draft'
18
+ click_on 'Send message'
19
+
20
+ assert page.has_css?('div.notice')
21
+ assert_equal 1, Discuss::Mailbox.new(@sender).drafts.count
22
+ assert_equal 0, Discuss::Mailbox.new(@recipient).inbox.count
23
+ end
24
+
25
+ it 'sends a message' do
26
+ visit '/discuss/message/compose'
27
+ select 'bart simpsons', from: 'Recipients'
28
+ fill_in 'Subject', with: 'camping trip'
29
+ fill_in 'Your message', with: "who's bringing what?"
30
+ click_on 'Send message'
31
+ assert page.has_css?('div.notice')
32
+ assert_equal 1, Discuss::Mailbox.new(@sender).outbox.count
33
+ assert_equal 1, Discuss::Mailbox.new(@recipient).inbox.count
34
+ end
35
+ end
36
+
37
+ context 'with messages' do
38
+ before do
39
+ @draft = @sender.messages.create(body: 'only for me eyes', recipients: [@lisa])
40
+ @message = @sender.messages.create(body: 'lorem ipsum', recipients: [@recipient])
41
+ @message.send!
42
+ @outbox = Discuss::Mailbox.new(@sender).outbox
43
+ end
44
+
45
+ it 'redirects to inbox if message is not mine' do
46
+ message = Discuss::Message.last
47
+ visit "/discuss/mailbox/inbox/#{message.id}"
48
+ assert_equal "/discuss/mailbox/inbox", current_path
49
+ refute page.has_content?(message.body)
50
+ refute page.has_css?('.reply')
51
+ end
52
+
53
+ it 'sees an outbox' do
54
+ assert_equal 1, @outbox.count
55
+
56
+ visit '/discuss/mailbox/outbox'
57
+ assert page.has_content?('1 message')
58
+ within '.messages' do
59
+ assert page.has_content?(@recipient.to_s)
60
+ end
61
+ end
62
+
63
+ it 'sees drafts' do
64
+ visit '/discuss/mailbox/drafts'
65
+ assert page.has_content?('Drafts')
66
+
67
+ within '.messages' do
68
+ assert page.has_content?(@draft.body)
69
+ assert page.has_content?(@lisa.to_s)
70
+ end
71
+ end
72
+
73
+ it 'sees trash' do
74
+ @draft.trash!
75
+ @outbox.first.trash!
76
+ visit '/discuss/mailbox/trash'
77
+ assert page.has_content?('Trash')
78
+ assert page.has_content?('2 messages')
79
+
80
+ within '.messages' do
81
+ assert_equal 2, page.all('.discuss_message').size
82
+ assert page.has_content?(@draft.body)
83
+ assert page.has_content?(@recipient.to_s)
84
+ end
85
+ end
86
+
87
+ it 'moves a message to trash' do
88
+ visit "/discuss/message/#{@message.id}"
89
+ click_on 'Move to trash'
90
+ assert page.has_content?('Message moved to trash')
91
+ assert_equal 0, Discuss::Mailbox.new(@sender).outbox.count
92
+ assert_equal 1, Discuss::Mailbox.new(@sender).trash.count
93
+ end
94
+
95
+ it 'empties trash' do
96
+ @message.trash!
97
+ assert_equal 1, Discuss::Mailbox.new(@sender).trash.count
98
+
99
+ visit '/discuss/mailbox/trash'
100
+ click_on 'Empty trash'
101
+ assert page.has_content?('Trash has been emptied')
102
+ assert_equal 0, Discuss::Mailbox.new(@sender).trash.count
103
+ end
104
+
105
+ it 'views a sent message' do
106
+ visit "/discuss/message/#{@message.id}"
107
+
108
+ within '.headers' do
109
+ assert page.has_content?(@message.sender)
110
+ assert page.has_content?('Recipients: bart simpsons')
111
+ end
112
+ end
113
+
114
+ it 'views a recieved message' do
115
+ message = Discuss::Mailbox.new(@recipient).inbox.first
116
+ message.reply! body: 'first reply'
117
+ recieved_message = Discuss::Mailbox.new(@sender).inbox.last
118
+
119
+ visit "/discuss/message/#{recieved_message.id}"
120
+ within 'div.compose' do
121
+ assert page.has_xpath?("//form[@action='/discuss/message/#{recieved_message.id}/reply']")
122
+ refute page.has_content?('Recipients')
123
+ end
124
+ end
125
+
126
+ it 'redirects to show view if uneditable?' do
127
+ visit "/discuss/message/#{@message.id}/edit"
128
+ assert_equal "/discuss/message/#{@message.id}", current_path
129
+ end
130
+
131
+ it 'redirects to edit view if unsent?' do
132
+ visit "/discuss/message/#{@draft.id}"
133
+ assert_equal "/discuss/message/#{@draft.id}/edit", current_path
134
+ end
135
+
136
+ it 'sends a draft' do
137
+ visit "/discuss/message/#{@draft.id}/edit"
138
+ fill_in 'Subject', with: 'great to go public'
139
+ fill_in 'Your message', with: 'not for my eyes only anymore'
140
+ click_on 'Send message'
141
+
142
+ assert page.has_css?('div.notice')
143
+ assert_equal 0, Discuss::Mailbox.new(@sender).drafts.count
144
+ assert_equal 1, Discuss::Mailbox.new(@lisa).inbox.count
145
+ end
146
+
147
+ it 'edits a draft' do
148
+ visit "/discuss/message/#{@draft.id}/edit"
149
+ fill_in 'Subject', with: 'not yet'
150
+ check 'Draft'
151
+ click_on 'Send message'
152
+
153
+ assert page.has_css?('div.notice')
154
+ assert_equal 1, Discuss::Mailbox.new(@sender).drafts.count
155
+ assert_equal 0, Discuss::Mailbox.new(@lisa).inbox.count
156
+ end
157
+
158
+ it 'does not see reply form if I sent the message' do
159
+ assert_equal @sender, @message.sender
160
+ visit "/discuss/message/#{@message.id}"
161
+ refute page.has_css?('.compose.reply')
162
+ end
163
+
164
+ it 'replies' do
165
+ message = Discuss::Mailbox.new(@recipient).inbox.first
166
+ message.reply! body: 'first reply'
167
+ recieved_message = Discuss::Mailbox.new(@sender).inbox.last
168
+
169
+ visit "/discuss/message/#{recieved_message.id}"
170
+
171
+ within 'div.compose' do
172
+ fill_in 'Your message', with: 'This is what I think on your previous message'
173
+ click_on 'Reply'
174
+ end
175
+
176
+ assert page.has_css?('div.notice')
177
+ assert_equal 2, Discuss::Mailbox.new(@sender).outbox.count
178
+ assert_equal 2, Discuss::Mailbox.new(@recipient).inbox.count
179
+ end
180
+ end
181
+ end
182
+
@@ -0,0 +1,68 @@
1
+ # Configure Rails Environment
2
+ ENV['RAILS_ENV'] = 'test'
3
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
4
+
5
+ require 'rails/test_help'
6
+ require 'minitest/autorun'
7
+ require 'minitest/spec'
8
+ require 'minitest/mock'
9
+ require 'capybara/rails'
10
+ require 'debugger'
11
+
12
+ require 'minitest/reporters'
13
+ MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
14
+
15
+ Rails.backtrace_cleaner.remove_silencers!
16
+
17
+ # Load support files
18
+ Dir['#{File.dirname(__FILE__)}/support/**/*.rb'].each { |f| require f }
19
+
20
+ require 'database_cleaner'
21
+ DatabaseCleaner.strategy = :truncation
22
+
23
+ class MiniTest::Spec
24
+ before(:each) do
25
+ DatabaseCleaner.start
26
+ create_users
27
+ end
28
+
29
+ after(:each) { DatabaseCleaner.clean }
30
+
31
+ class << self
32
+ alias context describe
33
+ end
34
+ end
35
+
36
+ class FeatureTest < MiniTest::Spec
37
+ include Rails.application.routes.url_helpers # to get url_helpers working
38
+ include Capybara::DSL # to get capybara working
39
+
40
+ before(:each) do
41
+ create_users
42
+ bypass_user
43
+ end
44
+
45
+ after(:each) { restore_user }
46
+ end
47
+
48
+
49
+ def create_users
50
+ @sender = User.where(email: 'teacher@school.com', first_name: 'teacher').first_or_create
51
+ @recipient = User.where(email: 'bart@student.com', first_name: 'bart', last_name: 'simpsons').first_or_create
52
+ @lisa = User.where(email: 'lisa@student.com', first_name: 'lisa', last_name: 'simpsons').first_or_create
53
+ end
54
+
55
+
56
+ def bypass_user(user=User.first)
57
+ current_user = @sender unless @current_user
58
+ Discuss::ApplicationController.send(:alias_method, :old_user, :discuss_current_user)
59
+ Discuss::ApplicationController.send(:define_method, :discuss_current_user) do
60
+ current_user
61
+ end
62
+ @current_user = current_user
63
+ end
64
+
65
+
66
+ def restore_user
67
+ Discuss::ApplicationController.send(:alias_method, :discuss_current_user, :old_user)
68
+ end