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.
- data/Gemfile +41 -0
- data/Gemfile.lock +130 -0
- data/README.md +170 -0
- data/Rakefile +19 -0
- data/VERSION +1 -0
- data/app/controllers/admin/areas/base_controller.rb +11 -0
- data/app/controllers/admin/areas/issues_controller.rb +67 -0
- data/app/controllers/admin/areas/memberships_controller.rb +7 -0
- data/app/controllers/admin/areas/posts_controller.rb +44 -0
- data/app/controllers/admin/areas_controller.rb +89 -0
- data/app/controllers/admin/base_controller.rb +16 -0
- data/app/controllers/admin/user_activity_controller.rb +29 -0
- data/app/controllers/admin/users_controller.rb +57 -0
- data/app/controllers/application_controller.rb +15 -0
- data/app/controllers/areas/base_controller.rb +25 -0
- data/app/controllers/areas/issues_controller.rb +35 -0
- data/app/controllers/areas/posts_controller.rb +28 -0
- data/app/controllers/areas_controller.rb +30 -0
- data/app/controllers/passwords_controller.rb +42 -0
- data/app/controllers/registrations_controller.rb +42 -0
- data/app/controllers/sessions_controller.rb +33 -0
- data/app/controllers/users_controller.rb +77 -0
- data/app/helpers/open_porch_helper.rb +24 -0
- data/app/mailers/user_mailer.rb +35 -0
- data/app/models/address.rb +57 -0
- data/app/models/area.rb +171 -0
- data/app/models/area_activity.rb +24 -0
- data/app/models/email_message.rb +104 -0
- data/app/models/issue.rb +66 -0
- data/app/models/issue_number.rb +22 -0
- data/app/models/membership.rb +27 -0
- data/app/models/post.rb +64 -0
- data/app/models/session_user.rb +69 -0
- data/app/models/user.rb +140 -0
- data/app/models/user_activity.rb +31 -0
- data/app/models/user_authority_check.rb +14 -0
- data/app/views/admin/areas/_form.html.haml +8 -0
- data/app/views/admin/areas/_nav.html.haml +12 -0
- data/app/views/admin/areas/edit.html.haml +22 -0
- data/app/views/admin/areas/edit_borders.html.haml +44 -0
- data/app/views/admin/areas/index.html.haml +61 -0
- data/app/views/admin/areas/issues/_post.html.haml +15 -0
- data/app/views/admin/areas/issues/add_posts.js.rjs +3 -0
- data/app/views/admin/areas/issues/edit.html.haml +37 -0
- data/app/views/admin/areas/issues/index.html.haml +31 -0
- data/app/views/admin/areas/issues/remove_posts.js.rjs +3 -0
- data/app/views/admin/areas/issues/show.html.haml +13 -0
- data/app/views/admin/areas/memberships/index.html.haml +17 -0
- data/app/views/admin/areas/new.html.haml +6 -0
- data/app/views/admin/areas/new.js.haml +4 -0
- data/app/views/admin/areas/posts/_edit.html.haml +6 -0
- data/app/views/admin/areas/posts/_post_status.html.haml +1 -0
- data/app/views/admin/areas/posts/destroy.js.rjs +1 -0
- data/app/views/admin/areas/posts/edit.js.rjs +1 -0
- data/app/views/admin/areas/posts/show.js.rjs +1 -0
- data/app/views/admin/areas/posts/toggle_reviewed_by.js.rjs +1 -0
- data/app/views/admin/areas/posts/update.js.rjs +5 -0
- data/app/views/admin/areas/show.html.haml +5 -0
- data/app/views/admin/user_activity/show.html.haml +5 -0
- data/app/views/admin/users/_form.html.haml +21 -0
- data/app/views/admin/users/edit.html.haml +5 -0
- data/app/views/admin/users/index.html.haml +31 -0
- data/app/views/admin/users/new.html.haml +5 -0
- data/app/views/areas/issues/index.html.haml +31 -0
- data/app/views/areas/issues/show.html.haml +22 -0
- data/app/views/areas/posts/_post.html.haml +8 -0
- data/app/views/areas/posts/_posts_search_form.html.haml +8 -0
- data/app/views/areas/posts/index.html.haml +27 -0
- data/app/views/areas/posts/new.html.haml +10 -0
- data/app/views/areas/show.html.haml +47 -0
- data/app/views/layouts/_account_nav.html.haml +18 -0
- data/app/views/layouts/_flash_message.html.haml +4 -0
- data/app/views/layouts/_footer.html.haml +9 -0
- data/app/views/layouts/_head.html.haml +16 -0
- data/app/views/layouts/admin/_nav.html.haml +13 -0
- data/app/views/layouts/admin.html.haml +15 -0
- data/app/views/layouts/application.html.haml +14 -0
- data/app/views/layouts/area_editor.html.haml +11 -0
- data/app/views/passwords/edit.html.haml +9 -0
- data/app/views/passwords/new.html.haml +13 -0
- data/app/views/registrations/_address_form.html.haml +7 -0
- data/app/views/registrations/create.html.haml +49 -0
- data/app/views/registrations/index.html.haml +30 -0
- data/app/views/registrations/new.html.haml +17 -0
- data/app/views/sessions/new.html.haml +18 -0
- data/app/views/stylesheets/common.sass +239 -0
- data/app/views/stylesheets/content.sass +193 -0
- data/app/views/stylesheets/reset.sass +46 -0
- data/app/views/stylesheets/structure.sass +11 -0
- data/app/views/stylesheets/typography.sass +57 -0
- data/app/views/user_mailer/email_verification.html.erb +5 -0
- data/app/views/user_mailer/email_verification.text.erb +7 -0
- data/app/views/user_mailer/new_issue.html.erb +32 -0
- data/app/views/user_mailer/new_issue.text.erb +26 -0
- data/app/views/user_mailer/password_reset.html.erb +7 -0
- data/app/views/user_mailer/password_reset.text.erb +6 -0
- data/app/views/users/_form.html.haml +5 -0
- data/app/views/users/edit.html.haml +11 -0
- data/app/views/users/new.html.haml +41 -0
- data/app/views/users/show.html.haml +30 -0
- data/bin/open_porch_engine +135 -0
- data/config/application.rb +43 -0
- data/config/boot.rb +13 -0
- data/config/database_example.yml +59 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +26 -0
- data/config/environments/production.rb +49 -0
- data/config/environments/test.rb +35 -0
- data/config/initializers/backtrace_silencers.rb +7 -0
- data/config/initializers/email_regex.rb +38 -0
- data/config/initializers/geokit_config.rb +61 -0
- data/config/initializers/inflections.rb +20 -0
- data/config/initializers/meta_search.rb +7 -0
- data/config/initializers/mime_types.rb +5 -0
- data/config/initializers/open_porch.rb +41 -0
- data/config/initializers/sass.rb +1 -0
- data/config/initializers/secret_token.rb +7 -0
- data/config/initializers/session_store.rb +8 -0
- data/config/initializers/states_provinces.rb +2 -0
- data/config/initializers/will_paginate.rb +2 -0
- data/config/locales/en.yml +5 -0
- data/config/open_porch_example.yml +23 -0
- data/config/routes.rb +54 -0
- data/config/schedule.rb +9 -0
- data/config.ru +4 -0
- data/db/migrate/01_create_areas.rb +21 -0
- data/db/migrate/02_create_users.rb +28 -0
- data/db/migrate/03_create_memberships.rb +14 -0
- data/db/migrate/04_create_posts.rb +20 -0
- data/db/migrate/05_create_issue_numbers.rb +13 -0
- data/db/migrate/06_create_issues.rb +21 -0
- data/db/migrate/20110204173301_add_published_to_areas.rb +10 -0
- data/db/migrate/20110204194840_create_user_activities.rb +13 -0
- data/db/migrate/20110208163604_add_zip_to_areas.rb +11 -0
- data/db/migrate/20110209175723_add_counters_to_areas.rb +11 -0
- data/db/migrate/20110209182244_remove_subject_from_issues.rb +9 -0
- data/db/migrate/20110209190146_add_reviewer_info_to_posts.rb +9 -0
- data/db/migrate/20110215173144_add_email_validation_key_to_users.rb +13 -0
- data/db/migrate/20110215182716_remove_published_from_areas.rb +10 -0
- data/db/migrate/20110215211012_create_area_activities.rb +19 -0
- data/db/migrate/20110215213802_create_email_messages.rb +19 -0
- data/db/migrate/20110217165018_change_send_mode_to_string.rb +17 -0
- data/db/migrate/20110223160609_denormalize_user_info_in_posts.rb +19 -0
- data/db/seeds.rb +7 -0
- data/doc/README_FOR_APP +2 -0
- data/lib/generators/open_porch_generator.rb +37 -0
- data/lib/open_porch/engine.rb +20 -0
- data/lib/open_porch.rb +3 -0
- data/lib/tasks/.gitkeep +0 -0
- data/lib/tasks/open_porch.rake +10 -0
- data/lib/tasks/postageapp_tasks.rake +78 -0
- data/open_porch.gemspec +335 -0
- data/public/404.html +26 -0
- data/public/422.html +26 -0
- data/public/500.html +26 -0
- data/public/favicon.ico +0 -0
- data/public/images/icons/ajax-loader.gif +0 -0
- data/public/images/icons/calendar.png +0 -0
- data/public/images/icons/post_new.png +0 -0
- data/public/images/icons/post_reviewed.png +0 -0
- data/public/javascripts/application.js +3 -0
- data/public/javascripts/google_maps.js +153 -0
- data/public/javascripts/highcharts.js +162 -0
- data/public/javascripts/highcharts_init.js +30 -0
- data/public/javascripts/issue_edit.js +57 -0
- data/public/javascripts/jquery-ui.min.js +191 -0
- data/public/javascripts/jquery.js +154 -0
- data/public/javascripts/rails.js +137 -0
- data/public/javascripts/region_editor.js +616 -0
- data/public/javascripts/user_activity.js +29 -0
- data/public/robots.txt +5 -0
- data/public/stylesheets/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/public/stylesheets/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/public/stylesheets/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/public/stylesheets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/public/stylesheets/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/public/stylesheets/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/public/stylesheets/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/public/stylesheets/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/public/stylesheets/images/ui-icons_222222_256x240.png +0 -0
- data/public/stylesheets/images/ui-icons_2e83ff_256x240.png +0 -0
- data/public/stylesheets/images/ui-icons_454545_256x240.png +0 -0
- data/public/stylesheets/images/ui-icons_888888_256x240.png +0 -0
- data/public/stylesheets/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/public/stylesheets/jquery-ui.css +362 -0
- data/script/rails +6 -0
- data/test/dummy/area.rb +5 -0
- data/test/dummy/area_activity.rb +7 -0
- data/test/dummy/issue.rb +4 -0
- data/test/dummy/membership.rb +4 -0
- data/test/dummy/post.rb +12 -0
- data/test/dummy/user.rb +29 -0
- data/test/dummy/user_activity.rb +11 -0
- data/test/functional/admin/areas/issues_controller_test.rb +48 -0
- data/test/functional/admin/areas/memberships_controller_test.rb +45 -0
- data/test/functional/admin/areas/posts_controller_test.rb +54 -0
- data/test/functional/admin/areas_controller_test.rb +134 -0
- data/test/functional/admin/base_controller_test.rb +8 -0
- data/test/functional/admin/user_activity_controller_test.rb +28 -0
- data/test/functional/admin/users_controller_test.rb +144 -0
- data/test/functional/areas/issues_controller_test.rb +33 -0
- data/test/functional/areas/posts_controller_test.rb +50 -0
- data/test/functional/areas_controller_test.rb +12 -0
- data/test/functional/passwords_controller_test.rb +64 -0
- data/test/functional/registrations_controller_test.rb +64 -0
- data/test/functional/sessions_controller_test.rb +120 -0
- data/test/functional/users_controller_test.rb +144 -0
- data/test/performance/browsing_test.rb +9 -0
- data/test/test_helper.rb +92 -0
- data/test/unit/address_test.rb +25 -0
- data/test/unit/area_activity_test.rb +57 -0
- data/test/unit/area_test.rb +92 -0
- data/test/unit/email_message_test.rb +8 -0
- data/test/unit/issue_number_test.rb +25 -0
- data/test/unit/issue_test.rb +154 -0
- data/test/unit/membership_test.rb +20 -0
- data/test/unit/post_test.rb +69 -0
- data/test/unit/session_user_test.rb +65 -0
- data/test/unit/user_activity_test.rb +31 -0
- data/test/unit/user_mailer_test.rb +20 -0
- data/test/unit/user_test.rb +61 -0
- data/vendor/plugins/.gitkeep +0 -0
- metadata +456 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class UsersControllerTest < ActionController::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@area = Area.create_dummy(
|
|
6
|
+
:name => 'Oakledge',
|
|
7
|
+
:border => Polygon.from_coordinates([[
|
|
8
|
+
[44.450713, -73.227265],
|
|
9
|
+
[44.456838, -73.225943],
|
|
10
|
+
[44.455921, -73.218375],
|
|
11
|
+
[44.449365, -73.220694],
|
|
12
|
+
[44.450713, -73.227265]
|
|
13
|
+
]])
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_new_with_no_address
|
|
18
|
+
get :new
|
|
19
|
+
assert_redirected_to root_path
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_new
|
|
23
|
+
get :new, :user => {
|
|
24
|
+
:address=>"123 Fake St",
|
|
25
|
+
:city=>"Burlington",
|
|
26
|
+
:state=>"Vermont",
|
|
27
|
+
:memberships_attributes=>{"0"=>{:area_id => @area.id}}
|
|
28
|
+
}
|
|
29
|
+
assert_response :success
|
|
30
|
+
assert_template 'new'
|
|
31
|
+
assert_equal assigns(:area), @area
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_create
|
|
35
|
+
assert_difference ['User.count', 'Membership.count'] do
|
|
36
|
+
assert_emails 1 do
|
|
37
|
+
post :create, :user => {
|
|
38
|
+
:email => 'user@example.com',
|
|
39
|
+
:password => 'tester',
|
|
40
|
+
:password_confirmation => 'tester',
|
|
41
|
+
:address=>"123 Fake St",
|
|
42
|
+
:city=>"Burlington",
|
|
43
|
+
:state=>"Vermont",
|
|
44
|
+
:first_name => 'John',
|
|
45
|
+
:last_name => 'Tester',
|
|
46
|
+
:memberships_attributes=>{"0"=>{:area_id => @area.id}}
|
|
47
|
+
}
|
|
48
|
+
assert_redirected_to root_path
|
|
49
|
+
assert_equal 'Thank you, please check your email to complete the registration.', flash[:notice]
|
|
50
|
+
assert !@controller.logged_in?
|
|
51
|
+
assert_not_nil assigns(:user).email_verification_key
|
|
52
|
+
assert !assigns(:user).is_verified?
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
response = ActionMailer::Base.deliveries.last
|
|
56
|
+
assert_equal 2, response.arguments['content'].length
|
|
57
|
+
response.arguments['content'].each do |content_type, body|
|
|
58
|
+
assert_match assigns(:user).email_verification_key, body
|
|
59
|
+
end
|
|
60
|
+
assert_equal assigns(:user).email, response.to[0]
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_create_fails
|
|
65
|
+
assert_no_difference ['User.count', 'Membership.count'] do
|
|
66
|
+
post :create, :user => {}
|
|
67
|
+
assert_redirected_to root_path
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_email_verification
|
|
72
|
+
user = a User
|
|
73
|
+
assert_created user
|
|
74
|
+
assert !user.is_verified?
|
|
75
|
+
|
|
76
|
+
area = an Area
|
|
77
|
+
assert_created area
|
|
78
|
+
|
|
79
|
+
user.areas << area
|
|
80
|
+
assert_equal area, user.areas.first
|
|
81
|
+
|
|
82
|
+
user.set_email_verification_key
|
|
83
|
+
user.save!
|
|
84
|
+
assert !user.is_verified?
|
|
85
|
+
|
|
86
|
+
get :verify_email, :email_verification_key => user.email_verification_key
|
|
87
|
+
assert_equal 'Your email address has been verified. You can now login', flash[:notice]
|
|
88
|
+
assert !@controller.logged_in?
|
|
89
|
+
assert_redirected_to login_path
|
|
90
|
+
user.reload
|
|
91
|
+
assert user.is_verified?
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def test_failed_email_verification
|
|
95
|
+
user = a User
|
|
96
|
+
assert_created user
|
|
97
|
+
assert !user.is_verified?
|
|
98
|
+
|
|
99
|
+
area = an Area
|
|
100
|
+
assert_created area
|
|
101
|
+
|
|
102
|
+
user.areas << area
|
|
103
|
+
assert_equal area, user.areas.first
|
|
104
|
+
|
|
105
|
+
user.set_email_verification_key
|
|
106
|
+
user.save!
|
|
107
|
+
assert !user.is_verified?
|
|
108
|
+
|
|
109
|
+
get :verify_email, :email_verification_key => 'bogus'
|
|
110
|
+
assert_equal 'We were not able to verify your account. Please contact us for assistance.', flash[:alert]
|
|
111
|
+
assert !@controller.logged_in?
|
|
112
|
+
user.reload
|
|
113
|
+
assert !user.is_verified?
|
|
114
|
+
assert_redirected_to root_path
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def test_resend_email_verification
|
|
118
|
+
user = a User
|
|
119
|
+
assert_created user
|
|
120
|
+
user.set_email_verification_key
|
|
121
|
+
user.save!
|
|
122
|
+
assert !user.is_verified?
|
|
123
|
+
|
|
124
|
+
assert_emails 1 do
|
|
125
|
+
get :resend_email_verification, :email_verification_key => user.email_verification_key
|
|
126
|
+
assert_redirected_to login_path
|
|
127
|
+
response = ActionMailer::Base.deliveries.last
|
|
128
|
+
assert_equal 2, response.arguments['content'].length
|
|
129
|
+
response.arguments['content'].each do |content_type, body|
|
|
130
|
+
assert_match assigns(:user).email_verification_key, body
|
|
131
|
+
end
|
|
132
|
+
assert_equal assigns(:user).email, response.to[0]
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def test_destroy
|
|
137
|
+
login_as(:regular_user)
|
|
138
|
+
assert_difference 'User.count', -1 do
|
|
139
|
+
delete :destroy
|
|
140
|
+
end
|
|
141
|
+
assert_equal "Your account has been deleted.", flash[:alert]
|
|
142
|
+
assert_redirected_to root_path
|
|
143
|
+
end
|
|
144
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
|
2
|
+
require File.expand_path('../../config/environment', __FILE__)
|
|
3
|
+
require 'rails/test_help'
|
|
4
|
+
|
|
5
|
+
class ActiveSupport::TestCase
|
|
6
|
+
self.use_transactional_fixtures = true
|
|
7
|
+
self.use_instantiated_fixtures = false
|
|
8
|
+
include ActionMailer::TestHelper
|
|
9
|
+
|
|
10
|
+
def data_path(name)
|
|
11
|
+
File.expand_path(File.join('test', 'data', name), Rails.root)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def assert_created(model)
|
|
15
|
+
assert model
|
|
16
|
+
assert_equal [ ], model.errors.full_messages
|
|
17
|
+
assert model.valid?
|
|
18
|
+
assert !model.new_record?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def assert_not_created(model)
|
|
22
|
+
assert model
|
|
23
|
+
assert model.new_record?
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def assert_errors_on(model, *attrs)
|
|
27
|
+
found_attrs = [ ]
|
|
28
|
+
|
|
29
|
+
model.errors.each do |attr, error|
|
|
30
|
+
found_attrs << attr
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
assert_equal attrs.flatten.collect(&:to_s).sort, found_attrs.uniq.collect(&:to_s).sort
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def assert_mapping(map, &block)
|
|
37
|
+
result_map = map.inject({ }) do |h, (k,v)|
|
|
38
|
+
h[k] = yield(k)
|
|
39
|
+
h
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
differences = result_map.inject([ ]) do |a, (k,v)|
|
|
43
|
+
if (v != map[k])
|
|
44
|
+
a << k
|
|
45
|
+
end
|
|
46
|
+
a
|
|
47
|
+
end
|
|
48
|
+
assert_equal map, result_map, "Difference: #{map.slice(*differences).inspect} vs #{result_map.slice(*differences).inspect}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def login_as(obj)
|
|
52
|
+
case obj
|
|
53
|
+
when String
|
|
54
|
+
user = a User
|
|
55
|
+
user.update_attribute(:role, obj)
|
|
56
|
+
when Symbol
|
|
57
|
+
user = a User
|
|
58
|
+
user.update_attribute(:role, obj.to_s)
|
|
59
|
+
when User
|
|
60
|
+
user = obj
|
|
61
|
+
else
|
|
62
|
+
raise "Please specifuy either a User or a role: #{obj.class.to_s}"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
session[:user_id] = user.id
|
|
66
|
+
token = Wristband::Support.encrypt_with_salt(user.id.to_s, Time.now.to_f.to_s)
|
|
67
|
+
cookies[:login_token] = {
|
|
68
|
+
:value => token,
|
|
69
|
+
:expires => 2.weeks.from_now.utc
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
user
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def assert_exception_raised(exception_class = nil, error_message = nil, &block)
|
|
76
|
+
exception_raised = nil
|
|
77
|
+
yield
|
|
78
|
+
rescue => exception_raised
|
|
79
|
+
ensure
|
|
80
|
+
if exception_raised
|
|
81
|
+
if exception_class
|
|
82
|
+
assert_equal exception_class, exception_raised.class, exception_raised.to_s
|
|
83
|
+
else
|
|
84
|
+
assert true
|
|
85
|
+
end
|
|
86
|
+
assert_equal error_message, exception_raised.to_s if error_message
|
|
87
|
+
else
|
|
88
|
+
flunk 'Exception was not raised'
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class AddressTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
def test_create_defaults
|
|
6
|
+
address = Address.new(
|
|
7
|
+
:address => '123 Fake St',
|
|
8
|
+
:city => 'Burlington',
|
|
9
|
+
:state => 'Vermont'
|
|
10
|
+
)
|
|
11
|
+
assert address.valid?
|
|
12
|
+
assert_equal address.address, '123 Fake St'
|
|
13
|
+
assert_equal address.city, 'Burlington'
|
|
14
|
+
assert_equal address.state, 'Vermont'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_create_requirements
|
|
18
|
+
address = Address.new
|
|
19
|
+
assert !address.valid?
|
|
20
|
+
assert_errors_on address, :address, :city, :state
|
|
21
|
+
assert address.errors[:address].include?("Please enter your address")
|
|
22
|
+
assert address.errors[:city].include?("Please enter your address")
|
|
23
|
+
assert address.errors[:state].include?("Please enter your address")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class AreaActivityTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
def test_create_dummy
|
|
6
|
+
activity = an AreaActivity
|
|
7
|
+
assert_created activity
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_activity_tracking_for_memberships
|
|
11
|
+
# Memberships
|
|
12
|
+
assert_difference 'AreaActivity.count', 1 do
|
|
13
|
+
@membership = Membership.create_dummy
|
|
14
|
+
assert_equal 1, @membership.area.activities.first.new_users_count
|
|
15
|
+
end
|
|
16
|
+
assert_no_difference 'AreaActivity.count' do
|
|
17
|
+
@membership.destroy
|
|
18
|
+
assert_equal 1, @membership.area.activities.first.quitters_count
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_activity_tracking_for_posts
|
|
23
|
+
# Posts
|
|
24
|
+
assert_difference ['Post.count', 'AreaActivity.count'], 1 do
|
|
25
|
+
post = Post.create_dummy
|
|
26
|
+
assert_equal 1, post.area.activities.first.new_posts_count
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_activity_tracking_for_issues
|
|
31
|
+
# Create an area
|
|
32
|
+
area = an Area
|
|
33
|
+
assert_created area
|
|
34
|
+
assert area.send_mode?(:immediate)
|
|
35
|
+
|
|
36
|
+
# Create en issue
|
|
37
|
+
assert_difference ['Post.count', 'Issue.count', 'AreaActivity.count'], 1 do
|
|
38
|
+
assert_emails 1 do
|
|
39
|
+
post = area.posts.create_dummy
|
|
40
|
+
assert_created post
|
|
41
|
+
assert_nil area.current_issue
|
|
42
|
+
assert_equal 1, area.activities.first.issues_published_count
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_activity_tracking_for_nonexistent_field
|
|
48
|
+
area = an Area
|
|
49
|
+
assert_created area
|
|
50
|
+
assert_exception_raised nil, "Cannot find field in the list of trackable fields. Currently tracking: #{AreaActivity::TRACKABLE.join(', ')}" do
|
|
51
|
+
assert_no_difference 'AreaActivity.count' do
|
|
52
|
+
area.record_activity_for!(:blah)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class AreaTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
def test_create_defaults
|
|
6
|
+
area = Area.create(
|
|
7
|
+
:name => 'Test Area'
|
|
8
|
+
)
|
|
9
|
+
assert_created area
|
|
10
|
+
assert_equal 'immediate', area.send_mode
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_create_requirements
|
|
14
|
+
area = Area.create
|
|
15
|
+
assert_errors_on area, :name
|
|
16
|
+
Area.create(:name => 'Test NF', :slug => 'test-nf')
|
|
17
|
+
assert_no_difference 'Area.count' do
|
|
18
|
+
['test-nf', 'test nf', 'test#NF'].each do |slug|
|
|
19
|
+
area = Area.create(:name => 'Test NF 2', :slug => slug)
|
|
20
|
+
assert_errors_on area, :slug
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_create_dummy
|
|
26
|
+
area = an Area
|
|
27
|
+
assert_created area
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_cascade_deletions
|
|
31
|
+
area = an Area
|
|
32
|
+
assert_created area
|
|
33
|
+
membership = area.memberships.create_dummy
|
|
34
|
+
assert_created membership
|
|
35
|
+
post = area.posts.create_dummy
|
|
36
|
+
assert_created post
|
|
37
|
+
# Note: Creating a membership and post will also create an AreaActivity,
|
|
38
|
+
# so no need to create that separately.
|
|
39
|
+
area.reload
|
|
40
|
+
assert_difference ['Area.count', 'Membership.count', 'Post.count', 'Issue.count', 'AreaActivity.count'], -1 do
|
|
41
|
+
area.destroy
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_record_activity_for
|
|
46
|
+
area = an Area
|
|
47
|
+
assert_equal 0, area.activities.count
|
|
48
|
+
assert_difference 'AreaActivity.count', 1 do
|
|
49
|
+
activity = area.record_activity_for!(:quitters)
|
|
50
|
+
assert_equal 1, activity.quitters_count
|
|
51
|
+
end
|
|
52
|
+
assert_no_difference 'AreaActivity.count' do
|
|
53
|
+
activity = area.record_activity_for!(:quitters)
|
|
54
|
+
assert_equal 2, activity.quitters_count
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_check_send_mode_change
|
|
59
|
+
area = Area.create_dummy(:send_mode => 'batched')
|
|
60
|
+
assert_created area
|
|
61
|
+
assert area.send_mode?(:batched)
|
|
62
|
+
|
|
63
|
+
posts = []
|
|
64
|
+
# Create 5 posts
|
|
65
|
+
assert_difference 'Post.count', 5 do
|
|
66
|
+
assert_difference 'Issue.count' do
|
|
67
|
+
assert_emails 0 do
|
|
68
|
+
1.upto(5){ posts << area.posts.create_dummy }
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
assert_not_nil area.current_issue
|
|
73
|
+
assert area.current_issue.posts.empty?
|
|
74
|
+
|
|
75
|
+
# Assign the first 2 posts to the current issue
|
|
76
|
+
0.upto(1){ |i| posts[i].update_attribute(:issue_id, area.current_issue.id) }
|
|
77
|
+
area.current_issue.reload
|
|
78
|
+
assert_equal 2, area.current_issue.posts.length
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
assert_no_difference 'Post.count' do
|
|
82
|
+
assert_difference 'Issue.count', 4 do
|
|
83
|
+
assert_emails 5 do
|
|
84
|
+
area.send_mode = 'immediate'
|
|
85
|
+
area.save!
|
|
86
|
+
assert area.send_mode?(:immediate)
|
|
87
|
+
assert_nil area.current_issue
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class IssueNumberTest < ActiveSupport::TestCase
|
|
4
|
+
def test_defaults
|
|
5
|
+
assert_difference ['Area.count', 'IssueNumber.count'] do
|
|
6
|
+
area = an Area
|
|
7
|
+
assert_created area
|
|
8
|
+
assert_created area.issue_number
|
|
9
|
+
|
|
10
|
+
assert_equal 0, area.issue_number.current
|
|
11
|
+
assert_equal 1, area.issue_number.next
|
|
12
|
+
assert_equal 1, area.issue_number.current
|
|
13
|
+
assert_equal 2, area.issue_number.next
|
|
14
|
+
assert_equal 2, area.issue_number.current
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_cascade_deletions
|
|
19
|
+
area = an Area
|
|
20
|
+
assert_difference ['Area.count', 'IssueNumber.count'], -1 do
|
|
21
|
+
area.destroy
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class IssueTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
def test_create_defaults
|
|
6
|
+
area = an Area
|
|
7
|
+
issue = Issue.create(
|
|
8
|
+
:area => area,
|
|
9
|
+
:scheduled_at => 2.days.from_now
|
|
10
|
+
)
|
|
11
|
+
assert_equal 1, issue.number
|
|
12
|
+
assert_created issue
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_create_requirements
|
|
16
|
+
issue = Issue.create(:scheduled_at => 2.days.ago)
|
|
17
|
+
assert_errors_on issue, :area_id, :scheduled_at
|
|
18
|
+
assert issue.errors[:scheduled_at].include?("can't be in the past.")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_create_dummy
|
|
22
|
+
issue = an Issue
|
|
23
|
+
assert_created issue
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_cascade_deletions
|
|
27
|
+
post = a Post
|
|
28
|
+
assert_created post
|
|
29
|
+
assert post.issue.is_a?(Issue)
|
|
30
|
+
post.reload
|
|
31
|
+
assert_difference ['Post.count', 'Issue.count'], -1 do
|
|
32
|
+
post.issue.destroy
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_send_in_immediate_mode!
|
|
37
|
+
# Create an area
|
|
38
|
+
area = an Area
|
|
39
|
+
assert_created area
|
|
40
|
+
assert area.send_mode?(:immediate)
|
|
41
|
+
|
|
42
|
+
# Create en issue
|
|
43
|
+
assert_difference ['Post.count', 'Issue.count'], 1 do
|
|
44
|
+
assert_emails 1 do
|
|
45
|
+
post = area.posts.create_dummy
|
|
46
|
+
assert_created post
|
|
47
|
+
assert_nil area.current_issue
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_send_in_batched_mode!
|
|
53
|
+
# Create an area
|
|
54
|
+
area = Area.create_dummy(:send_mode => 'batched')
|
|
55
|
+
assert_created area
|
|
56
|
+
assert area.send_mode?(:batched)
|
|
57
|
+
|
|
58
|
+
# Create an issue
|
|
59
|
+
issue = area.issues.create_dummy
|
|
60
|
+
assert_created issue
|
|
61
|
+
assert_nil issue.sent_at
|
|
62
|
+
assert_equal issue, area.current_issue
|
|
63
|
+
|
|
64
|
+
# Add two posts to the area
|
|
65
|
+
post_1 = area.posts.create_dummy
|
|
66
|
+
assert_created post_1
|
|
67
|
+
assert_equal post_1.area, area
|
|
68
|
+
|
|
69
|
+
post_2 = area.posts.create_dummy
|
|
70
|
+
assert_created post_2
|
|
71
|
+
assert_equal post_2.area, area
|
|
72
|
+
|
|
73
|
+
assert_equal [post_1, post_2], area.posts.order(:id)
|
|
74
|
+
assert_equal [], area.posts.in_issue(issue)
|
|
75
|
+
assert_equal [post_1, post_2], area.posts.in_issue(nil).order(:id)
|
|
76
|
+
|
|
77
|
+
# Add one post to the issue
|
|
78
|
+
post_1.update_attribute(:issue_id, issue.id)
|
|
79
|
+
area.reload
|
|
80
|
+
assert_equal [post_1], area.posts.in_issue(issue)
|
|
81
|
+
assert_equal [post_2], area.posts.in_issue(nil)
|
|
82
|
+
|
|
83
|
+
# Send the issue
|
|
84
|
+
assert_emails 1 do
|
|
85
|
+
# Another issue should be created
|
|
86
|
+
assert_difference 'Issue.count' do
|
|
87
|
+
issue.send!
|
|
88
|
+
assert issue.sent_at.is_a?(Time)
|
|
89
|
+
area = Area.find(area.id)
|
|
90
|
+
assert_not_equal issue, area.current_issue
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
issue = area.current_issue
|
|
95
|
+
assert_equal [], area.posts.in_issue(issue)
|
|
96
|
+
assert_equal [post_2], area.posts.in_issue(nil)
|
|
97
|
+
|
|
98
|
+
# Add the second post to the issue
|
|
99
|
+
post_2.update_attribute(:issue_id, issue.id)
|
|
100
|
+
area.reload
|
|
101
|
+
assert_equal [post_2], area.posts.in_issue(issue)
|
|
102
|
+
assert_equal [], area.posts.in_issue(nil)
|
|
103
|
+
|
|
104
|
+
# Send the second issue
|
|
105
|
+
assert_emails 1 do
|
|
106
|
+
# No new issue should be created
|
|
107
|
+
assert_no_difference 'Issue.count' do
|
|
108
|
+
issue.send!
|
|
109
|
+
assert issue.sent_at.is_a?(Time)
|
|
110
|
+
area = Area.find(area.id)
|
|
111
|
+
assert_nil area.current_issue
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def test_issue_number
|
|
117
|
+
# Create one area
|
|
118
|
+
area = an Area
|
|
119
|
+
assert_created area
|
|
120
|
+
|
|
121
|
+
# Add an issue
|
|
122
|
+
issue = area.issues.create_dummy
|
|
123
|
+
assert_created issue
|
|
124
|
+
area.reload
|
|
125
|
+
assert_equal 1, issue.number
|
|
126
|
+
assert_equal 1, area.issue_number.current
|
|
127
|
+
|
|
128
|
+
# Add another issue
|
|
129
|
+
issue = area.issues.create_dummy
|
|
130
|
+
assert_created issue
|
|
131
|
+
area.reload
|
|
132
|
+
assert_equal 2, issue.number
|
|
133
|
+
assert_equal 2, area.issue_number.current
|
|
134
|
+
|
|
135
|
+
# Create another area
|
|
136
|
+
area = an Area
|
|
137
|
+
assert_created area
|
|
138
|
+
|
|
139
|
+
# Add an issue
|
|
140
|
+
issue = area.issues.create_dummy
|
|
141
|
+
assert_created issue
|
|
142
|
+
area.reload
|
|
143
|
+
assert_equal 1, issue.number
|
|
144
|
+
assert_equal 1, area.issue_number.current
|
|
145
|
+
|
|
146
|
+
# Add another issue
|
|
147
|
+
issue = area.issues.create_dummy
|
|
148
|
+
assert_created issue
|
|
149
|
+
area.reload
|
|
150
|
+
assert_equal 2, issue.number
|
|
151
|
+
assert_equal 2, area.issue_number.current
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class MembershipTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
def test_validations
|
|
6
|
+
# Uniqueness
|
|
7
|
+
membership = Membership.create_dummy
|
|
8
|
+
assert_created membership
|
|
9
|
+
membership = membership.clone
|
|
10
|
+
membership.save
|
|
11
|
+
assert_not_created membership
|
|
12
|
+
assert membership.errors[:user_id].include?("has already been taken")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_create_dummy
|
|
16
|
+
membership = Membership.create_dummy
|
|
17
|
+
assert_created membership
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class PostTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
def test_create_defaults
|
|
6
|
+
assert_difference ['Post.count', 'Issue.count'], 1 do
|
|
7
|
+
post = Post.create(
|
|
8
|
+
:title => 'Test Post',
|
|
9
|
+
:content => 'Lorem ipsum dolor sit amet',
|
|
10
|
+
:user => (a User),
|
|
11
|
+
:area => (an Area)
|
|
12
|
+
)
|
|
13
|
+
assert post.area.send_mode?(:immediate)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_create_requirements
|
|
18
|
+
post = Post.create
|
|
19
|
+
assert_errors_on post, :title, :content, :user_id, :area_id, :user_first_name,
|
|
20
|
+
:user_last_name, :user_email, :user_address, :user_city,
|
|
21
|
+
:user_state
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_create_dummy
|
|
25
|
+
area = Area.create_dummy(:send_mode => 'batched')
|
|
26
|
+
assert_created area
|
|
27
|
+
assert area.send_mode?(:batched)
|
|
28
|
+
assert area.issues.empty?
|
|
29
|
+
|
|
30
|
+
# Creating the first post will also create an issue
|
|
31
|
+
assert_difference ['Post.count', 'Issue.count'] do
|
|
32
|
+
assert_emails 0 do
|
|
33
|
+
post = area.posts.create_dummy
|
|
34
|
+
assert_created post
|
|
35
|
+
assert_equal post.area.id, area.id
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# The second post will NOT create a new issue
|
|
40
|
+
assert_difference 'Post.count' do
|
|
41
|
+
assert_no_difference 'Issue.count' do
|
|
42
|
+
assert_emails 0 do
|
|
43
|
+
post = area.posts.create_dummy
|
|
44
|
+
assert_created post
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_send_immediatelly
|
|
51
|
+
area = Area.create_dummy(:send_mode => 'batched')
|
|
52
|
+
assert_created area
|
|
53
|
+
assert area.send_mode?(:batched)
|
|
54
|
+
|
|
55
|
+
post = nil
|
|
56
|
+
assert_difference ['Post.count', 'Issue.count'] do
|
|
57
|
+
assert_emails 0 do
|
|
58
|
+
post = area.posts.create_dummy
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
assert_difference 'Issue.count' do
|
|
63
|
+
assert_emails 1 do
|
|
64
|
+
post.send_immediatelly!
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
end
|