admin_assistant 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. data/Rakefile +2 -2
  2. data/VERSION +1 -1
  3. data/admin_assistant.gemspec +2 -171
  4. metadata +4 -173
  5. data/rails_3_0/Gemfile +0 -12
  6. data/rails_3_0/Gemfile.lock +0 -100
  7. data/rails_3_0/README +0 -256
  8. data/rails_3_0/Rakefile +0 -7
  9. data/rails_3_0/app/controllers/admin/appointments2_controller.rb +0 -15
  10. data/rails_3_0/app/controllers/admin/appointments_controller.rb +0 -11
  11. data/rails_3_0/app/controllers/admin/blog_posts2_controller.rb +0 -138
  12. data/rails_3_0/app/controllers/admin/blog_posts3_controller.rb +0 -76
  13. data/rails_3_0/app/controllers/admin/blog_posts4_controller.rb +0 -21
  14. data/rails_3_0/app/controllers/admin/blog_posts5_controller.rb +0 -27
  15. data/rails_3_0/app/controllers/admin/blog_posts6_controller.rb +0 -10
  16. data/rails_3_0/app/controllers/admin/blog_posts_controller.rb +0 -9
  17. data/rails_3_0/app/controllers/admin/blog_posts_custom_new_and_edit_controller.rb +0 -15
  18. data/rails_3_0/app/controllers/admin/blog_posts_read_only_controller.rb +0 -19
  19. data/rails_3_0/app/controllers/admin/bookmarks_controller.rb +0 -11
  20. data/rails_3_0/app/controllers/admin/comments2_controller.rb +0 -14
  21. data/rails_3_0/app/controllers/admin/comments_controller.rb +0 -12
  22. data/rails_3_0/app/controllers/admin/images2_controller.rb +0 -11
  23. data/rails_3_0/app/controllers/admin/images_controller.rb +0 -6
  24. data/rails_3_0/app/controllers/admin/misconfigured1_controller.rb +0 -7
  25. data/rails_3_0/app/controllers/admin/not_migrated_yets_controller.rb +0 -9
  26. data/rails_3_0/app/controllers/admin/product_categories2_controller.rb +0 -7
  27. data/rails_3_0/app/controllers/admin/product_categories_controller.rb +0 -5
  28. data/rails_3_0/app/controllers/admin/television_airings_controller.rb +0 -5
  29. data/rails_3_0/app/controllers/admin/television_time_slots_controller.rb +0 -5
  30. data/rails_3_0/app/controllers/admin/users2_controller.rb +0 -10
  31. data/rails_3_0/app/controllers/admin/users_controller.rb +0 -48
  32. data/rails_3_0/app/controllers/application_controller.rb +0 -7
  33. data/rails_3_0/app/controllers/blog_posts_controller.rb +0 -5
  34. data/rails_3_0/app/helpers/admin/appointments_helper.rb +0 -2
  35. data/rails_3_0/app/helpers/admin/blog_posts2_helper.rb +0 -27
  36. data/rails_3_0/app/helpers/admin/blog_posts3_helper.rb +0 -2
  37. data/rails_3_0/app/helpers/admin/blog_posts4_helper.rb +0 -2
  38. data/rails_3_0/app/helpers/admin/blog_posts6_helper.rb +0 -13
  39. data/rails_3_0/app/helpers/admin/blog_posts_custom_new_and_edit_helper.rb +0 -29
  40. data/rails_3_0/app/helpers/admin/blog_posts_helper.rb +0 -2
  41. data/rails_3_0/app/helpers/admin/blog_posts_read_only_helper.rb +0 -2
  42. data/rails_3_0/app/helpers/admin/bookmarks_helper.rb +0 -2
  43. data/rails_3_0/app/helpers/admin/comments2_helper.rb +0 -2
  44. data/rails_3_0/app/helpers/admin/comments_helper.rb +0 -2
  45. data/rails_3_0/app/helpers/admin/images2_helper.rb +0 -8
  46. data/rails_3_0/app/helpers/admin/images_helper.rb +0 -2
  47. data/rails_3_0/app/helpers/admin/misconfigured1_helper.rb +0 -2
  48. data/rails_3_0/app/helpers/admin/not_migrated_yets_helper.rb +0 -2
  49. data/rails_3_0/app/helpers/admin/product_categories2_helper.rb +0 -2
  50. data/rails_3_0/app/helpers/admin/product_categories_helper.rb +0 -2
  51. data/rails_3_0/app/helpers/admin/television_airings_helper.rb +0 -2
  52. data/rails_3_0/app/helpers/admin/television_time_slots_helper.rb +0 -2
  53. data/rails_3_0/app/helpers/admin/users2_helper.rb +0 -2
  54. data/rails_3_0/app/helpers/admin/users_helper.rb +0 -13
  55. data/rails_3_0/app/helpers/application_helper.rb +0 -2
  56. data/rails_3_0/app/models/appointment.rb +0 -5
  57. data/rails_3_0/app/models/blog_post.rb +0 -14
  58. data/rails_3_0/app/models/blog_post_tag.rb +0 -6
  59. data/rails_3_0/app/models/bookmark.rb +0 -6
  60. data/rails_3_0/app/models/comment.rb +0 -4
  61. data/rails_3_0/app/models/image.rb +0 -3
  62. data/rails_3_0/app/models/not_migrated_yet.rb +0 -2
  63. data/rails_3_0/app/models/product.rb +0 -5
  64. data/rails_3_0/app/models/product_category.rb +0 -9
  65. data/rails_3_0/app/models/tag.rb +0 -4
  66. data/rails_3_0/app/models/television_airing.rb +0 -3
  67. data/rails_3_0/app/models/television_time_slot.rb +0 -11
  68. data/rails_3_0/app/models/user.rb +0 -11
  69. data/rails_3_0/app/views/admin/appointments/_subject_input.html.erb +0 -2
  70. data/rails_3_0/app/views/admin/appointments2/_time_input.html.erb +0 -31
  71. data/rails_3_0/app/views/admin/blog_posts2/_after_form.html.erb +0 -5
  72. data/rails_3_0/app/views/admin/blog_posts2/_after_index.html.erb +0 -1
  73. data/rails_3_0/app/views/admin/blog_posts2/_after_tags_input.html.erb +0 -16
  74. data/rails_3_0/app/views/admin/blog_posts2/_before_index.html.erb +0 -2
  75. data/rails_3_0/app/views/admin/blog_posts5/_after_index_header.html.erb +0 -8
  76. data/rails_3_0/app/views/admin/blog_posts_read_only/_body_for_show.html.erb +0 -1
  77. data/rails_3_0/app/views/layouts/admin.html.erb +0 -32
  78. data/rails_3_0/app/views/layouts/application.html.erb +0 -14
  79. data/rails_3_0/config.ru +0 -4
  80. data/rails_3_0/config/application.rb +0 -42
  81. data/rails_3_0/config/boot.rb +0 -6
  82. data/rails_3_0/config/database.yml +0 -22
  83. data/rails_3_0/config/environment.rb +0 -5
  84. data/rails_3_0/config/environments/development.rb +0 -25
  85. data/rails_3_0/config/environments/production.rb +0 -49
  86. data/rails_3_0/config/environments/test.rb +0 -35
  87. data/rails_3_0/config/initializers/backtrace_silencers.rb +0 -7
  88. data/rails_3_0/config/initializers/inflections.rb +0 -10
  89. data/rails_3_0/config/initializers/mime_types.rb +0 -5
  90. data/rails_3_0/config/initializers/secret_token.rb +0 -7
  91. data/rails_3_0/config/initializers/session_store.rb +0 -8
  92. data/rails_3_0/config/locales/en.yml +0 -5
  93. data/rails_3_0/config/routes.rb +0 -8
  94. data/rails_3_0/db/migrate/20090213215514_create_blog_posts.rb +0 -12
  95. data/rails_3_0/db/migrate/20090217225542_add_body_to_blog_posts.rb +0 -9
  96. data/rails_3_0/db/migrate/20090221220917_create_tags.rb +0 -13
  97. data/rails_3_0/db/migrate/20090221220947_create_blog_post_tags.rb +0 -14
  98. data/rails_3_0/db/migrate/20090222162204_add_textile_to_blog_posts.rb +0 -9
  99. data/rails_3_0/db/migrate/20090222163231_add_published_at_to_blog_posts.rb +0 -9
  100. data/rails_3_0/db/migrate/20090301191722_create_images.rb +0 -16
  101. data/rails_3_0/db/migrate/20090305165345_create_accounts.rb +0 -14
  102. data/rails_3_0/db/migrate/20090307225027_rename_accounts_to_users.rb +0 -9
  103. data/rails_3_0/db/migrate/20090307225750_add_user_id_to_blog_posts.rb +0 -9
  104. data/rails_3_0/db/migrate/20090309185114_change_blog_posts_textile.rb +0 -9
  105. data/rails_3_0/db/migrate/20090309193635_create_products.rb +0 -14
  106. data/rails_3_0/db/migrate/20090309203056_create_comments.rb +0 -15
  107. data/rails_3_0/db/migrate/20090323005947_create_file_column_images.rb +0 -12
  108. data/rails_3_0/db/migrate/20090326160049_add_birthday_to_users.rb +0 -9
  109. data/rails_3_0/db/migrate/20090326223606_add_state_to_users.rb +0 -9
  110. data/rails_3_0/db/migrate/20090503134004_add_file_column_image_to_products.rb +0 -9
  111. data/rails_3_0/db/migrate/20090617173651_create_bookmarks.rb +0 -15
  112. data/rails_3_0/db/migrate/20090624165355_add_tags_string_to_blog_post.rb +0 -9
  113. data/rails_3_0/db/migrate/20090625144313_add_avatar_fields_to_user.rb +0 -11
  114. data/rails_3_0/db/migrate/20090629202956_add_merged_into_to_blog_posts.rb +0 -9
  115. data/rails_3_0/db/migrate/20090701171857_add_force_textile_to_users.rb +0 -9
  116. data/rails_3_0/db/migrate/20090704163647_add_deleted_at_to_products.rb +0 -9
  117. data/rails_3_0/db/migrate/20090704173800_add_sale_fields_to_products.rb +0 -13
  118. data/rails_3_0/db/migrate/20090714024501_create_product_categories.rb +0 -15
  119. data/rails_3_0/db/migrate/20090819162835_add_admin_level_to_users.rb +0 -9
  120. data/rails_3_0/db/migrate/20091115134559_add_first_and_last_names_to_users.rb +0 -11
  121. data/rails_3_0/db/migrate/20091221011256_add_position_to_product_categories.rb +0 -9
  122. data/rails_3_0/db/migrate/20091222160814_create_appointments.rb +0 -14
  123. data/rails_3_0/db/migrate/20091227224547_add_user_id_to_appointments.rb +0 -9
  124. data/rails_3_0/db/migrate/20100214213359_create_television_time_slots.rb +0 -13
  125. data/rails_3_0/db/migrate/20100214213451_create_television_airings.rb +0 -15
  126. data/rails_3_0/db/migrate/20110426215702_remove_avatar_fields_from_users.rb +0 -11
  127. data/rails_3_0/db/seeds.rb +0 -7
  128. data/rails_3_0/doc/README_FOR_APP +0 -2
  129. data/rails_3_0/public/404.html +0 -26
  130. data/rails_3_0/public/422.html +0 -26
  131. data/rails_3_0/public/500.html +0 -26
  132. data/rails_3_0/public/favicon.ico +0 -0
  133. data/rails_3_0/public/images/rails.png +0 -0
  134. data/rails_3_0/public/index.html +0 -239
  135. data/rails_3_0/public/javascripts/application.js +0 -2
  136. data/rails_3_0/public/javascripts/jquery-1.4.4.min.js +0 -167
  137. data/rails_3_0/public/javascripts/rails.js +0 -191
  138. data/rails_3_0/public/robots.txt +0 -5
  139. data/rails_3_0/public/stylesheets/admin.css +0 -3
  140. data/rails_3_0/public/stylesheets/scaffold.css +0 -54
  141. data/rails_3_0/script/rails +0 -6
  142. data/rails_3_0/test/data/ruby_throated.jpg +0 -0
  143. data/rails_3_0/test/data/tweenbot.jpg +0 -0
  144. data/rails_3_0/test/fixtures/placeholder.txt +0 -0
  145. data/rails_3_0/test/integration/admin/appointments2_integration_test.rb +0 -79
  146. data/rails_3_0/test/integration/admin/appointments_integration_test.rb +0 -367
  147. data/rails_3_0/test/integration/admin/blog_posts2_integration_test.rb +0 -789
  148. data/rails_3_0/test/integration/admin/blog_posts3_integration_test.rb +0 -418
  149. data/rails_3_0/test/integration/admin/blog_posts4_integration_test.rb +0 -189
  150. data/rails_3_0/test/integration/admin/blog_posts5_integration_test.rb +0 -75
  151. data/rails_3_0/test/integration/admin/blog_posts6_integration_test.rb +0 -39
  152. data/rails_3_0/test/integration/admin/blog_posts_custom_new_and_edit_integration_test.rb +0 -89
  153. data/rails_3_0/test/integration/admin/blog_posts_integration_test.rb +0 -776
  154. data/rails_3_0/test/integration/admin/blog_posts_read_only_integration_test.rb +0 -69
  155. data/rails_3_0/test/integration/admin/bookmarks_integration_test.rb +0 -445
  156. data/rails_3_0/test/integration/admin/comments2_integration_test.rb +0 -52
  157. data/rails_3_0/test/integration/admin/comments_integration_test.rb +0 -50
  158. data/rails_3_0/test/integration/admin/images2_integration_test.rb +0 -33
  159. data/rails_3_0/test/integration/admin/images_integration_test.rb +0 -79
  160. data/rails_3_0/test/integration/admin/misconfigured1_integration_test.rb +0 -21
  161. data/rails_3_0/test/integration/admin/product_categories2_integration_test.rb +0 -179
  162. data/rails_3_0/test/integration/admin/product_categories_integration_test.rb +0 -12
  163. data/rails_3_0/test/integration/admin/television_airings_integration_test.rb +0 -25
  164. data/rails_3_0/test/integration/admin/users2_integration_test.rb +0 -48
  165. data/rails_3_0/test/integration/admin/users_integration_test.rb +0 -182
  166. data/rails_3_0/test/integration/blog_posts_integration_test.rb +0 -10
  167. data/rails_3_0/test/performance/browsing_test.rb +0 -9
  168. data/rails_3_0/test/test_helper.rb +0 -138
  169. data/rails_3_1/Gemfile +0 -12
  170. data/rails_3_1/Gemfile.lock +0 -116
  171. data/rails_3_1/README +0 -256
  172. data/rails_3_1/Rakefile +0 -7
  173. data/rails_3_1/config.ru +0 -4
@@ -1,789 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../../test_helper")
2
-
3
- class Admin::BlogPosts2IntegrationTest < ActionController::IntegrationTest
4
- def setup
5
- User.destroy_all
6
- @user = User.find_or_create_by_username 'soren'
7
- end
8
-
9
- def create_foobar_blog_posts
10
- BlogPost.destroy_all
11
- BlogPost.create!(
12
- :title => 'textile_false_foobar', :textile => false, :user => @user
13
- )
14
- BlogPost.create!(
15
- :title => 'textile_true_foobar', :textile => true, :user => @user
16
- )
17
- BlogPost.create!(
18
- :title => 'not_in_the_title', :textile => false,
19
- :body => 'foobar here though', :user => @user
20
- )
21
- BlogPost.create!(
22
- :title => 'textile is false', :textile => false,
23
- :body => "body doesn't say f**bar", :user => @user
24
- )
25
- BlogPost.create!(
26
- :title => 'already published', :textile => false,
27
- :body => "body doesn't say f**bar", :user => @user,
28
- :published_at => Time.now.utc
29
- )
30
- end
31
-
32
- def test_comes_back_to_index_sorted_by_published_at_after_preview_then_create
33
- BlogPost.create! :title => random_word, :user => @user
34
- visit "/admin/blog_posts2"
35
- click_link "Published at"
36
- click_link "New blog post"
37
- fill_in "blog_post[title]", :with => 'Funny ha ha'
38
- select "soren", :from => "blog_post[user_id]"
39
- click_button 'Preview'
40
- click_button 'Update'
41
- assert_select 'th.asc', :text => 'Published at'
42
- end
43
-
44
- def test_create_when_there_are_no_validation_errors
45
- title = random_word
46
- post(
47
- "/admin/blog_posts2",
48
- :blog_post => {
49
- :title => title, :tags => 'tag1 tag2', :publish => '1',
50
- :user_id => @user.id
51
- }
52
- )
53
- @blog_post = BlogPost.find_by_title title
54
-
55
- # should create a new BlogPost
56
- assert @blog_post
57
-
58
- # should create tags
59
- assert_equal(2, @blog_post.tags.size)
60
- %w(tag1 tag2).each do |tag_str|
61
- assert(@blog_post.tags.any? { |tag| tag.tag == tag_str })
62
- end
63
-
64
- # should set published_at because of the publish flag
65
- assert @blog_post.published_at
66
-
67
- # should set the tags_string
68
- assert_match(/tag1,tag2/, @blog_post.tags_string)
69
- end
70
-
71
- def test_create_when_the_user_has_clicked_Preview
72
- title = random_word
73
- post(
74
- "/admin/blog_posts2",
75
- :blog_post => {
76
- :title => title, :tags => 'tag1 tag2', :publish => '1',
77
- :user_id => @user.id
78
- },
79
- :commit => 'Preview'
80
- )
81
- @blog_post = BlogPost.find_by_title title
82
-
83
- # should redirect to the edit page with the preview flag
84
- assert_redirected_to(
85
- "/admin/blog_posts2/#{@blog_post.id}/edit?preview=1"
86
- )
87
- end
88
-
89
- def test_create_with_a_bad_tag
90
- @title = random_word
91
- post(
92
- "/admin/blog_posts2",
93
- :blog_post => {
94
- :title => @title, :tags => 'foo bar! baz', :user_id => @user.id
95
- }
96
- )
97
-
98
- # should not create a new BlogPost
99
- assert_nil BlogPost.find_by_title(@title)
100
-
101
- # should keep the title in the form
102
- assert_select(
103
- "input[name=?][value=?]", 'blog_post[title]', @title
104
- )
105
-
106
- # should render a useful error
107
- assert_select("div.errorExplanation") do
108
- assert_select 'li', :text => "Tags contain invalid string 'bar!'"
109
- end
110
-
111
- # should highlight the tag string entry
112
- assert_select("div.field_with_errors") do
113
- assert_select "input[name=?][value=?]", "blog_post[tags]", "foo bar! baz"
114
- end
115
- end
116
-
117
- def test_create_with_a_bad_tag_and_a_missing_title
118
- @orig_count = BlogPost.count
119
- post(
120
- "/admin/blog_posts2",
121
- :blog_post => {
122
- :title => '', :tags => 'foo bar! baz', :user_id => @user.id
123
- }
124
- )
125
-
126
- # should not create a new BlogPost
127
- assert_equal(@orig_count, BlogPost.count)
128
-
129
- # should render a useful tags error
130
- assert_select("div.errorExplanation") do
131
- assert_select 'li', :text => "Tags contain invalid string 'bar!'"
132
- end
133
-
134
- # should highlight the tag string entry
135
- assert_select("div.field_with_errors") do
136
- assert_select "input[name=?][value=?]", "blog_post[tags]", "foo bar! baz"
137
- end
138
-
139
- # should render a useful title error
140
- assert_select("div.errorExplanation") do
141
- assert_select 'li', :text => "Title can't be blank"
142
- end
143
-
144
- # should highlight the title string entry
145
- assert_select("div.field_with_errors") do
146
- assert_select "input[name=?][value=?]", "blog_post[title]", ""
147
- end
148
- end
149
-
150
- def test_create_with_a_bad_publish_value_somehow
151
- @title = random_word
152
- post(
153
- "/admin/blog_posts2",
154
- :blog_post => {
155
- :title => @title, :tags => 'tag1 tag2', :publish => 'FOOBAR',
156
- }
157
- )
158
-
159
- # should be successful
160
- assert_response :success
161
-
162
- # should not save the blog post
163
- assert_nil BlogPost.find_by_title(@title)
164
-
165
- # should display the publish error
166
- assert_match(/Publish can't be .*FOOBAR.*/, response.body)
167
-
168
- # should display a user error too
169
- assert_match(/User can't be blank/, response.body)
170
- end
171
-
172
- def test_edit
173
- BlogPost.destroy_all
174
- @blog_post = BlogPost.create!(
175
- :title => "blog post title", :body => 'blog post body', :user => @user
176
- )
177
- tag1 = Tag.find_or_create_by_tag 'tag1'
178
- BlogPostTag.create! :blog_post => @blog_post, :tag => tag1
179
- tag2 = Tag.find_or_create_by_tag 'tag2'
180
- BlogPostTag.create! :blog_post => @blog_post, :tag => tag2
181
- get "/admin/blog_posts2/#{@blog_post.id}/edit"
182
- assert_response :success
183
-
184
- # should show the tags
185
- assert_match(%r|<input.*name="blog_post\[tags\]"|m, response.body)
186
- assert_match(/(tag2 tag1|tag1 tag2)/, response.body)
187
-
188
- # should show a preview button
189
- assert_select('input[type=submit][value=Preview]')
190
- end
191
-
192
- def test_edit_in_preview_mode
193
- @blog_post = BlogPost.create!(
194
- :title => "blog post title", :body => 'blog post body', :user => @user
195
- )
196
- get "/admin/blog_posts2/#{@blog_post.id}/edit?preview=1"
197
- assert_response :success
198
-
199
- # should render the preview HTML
200
- assert_select('html') do
201
- assert_select 'h4', 'Preview'
202
- end
203
- end
204
-
205
- def test_edit_when_there_are_more_than_15_users
206
- @blog_post = BlogPost.create! :title => random_word, :user => @user
207
- 1.upto(16) do |i|
208
- User.create! :username => "--user #{i}--"
209
- end
210
- get "/admin/blog_posts2/#{@blog_post.id}/edit"
211
-
212
- # should use the token input instead of a drop-down
213
- assert_select("select[name=?]", "blog_post[user_id]", false)
214
- assert_select("input[name=?][value=?]", 'blog_post[user_id]', @user.id)
215
- assert_match(
216
- %r|
217
- \$\("\#blog_post_user_id"\)\.tokenInput\(
218
- \s*"/admin/blog_posts2/autocomplete_user",
219
- .*prePopulate
220
- .*"id":\s*#{@user.id}
221
- |mx,
222
- response.body
223
- )
224
- end
225
-
226
- def test_edit_when_there_are_less_than_15_users
227
- @blog_post = BlogPost.create! :title => random_word, :user => @user
228
- User.count.downto(14) do
229
- user = User.find(
230
- :first, :conditions => ['username != ?', @user.username]
231
- )
232
- user.destroy
233
- end
234
- get "/admin/blog_posts2/#{@blog_post.id}/edit"
235
-
236
- # should use a drop-down without a blank option
237
- assert_select('select[name=?]', 'blog_post[user_id]') do
238
- assert_select("option[value='']", false)
239
- end
240
- end
241
-
242
- def test_edit_a_blog_post_that_has_already_been_published
243
- @blog_post = BlogPost.create!(
244
- :title => "blog post title", :body => 'blog post body', :user => @user,
245
- :published_at => Time.now.utc
246
- )
247
- get "/admin/blog_posts2/#{@blog_post.id}/edit"
248
- assert_response :success
249
-
250
- # should show the publish check-box checked
251
- assert_select(
252
- 'input[type=checkbox][name=?][checked=checked]', 'blog_post[publish]'
253
- )
254
- end
255
-
256
- def test_index_when_there_is_one_record_and_15_or_less_users
257
- BlogPost.destroy_all
258
- @blog_post = BlogPost.create!(
259
- :title => "blog post title", :body => 'blog post body',
260
- :user => @user
261
- )
262
- tag1 = Tag.find_or_create_by_tag 'tag1'
263
- BlogPostTag.create! :blog_post => @blog_post, :tag => tag1
264
- tag2 = Tag.find_or_create_by_tag 'tag2'
265
- BlogPostTag.create! :blog_post => @blog_post, :tag => tag2
266
- User.count.downto(15) do
267
- user = User.find(:first, :conditions => ['id != ?', @user.id])
268
- user.destroy
269
- end
270
- get "/admin/blog_posts2"
271
- assert_response :success
272
-
273
- # should show the tags
274
- assert_match(/(tag2 tag1|tag1 tag2)/, response.body)
275
-
276
- # should show the title
277
- assert_match(/blog post title/, response.body)
278
-
279
- # should not show the body
280
- assert_no_match(/blog post body/, response.body)
281
-
282
- # should show a link to the all index page
283
- assert_match(%r|<a.*href="/admin/blog_posts2\?all=1"|, response.body)
284
-
285
- # should not show a sort link for tags
286
- assert_no_match(%r|<a [^>]*>Tags</a>|, response.body)
287
-
288
- # should show a sort link for users
289
- assert_a_tag_with_get_args(
290
- 'Author', '/admin/blog_posts2',
291
- {:sort => 'user', :sort_order => 'asc'}, response.body
292
- )
293
-
294
- # should render the author as a username with a link
295
- assert_select('td') do
296
- assert_select(
297
- "a[href=?]", "/admin/users/#{@user.id}/edit", :text => 'soren'
298
- )
299
- end
300
-
301
- # should say 'Yes' or 'No' for the textile field
302
- assert_match(/No/, response.body)
303
-
304
- # should show a search form with specific fields
305
- assert_select(
306
- 'form[id=search_form][method=get]', :text => /Title/
307
- ) do
308
- assert_select(
309
- 'input[type=radio][name=?][value=all][checked=checked]',
310
- 'search[(all_or_any)]'
311
- )
312
- assert_select(
313
- 'input[type=radio][name=?][value=any]', 'search[(all_or_any)]'
314
- )
315
- assert_select('input[name=?]', 'search[title]')
316
- assert_select('input[name=?]', 'search[body]')
317
- assert_select('select[name=?]', 'search[textile]') do
318
- assert_select("option[value='']", :text => '')
319
- assert_select("option[value='true']", :text => 'Yes')
320
- assert_select("option[value='false']", :text => 'No')
321
- end
322
- assert_select('select[name=?]', 'search[user_id]') do
323
- assert_select("option[value='']", :text => '')
324
- assert_select("option[value=?]", @user.id)
325
- end
326
- end
327
-
328
- # should show a link to /admin/comments/new
329
- assert_select('td') do
330
- assert_select(
331
- "a[href=?]",
332
- "/admin/comments/new?comment[blog_post_id]=#{@blog_post.id}",
333
- :text => "New comment"
334
- )
335
- end
336
-
337
- # should have a header of 'Blog posts (unpublished)'
338
- assert_select('h2', :text => 'Blog posts (unpublished)')
339
-
340
- # should render custom HTML after the index
341
- assert_select(
342
- '#after_index', :text => 'Custom HTML rendered after the index'
343
- )
344
-
345
- # should render custom HTML before the index
346
- assert_select(
347
- '#before_index', :text => 'Custom HTML rendered before the index'
348
- )
349
-
350
- # should not have a blank checkbox for the body search field
351
- assert_select('form[id=search_form][method=get]') do
352
- assert_select(
353
- "input[type=checkbox][name=?]", "search[body(blank)]", false
354
- )
355
- end
356
-
357
- # should output ivar set by index_before_render controller hook
358
- assert assigns(:var_set_by_before_render_for_index_hook)
359
- assert_match(/Confirmed that we have some records/, response.body)
360
- end
361
-
362
- def test_index_when_there_is_one_published_post_and_one_unpublished_post
363
- BlogPost.create! :title => "--unpublished--", :user => @user
364
- BlogPost.create!(
365
- :title => "--published--", :published_at => Time.now.utc,
366
- :user => @user
367
- )
368
- get "/admin/blog_posts2"
369
- assert_response :success
370
-
371
- # should show the unpublished post
372
- assert_match(/--unpublished--/, response.body)
373
-
374
- # should not show the published post
375
- assert_no_match(/--published--/, response.body)
376
- end
377
-
378
- def test_index_when_there_is_1_blog_post_and_16_users
379
- @blog_post = BlogPost.create! :title => random_word, :user => @user
380
- User.count.upto(16) do |i|
381
- User.create! :username => random_word
382
- end
383
- get "/admin/blog_posts2"
384
-
385
- # should use the token input in the search form for users
386
- assert_select("select[name=?]", "search[user_id]]", false)
387
- assert_select("input:not([value])[name=?]", 'search[user_id]')
388
- assert_match(
389
- %r|
390
- \$\("\#search_user_id"\)\.tokenInput\(
391
- \s*"/admin/blog_posts2/autocomplete_user"
392
- |mx,
393
- response.body
394
- )
395
- end
396
-
397
- def test_index_all_1
398
- BlogPost.create!(
399
- :title => "--published--", :published_at => Time.now.utc,
400
- :user => @user
401
- )
402
- get "/admin/blog_posts2", :all => '1'
403
- assert_response :success
404
-
405
- # should show published posts
406
- assert_match(/--published--/, response.body)
407
-
408
- # should show a sort link for titles that includes all=1
409
- assert_a_tag_with_get_args(
410
- 'Title', '/admin/blog_posts2',
411
- {:sort => 'title', :sort_order => 'asc', :all => '1'}, response.body
412
- )
413
-
414
- # should have a header of 'Blog posts (all)'
415
- assert_select('h2', :text => 'Blog posts (all)')
416
- end
417
-
418
- def test_index_all_1_with_two_published_posts
419
- BlogPost.create!(
420
- :title => 'published later', :published_at => Time.utc(2009, 2, 1),
421
- :user => @user
422
- )
423
- BlogPost.create!(
424
- :title => 'published earlier', :published_at => Time.utc(2009, 1, 1),
425
- :user => @user
426
- )
427
- get "/admin/blog_posts2", :all => '1'
428
-
429
- # should order by published_at desc
430
- assert_match(/published later.*published earlier/m, response.body)
431
- end
432
-
433
- def test_index_when_searching_for_title_with_foobar
434
- create_foobar_blog_posts
435
- get(
436
- "/admin/blog_posts2",
437
- :search => {
438
- :body => "", :title => "foobar", :textile => "", :id => "",
439
- :user => ''
440
- }
441
- )
442
- assert_response :success
443
-
444
- # should match records where textile=true
445
- assert_select('td', :text => 'textile_true_foobar')
446
-
447
- # should match records where textile=false
448
- assert_select('td', :text => 'textile_false_foobar')
449
-
450
- # should show the textile and title search fields pre-set
451
- assert_select('form[id=search_form][method=get]') do
452
- assert_select('input[name=?][value=foobar]', 'search[title]')
453
- assert_select('select[name=?]', 'search[textile]') do
454
- assert_select("option[value='']", :text => '')
455
- assert_select("option:not(selected)[value='true']", :text => 'Yes')
456
- assert_select("option:not(selected)[value='false']", :text => 'No')
457
- end
458
- end
459
- end
460
-
461
- def test_index_when_searching_for_title_with_foobar_and_textile_false
462
- create_foobar_blog_posts
463
- get(
464
- "/admin/blog_posts2",
465
- :search => {
466
- :textile => 'false', :title => 'foobar', '(all_or_any)' => 'all',
467
- :user => ''
468
- }
469
- )
470
- assert_response :success
471
-
472
- # should show blog posts with textile=false and the word 'foobar' in the title
473
- assert_select('td', :text => 'textile_false_foobar')
474
-
475
- # should not show a blog post with textile=true
476
- assert_no_match(%r|<td[^>]*>textile_true_foobar</td>|, response.body)
477
-
478
- # should not show a blog post just 'cause it has 'foobar' in the body
479
- assert_no_match(%r|<td[^>]*>not_in_the_title</td>|, response.body)
480
-
481
- # should show the textile, title, and all-or-any search fields pre-set
482
- assert_select('form[id=search_form][method=get]') do
483
- assert_select(
484
- 'input[type=radio][name=?][value=all][checked=checked]',
485
- 'search[(all_or_any)]'
486
- )
487
- assert_select('input[name=?][value=foobar]', 'search[title]')
488
- assert_select('select[name=?]', 'search[textile]') do
489
- assert_select("option[value='']", :text => '')
490
- assert_select("option[value='true']", :text => 'Yes')
491
- assert_select("option[value='false'][selected=selected]", :text => 'No')
492
- end
493
- end
494
- end
495
-
496
- def test_index_for_title_with_foobar_and_textile_false
497
- create_foobar_blog_posts
498
- get(
499
- "/admin/blog_posts2",
500
- :search => {
501
- :textile => 'false', :title => 'foobar', '(all_or_any)' => 'any',
502
- :user => ''
503
- }
504
- )
505
- assert_response :success
506
-
507
- # should show a blog post with 'foobar' in the title
508
- assert_select('td', :text => 'textile_true_foobar')
509
-
510
- # should show a blog post with textile=false
511
- assert_select('td', :text => 'textile is false')
512
-
513
- # should not show a blog post that's already published, because of the conditions set in controller
514
- assert_no_match(%r|<td[^>]*>already published</td>|, response.body)
515
-
516
- # should show the textile, title, and all-or-any search fields pre-set
517
- assert_select('form[id=search_form][method=get]') do
518
- assert_select(
519
- 'input[type=radio][name=?][value=any][checked=checked]',
520
- 'search[(all_or_any)]'
521
- )
522
- assert_select('input[name=?][value=foobar]', 'search[title]')
523
- assert_select('select[name=?]', 'search[textile]') do
524
- assert_select("option[value='']", :text => '')
525
- assert_select("option[value='true']", :text => 'Yes')
526
- assert_select("option[value='false'][selected=selected]", :text => 'No')
527
- end
528
- end
529
- end
530
-
531
- def test_index_when_searching_by_user_and_there_are_less_than_15_users
532
- @user2 = User.create! :username => 'Jean-Paul'
533
- User.count.downto(14) do
534
- user = User.find(
535
- :first,
536
- :conditions => [
537
- 'username != ? and username != ?', @user.username, @user.username
538
- ]
539
- )
540
- user.destroy
541
- end
542
- BlogPost.destroy_all
543
- BlogPost.create! :title => "Soren's first post", :user => @user
544
- BlogPost.create! :title => "Soren's second post", :user => @user
545
- BlogPost.create! :title => "Jean-Paul's post", :user => @user2
546
- get(
547
- "/admin/blog_posts2",
548
- :search => {:textile => '', :title => '', :user_id => @user2.id.to_s}
549
- )
550
- assert_response :success
551
-
552
- # should show blog posts by Jean-Paul
553
- assert_select('td', :text => "Jean-Paul's post")
554
-
555
- # should not show blog posts by Soren
556
- assert_no_match(%r|<td[^>]*>Soren's first post</td>|, response.body)
557
- assert_no_match(%r|<td[^>]*>Soren's second post</td>|, response.body)
558
-
559
- # should show the user field pre-set
560
- assert_select(
561
- 'form[id=search_form][method=get]', :text => /Title/
562
- ) do
563
- assert_select('select[name=?]', 'search[user_id]') do
564
- assert_select("option[value='']", :text => '')
565
- assert_select("option[value=?][selected=selected]", @user2.id)
566
- end
567
- end
568
- end
569
-
570
- def test_index_when_searching_by_user_and_there_are_more_than_15_users
571
- @blog_post = BlogPost.create! :title => random_word, :user => @user
572
- User.count.upto(16) do |i|
573
- User.create! :username => "--user #{i}--"
574
- end
575
- get(
576
- "/admin/blog_posts2",
577
- :search => {:textile => '', :title => '', :user_id => @user.id.to_s}
578
- )
579
- assert_response :success
580
-
581
- # should show pre-populated user token input in the search form
582
- assert_select("select[name=?]", "search[user_id]]", false)
583
- assert_select("input[name=?][value=?]", 'search[user_id]', @user.id)
584
- assert_match(
585
- %r|
586
- \$\("\#search_user_id"\)\.tokenInput\(
587
- \s*"/admin/blog_posts2/autocomplete_user",
588
- .*prePopulate
589
- .*"id":\s*#{@user.id}
590
- |mx,
591
- response.body
592
- )
593
- end
594
-
595
- def test_index_with_a_blank_search
596
- get(
597
- "/admin/blog_posts2",
598
- :search => {
599
- :body => '', :title => '', :textile => '', :id => '', :user_id => '',
600
- '(all_or_any)' => 'all', 'id(comparator)' => ''
601
- }
602
- )
603
-
604
- # should be successful
605
- assert_response :success
606
- end
607
-
608
- def test_index_with_one_record_with_a_false_textile_field
609
- BlogPost.destroy_all
610
- @blog_post = BlogPost.create!(
611
- :title => random_word, :user => @user, :textile => false
612
- )
613
- get "/admin/blog_posts2"
614
-
615
- # should make the textile field an Ajax toggle
616
- toggle_div_id = "blog_post_#{@blog_post.id}_textile"
617
- post_url =
618
- "/admin/blog_posts2/#{@blog_post.id}?" +
619
- 'blog_post[textile]' + "=1&amp;from=#{toggle_div_id}"
620
- assert_select("div[id=?]", toggle_div_id) do
621
- assert_select("a.toggle[href=?]", post_url, :text => 'No')
622
- end
623
- end
624
-
625
- def test_index_with_11_blog_posts
626
- BlogPost.destroy_all
627
- 1.upto(11) do |i|
628
- BlogPost.create!(
629
- :title => "--post #{i}--", :user => @user
630
- )
631
- end
632
- get "/admin/blog_posts2"
633
-
634
- # should show link to page 2
635
- assert_will_paginate_link("/admin/blog_posts2", 2)
636
-
637
- # should say 11 blog posts found
638
- assert_match(/11 blog posts found/, response.body)
639
-
640
- # should mark the table rows with custom CSS class
641
- assert_select('tr[class~="custom_tr_css_class"]')
642
-
643
- # should mark the user cells with custom CSS class
644
- assert_select('td[class~="custom_td_css_class"]', :text => @user.username)
645
- end
646
-
647
- def test_new
648
- Tag.find_or_create_by_tag 'tag_from_yesterday'
649
- get "/admin/blog_posts2/new"
650
-
651
- # should show a field for tags
652
- assert_match(%r|<input.*name="blog_post\[tags\]"|m, response.body)
653
-
654
- # should show current tags
655
- assert_match(/tag_from_yesterday/, response.body)
656
-
657
- # should show a checkbox for the 'publish' virtual field
658
- assert_match(
659
- %r!
660
- <input[^>]*
661
- (name="blog_post\[publish\][^>]*type="hidden"[^>]value="0"|
662
- type="hidden"[^>]*name="blog_post\[publish\][^>]value="0")
663
- .*
664
- <input[^>]*
665
- (name="blog_post\[publish\][^>]*type="checkbox"[^>]value="1"|
666
- type="checkbox"[^>]*name="blog_post\[publish\][^>]value="1")
667
- !x,
668
- response.body
669
- )
670
-
671
- # should not duplicate the DOM ID of the 'publish' checkbox on the page
672
- assert_equal(
673
- 1,
674
- response.body.scan(
675
- /id="blog_post_publish"|id="blog_post\[publish\]"/
676
- ).size
677
- )
678
-
679
- # should show the description for the 'publish' virtual field
680
- assert_match(
681
- /Click this and published_at will be set automatically/,
682
- response.body
683
- )
684
-
685
- # should show a preview button
686
- assert_select('input[type=submit][value=Preview]')
687
-
688
- # should use a textarea for the body field
689
- assert_select(
690
- 'textarea[name=?][cols=20][rows=40]', 'blog_post[body]'
691
- )
692
-
693
- # should use a checkbox for the boolean field 'textile'
694
- assert_match(
695
- %r!
696
- <input[^>]*
697
- (name="blog_post\[textile\][^>]*type="checkbox"|
698
- type="checkbox"[^>]*name="blog_post\[textile\])
699
- !x,
700
- response.body
701
- )
702
-
703
- # should say 'Author' instead of 'User'
704
- assert_match(/Author/, response.body)
705
- end
706
-
707
- def test_show
708
- @blog_post = BlogPost.create! :title => random_word, :user => @user
709
- get "/admin/blog_posts2/#{@blog_post.id}"
710
- assert_response :success
711
-
712
- # should show user
713
- assert_match(/soren/, response.body)
714
-
715
- # should not show created at
716
- assert_no_match(/Created at/, response.body)
717
- end
718
-
719
- def test_update_when_there_are_no_validation_errors
720
- @blog_post = BlogPost.create! :title => random_word, :user => @user
721
- put(
722
- "/admin/blog_posts2/#{@blog_post.id}",
723
- :blog_post => {:tags => 'tag1 tag2 tag3'}
724
- )
725
-
726
- # should set the tags_string
727
- @blog_post.reload
728
- assert_match(/tag1,tag2,tag3/, @blog_post.tags_string)
729
- end
730
-
731
- def test_update_when_the_user_has_clicked_Preview
732
- @blog_post = BlogPost.create! :title => random_word, :user => @user
733
- title2 = random_word
734
- put(
735
- "/admin/blog_posts2/#{@blog_post.id}",
736
- :blog_post => {:title => title2},
737
- :commit => 'Preview'
738
- )
739
-
740
- # should redirect to the edit page with the preview flag
741
- assert_redirected_to("/admin/blog_posts2/#{@blog_post.id}/edit?preview=1")
742
- end
743
-
744
- def test_update_with_a_bad_tag
745
- @blog_post = BlogPost.create! :title => random_word, :user => @user
746
- put(
747
- "/admin/blog_posts2/#{@blog_post.id}",
748
- :blog_post => {:tags => "foo bar! baz"}
749
- )
750
-
751
- # should render a useful error
752
- assert_select("div.errorExplanation") do
753
- assert_select 'li', :text => "Tags contain invalid string 'bar!'"
754
- end
755
-
756
- # should highlight the tag string entry
757
- assert_select("div.field_with_errors") do
758
- assert_select "input[name=?][value=?]", "blog_post[tags]", "foo bar! baz"
759
- end
760
- end
761
-
762
- def test_update_with_a_bad_tag_and_a_missing_title
763
- @blog_post = BlogPost.create! :title => random_word, :user => @user
764
- put(
765
- "/admin/blog_posts2/#{@blog_post.id}",
766
- :blog_post => {:tags => "foo bar! baz", :title => ''}
767
- )
768
-
769
- # should render a useful tags error
770
- assert_select("div.errorExplanation") do
771
- assert_select 'li', :text => "Tags contain invalid string 'bar!'"
772
- end
773
-
774
- # should highlight the tag string entry
775
- assert_select("div.field_with_errors") do
776
- assert_select "input[name=?][value=?]", "blog_post[tags]", "foo bar! baz"
777
- end
778
-
779
- # should render a useful title error
780
- assert_select("div.errorExplanation") do
781
- assert_select 'li', :text => "Title can't be blank"
782
- end
783
-
784
- # should highlight the title string entry
785
- assert_select("div.field_with_errors") do
786
- assert_select "input[name=?][value=?]", "blog_post[title]", ""
787
- end
788
- end
789
- end