open_porch 0.5.0

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 (223) hide show
  1. data/Gemfile +41 -0
  2. data/Gemfile.lock +130 -0
  3. data/README.md +170 -0
  4. data/Rakefile +19 -0
  5. data/VERSION +1 -0
  6. data/app/controllers/admin/areas/base_controller.rb +11 -0
  7. data/app/controllers/admin/areas/issues_controller.rb +67 -0
  8. data/app/controllers/admin/areas/memberships_controller.rb +7 -0
  9. data/app/controllers/admin/areas/posts_controller.rb +44 -0
  10. data/app/controllers/admin/areas_controller.rb +89 -0
  11. data/app/controllers/admin/base_controller.rb +16 -0
  12. data/app/controllers/admin/user_activity_controller.rb +29 -0
  13. data/app/controllers/admin/users_controller.rb +57 -0
  14. data/app/controllers/application_controller.rb +15 -0
  15. data/app/controllers/areas/base_controller.rb +25 -0
  16. data/app/controllers/areas/issues_controller.rb +35 -0
  17. data/app/controllers/areas/posts_controller.rb +28 -0
  18. data/app/controllers/areas_controller.rb +30 -0
  19. data/app/controllers/passwords_controller.rb +42 -0
  20. data/app/controllers/registrations_controller.rb +42 -0
  21. data/app/controllers/sessions_controller.rb +33 -0
  22. data/app/controllers/users_controller.rb +77 -0
  23. data/app/helpers/open_porch_helper.rb +24 -0
  24. data/app/mailers/user_mailer.rb +35 -0
  25. data/app/models/address.rb +57 -0
  26. data/app/models/area.rb +171 -0
  27. data/app/models/area_activity.rb +24 -0
  28. data/app/models/email_message.rb +104 -0
  29. data/app/models/issue.rb +66 -0
  30. data/app/models/issue_number.rb +22 -0
  31. data/app/models/membership.rb +27 -0
  32. data/app/models/post.rb +64 -0
  33. data/app/models/session_user.rb +69 -0
  34. data/app/models/user.rb +140 -0
  35. data/app/models/user_activity.rb +31 -0
  36. data/app/models/user_authority_check.rb +14 -0
  37. data/app/views/admin/areas/_form.html.haml +8 -0
  38. data/app/views/admin/areas/_nav.html.haml +12 -0
  39. data/app/views/admin/areas/edit.html.haml +22 -0
  40. data/app/views/admin/areas/edit_borders.html.haml +44 -0
  41. data/app/views/admin/areas/index.html.haml +61 -0
  42. data/app/views/admin/areas/issues/_post.html.haml +15 -0
  43. data/app/views/admin/areas/issues/add_posts.js.rjs +3 -0
  44. data/app/views/admin/areas/issues/edit.html.haml +37 -0
  45. data/app/views/admin/areas/issues/index.html.haml +31 -0
  46. data/app/views/admin/areas/issues/remove_posts.js.rjs +3 -0
  47. data/app/views/admin/areas/issues/show.html.haml +13 -0
  48. data/app/views/admin/areas/memberships/index.html.haml +17 -0
  49. data/app/views/admin/areas/new.html.haml +6 -0
  50. data/app/views/admin/areas/new.js.haml +4 -0
  51. data/app/views/admin/areas/posts/_edit.html.haml +6 -0
  52. data/app/views/admin/areas/posts/_post_status.html.haml +1 -0
  53. data/app/views/admin/areas/posts/destroy.js.rjs +1 -0
  54. data/app/views/admin/areas/posts/edit.js.rjs +1 -0
  55. data/app/views/admin/areas/posts/show.js.rjs +1 -0
  56. data/app/views/admin/areas/posts/toggle_reviewed_by.js.rjs +1 -0
  57. data/app/views/admin/areas/posts/update.js.rjs +5 -0
  58. data/app/views/admin/areas/show.html.haml +5 -0
  59. data/app/views/admin/user_activity/show.html.haml +5 -0
  60. data/app/views/admin/users/_form.html.haml +21 -0
  61. data/app/views/admin/users/edit.html.haml +5 -0
  62. data/app/views/admin/users/index.html.haml +31 -0
  63. data/app/views/admin/users/new.html.haml +5 -0
  64. data/app/views/areas/issues/index.html.haml +31 -0
  65. data/app/views/areas/issues/show.html.haml +22 -0
  66. data/app/views/areas/posts/_post.html.haml +8 -0
  67. data/app/views/areas/posts/_posts_search_form.html.haml +8 -0
  68. data/app/views/areas/posts/index.html.haml +27 -0
  69. data/app/views/areas/posts/new.html.haml +10 -0
  70. data/app/views/areas/show.html.haml +47 -0
  71. data/app/views/layouts/_account_nav.html.haml +18 -0
  72. data/app/views/layouts/_flash_message.html.haml +4 -0
  73. data/app/views/layouts/_footer.html.haml +9 -0
  74. data/app/views/layouts/_head.html.haml +16 -0
  75. data/app/views/layouts/admin/_nav.html.haml +13 -0
  76. data/app/views/layouts/admin.html.haml +15 -0
  77. data/app/views/layouts/application.html.haml +14 -0
  78. data/app/views/layouts/area_editor.html.haml +11 -0
  79. data/app/views/passwords/edit.html.haml +9 -0
  80. data/app/views/passwords/new.html.haml +13 -0
  81. data/app/views/registrations/_address_form.html.haml +7 -0
  82. data/app/views/registrations/create.html.haml +49 -0
  83. data/app/views/registrations/index.html.haml +30 -0
  84. data/app/views/registrations/new.html.haml +17 -0
  85. data/app/views/sessions/new.html.haml +18 -0
  86. data/app/views/stylesheets/common.sass +239 -0
  87. data/app/views/stylesheets/content.sass +193 -0
  88. data/app/views/stylesheets/reset.sass +46 -0
  89. data/app/views/stylesheets/structure.sass +11 -0
  90. data/app/views/stylesheets/typography.sass +57 -0
  91. data/app/views/user_mailer/email_verification.html.erb +5 -0
  92. data/app/views/user_mailer/email_verification.text.erb +7 -0
  93. data/app/views/user_mailer/new_issue.html.erb +32 -0
  94. data/app/views/user_mailer/new_issue.text.erb +26 -0
  95. data/app/views/user_mailer/password_reset.html.erb +7 -0
  96. data/app/views/user_mailer/password_reset.text.erb +6 -0
  97. data/app/views/users/_form.html.haml +5 -0
  98. data/app/views/users/edit.html.haml +11 -0
  99. data/app/views/users/new.html.haml +41 -0
  100. data/app/views/users/show.html.haml +30 -0
  101. data/bin/open_porch_engine +135 -0
  102. data/config/application.rb +43 -0
  103. data/config/boot.rb +13 -0
  104. data/config/database_example.yml +59 -0
  105. data/config/environment.rb +5 -0
  106. data/config/environments/development.rb +26 -0
  107. data/config/environments/production.rb +49 -0
  108. data/config/environments/test.rb +35 -0
  109. data/config/initializers/backtrace_silencers.rb +7 -0
  110. data/config/initializers/email_regex.rb +38 -0
  111. data/config/initializers/geokit_config.rb +61 -0
  112. data/config/initializers/inflections.rb +20 -0
  113. data/config/initializers/meta_search.rb +7 -0
  114. data/config/initializers/mime_types.rb +5 -0
  115. data/config/initializers/open_porch.rb +41 -0
  116. data/config/initializers/sass.rb +1 -0
  117. data/config/initializers/secret_token.rb +7 -0
  118. data/config/initializers/session_store.rb +8 -0
  119. data/config/initializers/states_provinces.rb +2 -0
  120. data/config/initializers/will_paginate.rb +2 -0
  121. data/config/locales/en.yml +5 -0
  122. data/config/open_porch_example.yml +23 -0
  123. data/config/routes.rb +54 -0
  124. data/config/schedule.rb +9 -0
  125. data/config.ru +4 -0
  126. data/db/migrate/01_create_areas.rb +21 -0
  127. data/db/migrate/02_create_users.rb +28 -0
  128. data/db/migrate/03_create_memberships.rb +14 -0
  129. data/db/migrate/04_create_posts.rb +20 -0
  130. data/db/migrate/05_create_issue_numbers.rb +13 -0
  131. data/db/migrate/06_create_issues.rb +21 -0
  132. data/db/migrate/20110204173301_add_published_to_areas.rb +10 -0
  133. data/db/migrate/20110204194840_create_user_activities.rb +13 -0
  134. data/db/migrate/20110208163604_add_zip_to_areas.rb +11 -0
  135. data/db/migrate/20110209175723_add_counters_to_areas.rb +11 -0
  136. data/db/migrate/20110209182244_remove_subject_from_issues.rb +9 -0
  137. data/db/migrate/20110209190146_add_reviewer_info_to_posts.rb +9 -0
  138. data/db/migrate/20110215173144_add_email_validation_key_to_users.rb +13 -0
  139. data/db/migrate/20110215182716_remove_published_from_areas.rb +10 -0
  140. data/db/migrate/20110215211012_create_area_activities.rb +19 -0
  141. data/db/migrate/20110215213802_create_email_messages.rb +19 -0
  142. data/db/migrate/20110217165018_change_send_mode_to_string.rb +17 -0
  143. data/db/migrate/20110223160609_denormalize_user_info_in_posts.rb +19 -0
  144. data/db/seeds.rb +7 -0
  145. data/doc/README_FOR_APP +2 -0
  146. data/lib/generators/open_porch_generator.rb +37 -0
  147. data/lib/open_porch/engine.rb +20 -0
  148. data/lib/open_porch.rb +3 -0
  149. data/lib/tasks/.gitkeep +0 -0
  150. data/lib/tasks/open_porch.rake +10 -0
  151. data/lib/tasks/postageapp_tasks.rake +78 -0
  152. data/open_porch.gemspec +335 -0
  153. data/public/404.html +26 -0
  154. data/public/422.html +26 -0
  155. data/public/500.html +26 -0
  156. data/public/favicon.ico +0 -0
  157. data/public/images/icons/ajax-loader.gif +0 -0
  158. data/public/images/icons/calendar.png +0 -0
  159. data/public/images/icons/post_new.png +0 -0
  160. data/public/images/icons/post_reviewed.png +0 -0
  161. data/public/javascripts/application.js +3 -0
  162. data/public/javascripts/google_maps.js +153 -0
  163. data/public/javascripts/highcharts.js +162 -0
  164. data/public/javascripts/highcharts_init.js +30 -0
  165. data/public/javascripts/issue_edit.js +57 -0
  166. data/public/javascripts/jquery-ui.min.js +191 -0
  167. data/public/javascripts/jquery.js +154 -0
  168. data/public/javascripts/rails.js +137 -0
  169. data/public/javascripts/region_editor.js +616 -0
  170. data/public/javascripts/user_activity.js +29 -0
  171. data/public/robots.txt +5 -0
  172. data/public/stylesheets/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  173. data/public/stylesheets/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  174. data/public/stylesheets/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  175. data/public/stylesheets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  176. data/public/stylesheets/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  177. data/public/stylesheets/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  178. data/public/stylesheets/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  179. data/public/stylesheets/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  180. data/public/stylesheets/images/ui-icons_222222_256x240.png +0 -0
  181. data/public/stylesheets/images/ui-icons_2e83ff_256x240.png +0 -0
  182. data/public/stylesheets/images/ui-icons_454545_256x240.png +0 -0
  183. data/public/stylesheets/images/ui-icons_888888_256x240.png +0 -0
  184. data/public/stylesheets/images/ui-icons_cd0a0a_256x240.png +0 -0
  185. data/public/stylesheets/jquery-ui.css +362 -0
  186. data/script/rails +6 -0
  187. data/test/dummy/area.rb +5 -0
  188. data/test/dummy/area_activity.rb +7 -0
  189. data/test/dummy/issue.rb +4 -0
  190. data/test/dummy/membership.rb +4 -0
  191. data/test/dummy/post.rb +12 -0
  192. data/test/dummy/user.rb +29 -0
  193. data/test/dummy/user_activity.rb +11 -0
  194. data/test/functional/admin/areas/issues_controller_test.rb +48 -0
  195. data/test/functional/admin/areas/memberships_controller_test.rb +45 -0
  196. data/test/functional/admin/areas/posts_controller_test.rb +54 -0
  197. data/test/functional/admin/areas_controller_test.rb +134 -0
  198. data/test/functional/admin/base_controller_test.rb +8 -0
  199. data/test/functional/admin/user_activity_controller_test.rb +28 -0
  200. data/test/functional/admin/users_controller_test.rb +144 -0
  201. data/test/functional/areas/issues_controller_test.rb +33 -0
  202. data/test/functional/areas/posts_controller_test.rb +50 -0
  203. data/test/functional/areas_controller_test.rb +12 -0
  204. data/test/functional/passwords_controller_test.rb +64 -0
  205. data/test/functional/registrations_controller_test.rb +64 -0
  206. data/test/functional/sessions_controller_test.rb +120 -0
  207. data/test/functional/users_controller_test.rb +144 -0
  208. data/test/performance/browsing_test.rb +9 -0
  209. data/test/test_helper.rb +92 -0
  210. data/test/unit/address_test.rb +25 -0
  211. data/test/unit/area_activity_test.rb +57 -0
  212. data/test/unit/area_test.rb +92 -0
  213. data/test/unit/email_message_test.rb +8 -0
  214. data/test/unit/issue_number_test.rb +25 -0
  215. data/test/unit/issue_test.rb +154 -0
  216. data/test/unit/membership_test.rb +20 -0
  217. data/test/unit/post_test.rb +69 -0
  218. data/test/unit/session_user_test.rb +65 -0
  219. data/test/unit/user_activity_test.rb +31 -0
  220. data/test/unit/user_mailer_test.rb +20 -0
  221. data/test/unit/user_test.rb +61 -0
  222. data/vendor/plugins/.gitkeep +0 -0
  223. metadata +456 -0
@@ -0,0 +1,134 @@
1
+ require 'test_helper'
2
+
3
+ class Admin::AreasControllerTest < ActionController::TestCase
4
+
5
+ def setup
6
+ @user = a User
7
+ assert_created @user
8
+
9
+ @user.update_attribute(:role, 'admin')
10
+ assert @user.is_admin?
11
+
12
+ @area = Area.create_dummy(
13
+ :name => 'Oakledge',
14
+ :border => Polygon.from_coordinates([[
15
+ [44.450713, -73.227265],
16
+ [44.456838, -73.225943],
17
+ [44.455921, -73.218375],
18
+ [44.449365, -73.220694],
19
+ [44.450713, -73.227265]
20
+ ]])
21
+ )
22
+ assert_created @area
23
+
24
+ @user.areas << @area
25
+ assert_equal @area, @user.areas.first
26
+
27
+ login_as(@user)
28
+ end
29
+
30
+ def test_require_admin
31
+ @user.update_attribute(:role, 'regular_user')
32
+ login_as(@user)
33
+
34
+ get :index
35
+ assert_equal "You're not authorized to access that page.", flash[:alert]
36
+ assert_redirected_to area_path(@user.areas.first)
37
+ end
38
+
39
+ def test_get_index
40
+ get :index
41
+ assert_response :success
42
+ assert_template :index
43
+ assert assigns(:areas)
44
+ end
45
+
46
+ def test_get_new
47
+ get :new
48
+ assert_response :success
49
+ assert_template :new
50
+ end
51
+
52
+ def test_create
53
+ assert_difference ['Area.count', 'IssueNumber.count'], 1 do
54
+ post :create, :area => area_params
55
+ end
56
+ assert_redirected_to admin_areas_path
57
+ end
58
+
59
+ def test_create_fails
60
+ assert_no_difference ['Area.count', 'IssueNumber.count'] do
61
+ post :create, :area => area_params(:name => '')
62
+ end
63
+ assert_response :success
64
+ assert_template :new
65
+ end
66
+
67
+ def test_create_from_js
68
+ assert_difference ['Area.count', 'IssueNumber.count'], 1 do
69
+ xhr :post, :create, :area => area_params
70
+ end
71
+ assert_response :success
72
+ end
73
+
74
+ def test_get_edit
75
+ area = an Area
76
+ get :edit, :id => area
77
+ assert_response :success
78
+ assert_template :edit
79
+ end
80
+
81
+ def test_update
82
+ area = an Area
83
+ put :update, :id => area, :area => { :name => '[EDIT] New Area Name'}
84
+ area.reload
85
+ assert_equal '[EDIT] New Area Name', area.name
86
+ assert_redirected_to admin_areas_path
87
+ end
88
+
89
+ def test_update_fails
90
+ area = an Area
91
+ put :update, :id => area, :area => { :name => '' }
92
+ assert_response :success
93
+ assert_template :edit
94
+ assert_not_nil area.name
95
+ end
96
+
97
+ def test_destroy
98
+ area = an Area
99
+ assert_difference ['Area.count', 'IssueNumber.count'], -1 do
100
+ delete :destroy, :id => area
101
+ end
102
+ assert_redirected_to admin_areas_path
103
+ end
104
+
105
+ def test_edit_borders
106
+ get :edit_borders, :id => @area.id
107
+ assert_response :success
108
+ assert_template :edit_borders
109
+ assert_equal [@area], assigns(:areas)
110
+ assert_equal @area, assigns(:selected_area)
111
+ end
112
+
113
+ def test_bulk_update
114
+ skip # < --------------------
115
+ xhr :post, :bulk_update, "areas"=>{
116
+ "0"=>{
117
+ "id"=> @area.id,
118
+ "coordinates"=>{"0"=>["44.471237230753886", "-73.23112146041126"], "1"=>["44.46936923281188", "-73.22386876723499"], "2"=>["44.4617123643827", "-73.22558538100452"]}
119
+ }
120
+ }
121
+
122
+ new_area = Area.find(@area.id)
123
+ puts new_area.to_a.to_yaml
124
+ assert_equal [44.450713, -73.227265], [area.border.first.points.first.x, area.border.first.points.first.y]
125
+ end
126
+
127
+ protected
128
+ def area_params(options = {})
129
+ {
130
+ :name => 'New Area',
131
+ :slug => 'new-area'
132
+ }.merge(options)
133
+ end
134
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class Admin::BaseControllerTest < ActionController::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class Admin::UserActivityControllerTest < ActionController::TestCase
4
+
5
+ def setup
6
+ login_as(:admin)
7
+ @user_activity = a UserActivity
8
+ end
9
+
10
+ def test_require_admin
11
+ user = login_as(:regular_user)
12
+ get :show, :id => @user_activity
13
+ assert_equal "You're not authorized to access that page.", flash[:alert]
14
+ assert_redirected_to area_path(user.areas.first)
15
+ end
16
+
17
+ def test_get_show
18
+ get :show, :id => @user_activity
19
+ assert_response :success
20
+ assert_template :show
21
+ end
22
+
23
+ def test_update
24
+ put :update, :id => @user_activity
25
+ assert (@user_activity.expires_at > Time.now)
26
+ end
27
+
28
+ end
@@ -0,0 +1,144 @@
1
+ require 'test_helper'
2
+
3
+ class Admin::UsersControllerTest < ActionController::TestCase
4
+
5
+ def setup
6
+ @user = a User
7
+ assert_created @user
8
+
9
+ @user.update_attribute(:role, 'admin')
10
+ assert @user.is_admin?
11
+
12
+ @area = Area.create_dummy(
13
+ :name => 'Oakledge',
14
+ :border => Polygon.from_coordinates([[
15
+ [44.450713, -73.227265],
16
+ [44.456838, -73.225943],
17
+ [44.455921, -73.218375],
18
+ [44.449365, -73.220694],
19
+ [44.450713, -73.227265]
20
+ ]])
21
+ )
22
+ assert_created @area
23
+
24
+ @user.areas << @area
25
+ assert_equal @area, @user.areas.first
26
+
27
+ login_as(@user)
28
+ end
29
+
30
+ def test_require_admin
31
+ @user.update_attribute(:role, 'regular_user')
32
+ login_as(@user)
33
+ get :index
34
+ assert_equal "You're not authorized to access that page.", flash[:alert]
35
+ assert_redirected_to area_path(@user.areas.first)
36
+ end
37
+
38
+ def test_get_index
39
+ get :index
40
+ assert_response :success
41
+ assert_template :index
42
+ assert assigns(:users)
43
+ end
44
+
45
+ def test_get_new
46
+ get :new
47
+ assert_response :success
48
+ assert_template :new
49
+ end
50
+
51
+ def test_create
52
+ assert_difference 'User.count', 1 do
53
+ post :create, :user => user_params(:password => 'testtest', :password_confirmation => 'testtest')
54
+ end
55
+ assert_equal 'User was successfully created.', flash[:notice]
56
+ assert_redirected_to admin_users_path
57
+ end
58
+
59
+ def test_creation_fail
60
+ assert_no_difference 'User.count' do
61
+ post :create, :user => user_params(:first_name => '')
62
+ end
63
+ assert_response :success
64
+ assert_template :new
65
+ end
66
+
67
+ def test_get_edit
68
+ user = a User
69
+ get :edit, :id => user
70
+ assert_response :success
71
+ assert_template :edit
72
+ end
73
+
74
+ def test_update_from_users
75
+ user = a User
76
+ assert_not_equal 'user@domain.com', user.email
77
+ assert_not_equal 'Test', user.first_name
78
+ assert_not_equal 'Name', user.last_name
79
+ assert_not_equal 'Test Address', user.address
80
+ assert_not_equal 'Test City', user.city
81
+ assert_not_equal 'Test State', user.state
82
+ put :update, :id => user, :user => user_params, :area_id => nil
83
+ user.reload
84
+ assert_equal flash[:notice], 'User has been successfully updated.'
85
+ assert_equal 'user@domain.com', user.email
86
+ assert_equal 'Test', user.first_name
87
+ assert_equal 'Name', user.last_name
88
+ assert_equal 'Test Address', user.address
89
+ assert_equal 'Test City', user.city
90
+ assert_equal 'Test State', user.state
91
+ assert_redirected_to admin_users_path
92
+ end
93
+
94
+ def test_update_from_areas
95
+ area = an Area
96
+ user = a User
97
+ assert_not_equal 'user@domain.com', user.email
98
+ assert_not_equal 'Test', user.first_name
99
+ assert_not_equal 'Name', user.last_name
100
+ assert_not_equal 'Test Address', user.address
101
+ assert_not_equal 'Test City', user.city
102
+ assert_not_equal 'Test State', user.state
103
+ put :update, :id => user, :user => user_params, :area_id => area
104
+ assert_equal flash[:notice], 'User has been successfully updated.'
105
+ assert_equal 'user@domain.com', assigns(:user).email
106
+ assert_equal 'Test', assigns(:user).first_name
107
+ assert_equal 'Name', assigns(:user).last_name
108
+ assert_equal 'Test Address', assigns(:user).address
109
+ assert_equal 'Test City', assigns(:user).city
110
+ assert_equal 'Test State', assigns(:user).state
111
+ assert_redirected_to admin_area_memberships_path(area)
112
+ end
113
+
114
+ def test_update_fails
115
+ user = a User
116
+ put :update, :id => user, :user => { :email => '' }
117
+ assert_response :success
118
+ assert_template :edit
119
+ assert_not_nil assigns(:user).email
120
+ assert assigns(:user).errors[:email].include?("Please enter your email address")
121
+ assert assigns(:user).errors[:email].include?("The email address you entered is to short")
122
+ assert assigns(:user).errors[:email].include?("The email address you entered is not valid")
123
+ end
124
+
125
+ def test_destroy
126
+ user = a User
127
+ assert_difference 'User.count', -1 do
128
+ delete :destroy, :id => user
129
+ end
130
+ assert_redirected_to admin_users_path
131
+ end
132
+
133
+ protected
134
+ def user_params(options = {})
135
+ {
136
+ :email => 'user@domain.com',
137
+ :first_name => 'Test',
138
+ :last_name => 'Name',
139
+ :address => 'Test Address',
140
+ :city => 'Test City',
141
+ :state => 'Test State'
142
+ }.merge(options)
143
+ end
144
+ end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ class Areas::IssuesControllerTest < ActionController::TestCase
4
+ def setup
5
+ login_as(:regular_user)
6
+ @current_user = @controller.current_user
7
+ end
8
+
9
+ def test_get_index
10
+ issue = Issue.create_dummy
11
+ @current_user.memberships.create(:area => issue.area)
12
+ get :index, :area_id => issue.area
13
+ assert_response :success
14
+ assert_template :index
15
+ end
16
+
17
+ def test_get_show
18
+ issue = an Issue
19
+ issue.update_attribute(:sent_at, Time.now)
20
+ @current_user.memberships.create(:area => issue.area)
21
+ get :show, :area_id => issue.area, :id => issue.number
22
+ assert_response :success
23
+ assert_template :show
24
+ end
25
+
26
+ def test_get_archive
27
+ area = an Area
28
+ @current_user.memberships.create(:area => area)
29
+ get :index, :area_id => area, :year => 2011, :month => 01
30
+ assert_response :success
31
+ assert_template :index
32
+ end
33
+ end
@@ -0,0 +1,50 @@
1
+ require 'test_helper'
2
+
3
+ class Areas::PostsControllerTest < ActionController::TestCase
4
+
5
+ def setup
6
+ login_as(:regular_user)
7
+ end
8
+
9
+ def test_new
10
+ area = an Area
11
+ assert_created area
12
+ @controller.current_user.memberships.create!(:area => area)
13
+ get :new, :area_id => area
14
+ assert_response :success
15
+ assert_template :new
16
+ end
17
+
18
+ def test_create
19
+ area = an Area
20
+ assert_created area
21
+ @controller.current_user.memberships.create!(:area => area)
22
+ assert_difference 'Post.count', 1 do
23
+ post :create, :area_id => area, :post => { :title => "New Post", :content => 'test'}
24
+ end
25
+ assert_redirected_to area_path(area)
26
+ end
27
+
28
+ def test_create_fails
29
+ area = an Area
30
+ assert_created area
31
+ @controller.current_user.memberships.create!(:area => area)
32
+ assert_no_difference 'Post.count' do
33
+ post :create, :area_id => area
34
+ end
35
+ assert_errors_on assigns(:post), :title, :content
36
+ assert_response :success
37
+ assert_template :new
38
+ end
39
+
40
+ def test_shouldnt_post_to_other_forums
41
+ area = an Area
42
+ assert_created area
43
+ assert !@controller.current_user.is_admin?
44
+ assert_no_difference 'Post.count' do
45
+ post :create, :area_id => area
46
+ end
47
+ assert_redirected_to user_path
48
+ end
49
+
50
+ end
@@ -0,0 +1,12 @@
1
+ require 'test_helper'
2
+
3
+ class AreasControllerTest < ActionController::TestCase
4
+
5
+ def test_get_show
6
+ area = an Area
7
+ get :show, :id => area
8
+ assert_response :success
9
+ assert_template :show
10
+ end
11
+
12
+ end
@@ -0,0 +1,64 @@
1
+ require 'test_helper'
2
+
3
+ class PasswordsControllerTest < ActionController::TestCase
4
+ def test_new
5
+ get :new
6
+ assert_response :success
7
+ assert_template 'new'
8
+ end
9
+
10
+ def test_create
11
+ user = a User
12
+ assert_created user
13
+ assert_difference 'ActionMailer::Base.deliveries.size', 1 do
14
+ assert_emails 1 do
15
+ post :create, :email => user.email
16
+ assert_equal 'Email to reset password successfully sent.', flash[:notice]
17
+ assert_redirected_to login_path
18
+ user.reload
19
+ assert_not_nil user.perishable_token
20
+ end
21
+ end
22
+ response = ActionMailer::Base.deliveries.last
23
+ assert_equal 2, response.arguments['content'].length
24
+ response.arguments['content'].each do |content_type, body|
25
+ assert_match user.perishable_token, body
26
+ end
27
+ assert_equal user.email, response.to[0]
28
+ end
29
+
30
+ def test_edit
31
+ user = a User
32
+ user.reset_perishable_token!
33
+ get :edit, :id => user.perishable_token
34
+ assert_response :success
35
+ assert_template 'edit'
36
+ end
37
+
38
+ def test_edit_redirects_on_invalid_perishable_token
39
+ user = a User
40
+ user.reset_perishable_token!
41
+ get :edit, :id => user.perishable_token + 'bogus'
42
+ assert_redirected_to login_path
43
+ end
44
+
45
+ def test_update
46
+ user = a User
47
+ user.reset_perishable_token!
48
+ assert !user.password_match?('newpassword')
49
+ put :update, :id => user.perishable_token, :user => {:password => 'newpassword', :password_confirmation => 'newpassword'}
50
+ assert_redirected_to user_path(user)
51
+ user.reload
52
+ assert_nil user.perishable_token
53
+ assert user.password_match?('newpassword')
54
+ end
55
+
56
+ def test_update_redirects_on_invalid_perishable_token
57
+ user = a User
58
+ user.reset_perishable_token!
59
+ put :update, :id => user.perishable_token + 'bogus', :user => {:password => 'newpassword', :password_confirmation => 'newpassword'}
60
+ assert_redirected_to login_path
61
+ user.reload
62
+ assert_not_nil user.perishable_token
63
+ end
64
+ end
@@ -0,0 +1,64 @@
1
+ require 'test_helper'
2
+
3
+ class RegistrationsControllerTest < ActionController::TestCase
4
+ include GeoKit::Geocoders
5
+
6
+ def test_index
7
+ get :index
8
+ assert_response :success
9
+ assert_template 'index'
10
+ end
11
+
12
+ def test_new
13
+ get :new
14
+ assert_response :success
15
+ assert_template 'new'
16
+ end
17
+
18
+ def test_create
19
+ oakledge = Area.create_dummy(
20
+ :name => 'Oakledge',
21
+ :border => Polygon.from_coordinates([[
22
+ [44.450713, -73.227265],
23
+ [44.456838, -73.225943],
24
+ [44.455921, -73.218375],
25
+ [44.449365, -73.220694],
26
+ [44.450713, -73.227265]
27
+ ]])
28
+ )
29
+ Geokit::Geocoders::GoogleGeocoder.expects(:geocode).returns(success_geocode(44.4533518, -73.2219273))
30
+
31
+ post :create, :address => {:address=>"123 Fake St", :city=>"Burlington", :state=>"Vermont"}
32
+ assert assigns(:areas).empty?
33
+ assert_equal oakledge, assigns(:selected_area)
34
+ assert_response :success
35
+ assert_template 'create'
36
+ end
37
+
38
+ def test_create_with_invalid_address
39
+ Address.any_instance.stubs(:closest_regions).returns([])
40
+ post :create, :address => {:address=>"123 Fake St"}
41
+ assert_redirected_to root_path
42
+ assert !assigns(:address).valid?
43
+ end
44
+
45
+ def test_create_with_no_regions
46
+ Address.any_instance.stubs(:closest_regions).returns([])
47
+ post :create, :address => {:address=>"123 Fake St", :city=>"Burlington", :state=>"Vermont"}
48
+ assert_equal flash.now[:alert], "Sorry, we couldn't find any neighbourhoods close to you!"
49
+ assert_redirected_to root_path
50
+ end
51
+
52
+ protected
53
+ def success_geocode(lat, lng)
54
+ @success = Geokit::GeoLoc.new({
55
+ :street_address=>"some address",
56
+ :city=>"SAN FRANCISCO",
57
+ :state=>"CA",
58
+ :country_code=>"US",
59
+ :lat=>lat,
60
+ :lng=>lng})
61
+ @success.success = true
62
+ @success
63
+ end
64
+ end
@@ -0,0 +1,120 @@
1
+ require 'test_helper'
2
+
3
+ class SessionsControllerTest < ActionController::TestCase
4
+ def setup
5
+ @regular_user = a User
6
+ assert_created @regular_user
7
+
8
+ @regular_user.set_email_verification_key
9
+ @regular_user.role = 'regular_user'
10
+ @regular_user.save!
11
+ assert !@regular_user.is_admin?
12
+ assert !@regular_user.is_verified?
13
+
14
+ area = an Area
15
+ assert_created area
16
+
17
+ @regular_user.areas << area
18
+ assert_equal area, @regular_user.areas.first
19
+ end
20
+
21
+ # >> Login -----------------------------------------------------------
22
+
23
+ def test_get_new
24
+ get :new
25
+ assert_response :success
26
+ assert_template 'new'
27
+ assert !@controller.logged_in?
28
+ assert_nil @controller.current_user
29
+ end
30
+
31
+ def test_should_login_with_email_and_redirect
32
+ @regular_user.update_attribute(:verified_at, Time.now)
33
+ assert @regular_user.is_verified?
34
+
35
+ post :create, :session_user => { :email => @regular_user.email, :password => @regular_user.password }
36
+ assert_equal "Welcome, you are now logged in.", flash[:notice]
37
+ assert_equal session[:user_id], @regular_user.id
38
+ assert_redirected_to area_path(@controller.current_user.areas.first)
39
+ assert @controller.logged_in?
40
+ assert_equal @controller.current_user, @regular_user
41
+ end
42
+
43
+ def test_login_errors
44
+ post :create, :session_user => { :email => 'a', :password => 'b' }
45
+ assert_equal "Login failed. Did you mistype?", flash[:alert]
46
+ assert_nil session[:user]
47
+ assert_response :success
48
+ assert_template 'new'
49
+ assert !@controller.logged_in?
50
+ assert_nil @controller.current_user
51
+
52
+ assert !assigns(:session_user).valid?
53
+ assert_errors_on assigns(:session_user), :email, :password
54
+ assert assigns(:session_user).errors[:email].include?("The email address you entered is not valid")
55
+ assert assigns(:session_user).errors[:email].include?("The email address you entered is to short")
56
+ assert assigns(:session_user).errors[:password].include?("The password you entered is too short (minimum is 4 characters)")
57
+ end
58
+
59
+ def test_login_with_email_not_verified
60
+ post :create, :session_user => { :email => @regular_user.email, :password => @regular_user.password }
61
+ assert_equal "Login failed. Did you mistype?", flash[:alert]
62
+ assert_nil session[:user]
63
+ assert_response :success
64
+ assert_template 'new'
65
+ assert !@controller.logged_in?
66
+ assert_nil @controller.current_user
67
+ assert_errors_on assigns(:session_user), :email
68
+ assert assigns(:session_user).errors[:email].include?("This email address needs to be verified before you can login. <a href='/resend-email-verification/#{@regular_user.email_verification_key}'>Resend verification</a>")
69
+ end
70
+
71
+ def test_new_redirects_if_logged_in
72
+ login_as(@regular_user)
73
+ assert_equal session[:user_id], @regular_user.id
74
+ assert @controller.logged_in?
75
+ assert_equal @controller.current_user, @regular_user
76
+
77
+ get :new
78
+ assert_redirected_to user_path
79
+ end
80
+
81
+ def test_create_redirects_if_logged_in
82
+ login_as(@regular_user)
83
+ assert_equal session[:user_id], @regular_user.id
84
+ assert @controller.logged_in?
85
+ assert_equal @controller.current_user, @regular_user
86
+
87
+ post :create, :session_user => { :email => @regular_user.email, :password => @regular_user.password }
88
+ assert_redirected_to user_path
89
+ end
90
+
91
+ # >> Logout -----------------------------------------------------------
92
+
93
+ def test_should_logout
94
+ login_as(@regular_user)
95
+ assert_equal session[:user_id], @regular_user.id
96
+ assert @controller.logged_in?
97
+ assert_equal @controller.current_user, @regular_user
98
+
99
+ get :destroy
100
+ assert_redirected_to root_path
101
+ assert_nil cookies[:login_token]
102
+ assert_nil session[:user_id]
103
+ @regular_user.reload
104
+ assert_nil @regular_user.remember_token
105
+ assert !@controller.logged_in?
106
+ assert_nil @controller.current_user
107
+ end
108
+
109
+ # >> Remember me -----------------------------------------------------------
110
+
111
+ def test_remember_me
112
+ @regular_user.update_attribute(:verified_at, Time.now)
113
+ assert @regular_user.is_verified?
114
+
115
+ post :create, :session_user => { :email => @regular_user.email, :password => @regular_user.password , :remember_me => '1' }
116
+ assert_equal request.session[:user_id], @regular_user.id
117
+ assert_not_nil assigns(:session_user).user.remember_token
118
+ assert_equal assigns(:session_user).user.remember_token, cookies['login_token']
119
+ end
120
+ end