parlement 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +709 -0
- data/COPYING +223 -0
- data/README +20 -0
- data/Rakefile +136 -0
- data/app/controllers/account_controller.rb +181 -0
- data/app/controllers/application.rb +30 -0
- data/app/controllers/elt_controller.rb +83 -0
- data/app/helpers/account_helper.rb +2 -0
- data/app/helpers/application_helper.rb +4 -0
- data/app/helpers/elt_helper.rb +37 -0
- data/app/helpers/live_tree.rb +238 -0
- data/app/helpers/mailman.rb +96 -0
- data/app/models/attachment.rb +4 -0
- data/app/models/elt.rb +17 -0
- data/app/models/mail.rb +4 -0
- data/app/models/notifier.rb +13 -0
- data/app/models/person.rb +9 -0
- data/app/models/user.rb +7 -0
- data/app/models/user_notify.rb +75 -0
- data/app/views/account/_help.rhtml +23 -0
- data/app/views/account/_login.rhtml +57 -0
- data/app/views/account/_show.rhtml +31 -0
- data/app/views/account/logout.rhtml +10 -0
- data/app/views/account/signup.rhtml +17 -0
- data/app/views/account/welcome.rhtml +13 -0
- data/app/views/elt/_elt.rhtml +105 -0
- data/app/views/elt/_form.rhtml +31 -0
- data/app/views/elt/_list.rhtml +28 -0
- data/app/views/elt/new.rhtml +102 -0
- data/app/views/elt/rss.rxml +31 -0
- data/app/views/elt/show.rhtml +46 -0
- data/app/views/elt/show_tree.rhtml +8 -0
- data/app/views/layouts/scaffold.rhtml +13 -0
- data/app/views/layouts/top.rhtml +45 -0
- data/app/views/notifier/changeEmail.rhtml +10 -0
- data/config/boot.rb +17 -0
- data/config/database.yml +82 -0
- data/config/environment.rb +92 -0
- data/config/environments/development.rb +17 -0
- data/config/environments/production.rb +17 -0
- data/config/environments/test.rb +17 -0
- data/config/environments/user_environment.rb +1 -0
- data/config/routes.rb +28 -0
- data/db/ROOT/CV.txt +166 -0
- data/db/ROOT/IP.txt +3 -0
- data/db/ROOT/parleR.txt +3 -0
- data/db/ROOT/parlement/security.txt +34 -0
- data/db/ROOT/parlement/test.txt +4 -0
- data/db/ROOT/parlement.txt +51 -0
- data/db/ROOT/perso.txt +215 -0
- data/db/schema.sql +127 -0
- data/lib/data_import.rb +54 -0
- data/lib/file_column.rb +263 -0
- data/lib/file_column_helper.rb +45 -0
- data/lib/localization.rb +88 -0
- data/lib/localizer.rb +88 -0
- data/lib/login_system.rb +87 -0
- data/lib/rails_file_column.rb +19 -0
- data/lib/user_system.rb +101 -0
- data/public/404.html +8 -0
- data/public/500.html +8 -0
- data/public/dispatch.cgi +10 -0
- data/public/dispatch.fcgi +24 -0
- data/public/dispatch.rb +10 -0
- data/public/engine_files/README +5 -0
- data/public/engine_files/login_engine/stylesheets/login_engine.css +81 -0
- data/public/favicon.ico +0 -0
- data/public/favicon.png +0 -0
- data/public/images/live_tree_branch_collapsed_icon.gif +0 -0
- data/public/images/live_tree_branch_expanded_icon.gif +0 -0
- data/public/images/live_tree_leaf_icon.gif +0 -0
- data/public/images/live_tree_loading_spinner.gif +0 -0
- data/public/images/webfeed.gif +0 -0
- data/public/javascripts/controls.js +721 -0
- data/public/javascripts/dragdrop.js +519 -0
- data/public/javascripts/effects.js +992 -0
- data/public/javascripts/live_tree.js +749 -0
- data/public/javascripts/prototype.js +1726 -0
- data/public/javascripts/scriptaculous.js +47 -0
- data/public/javascripts/slider.js +258 -0
- data/public/oldREADME +190 -0
- data/public/oldindex.html +78 -0
- data/public/robots.txt +1 -0
- data/public/stylesheets/default.css +238 -0
- data/public/stylesheets/live_tree.css +62 -0
- data/public/stylesheets/scaffold.css +74 -0
- data/script/about +3 -0
- data/script/benchmarker +19 -0
- data/script/breakpointer +3 -0
- data/script/console +3 -0
- data/script/create_db +7 -0
- data/script/destroy +3 -0
- data/script/generate +3 -0
- data/script/performance/benchmarker +3 -0
- data/script/performance/profiler +3 -0
- data/script/plugin +3 -0
- data/script/process/reaper +3 -0
- data/script/process/spawner +3 -0
- data/script/process/spinner +3 -0
- data/script/profiler +34 -0
- data/script/runner +3 -0
- data/script/server +3 -0
- data/test/fixtures/attachments.yml +10 -0
- data/test/fixtures/elts.yml +15 -0
- data/test/fixtures/mails.yml +7 -0
- data/test/fixtures/people.yml +49 -0
- data/test/fixtures/users.yml +41 -0
- data/test/functional/account_controller_test.rb +239 -0
- data/test/functional/elt_controller_test.rb +18 -0
- data/test/mocks/test/time.rb +17 -0
- data/test/mocks/test/user_notify.rb +16 -0
- data/test/test_helper.rb +28 -0
- data/test/unit/attachment_test.rb +14 -0
- data/test/unit/elt_test.rb +14 -0
- data/test/unit/mail_test.rb +14 -0
- data/test/unit/notifier_test.rb +31 -0
- data/test/unit/person_test.rb +24 -0
- data/test/unit/user_test.rb +94 -0
- data/vendor/plugins/engines/CHANGELOG +7 -0
- data/vendor/plugins/engines/README +128 -0
- data/vendor/plugins/engines/init.rb +33 -0
- data/vendor/plugins/engines/lib/action_mailer_extensions.rb +160 -0
- data/vendor/plugins/engines/lib/action_view_extensions.rb +130 -0
- data/vendor/plugins/engines/lib/dependencies_extensions.rb +56 -0
- data/vendor/plugins/engines/lib/engines.rb +292 -0
- data/vendor/plugins/engines/lib/ruby_extensions.rb +127 -0
- data/vendor/plugins/engines/lib/testing_extensions.rb +33 -0
- data/vendor/plugins/engines/test/ruby_extensions_test.rb +94 -0
- data/vendor/plugins/login_engine/README +258 -0
- data/vendor/plugins/login_engine/app/controllers/user_controller.rb +248 -0
- data/vendor/plugins/login_engine/app/helpers/user_helper.rb +88 -0
- data/vendor/plugins/login_engine/app/models/user.rb +7 -0
- data/vendor/plugins/login_engine/app/models/user_notify.rb +75 -0
- data/vendor/plugins/login_engine/app/views/user/_edit.rhtml +11 -0
- data/vendor/plugins/login_engine/app/views/user/_password.rhtml +9 -0
- data/vendor/plugins/login_engine/app/views/user/change_password.rhtml +17 -0
- data/vendor/plugins/login_engine/app/views/user/edit.rhtml +23 -0
- data/vendor/plugins/login_engine/app/views/user/forgot_password.rhtml +18 -0
- data/vendor/plugins/login_engine/app/views/user/home.rhtml +7 -0
- data/vendor/plugins/login_engine/app/views/user/login.rhtml +17 -0
- data/vendor/plugins/login_engine/app/views/user/logout.rhtml +8 -0
- data/vendor/plugins/login_engine/app/views/user/signup.rhtml +17 -0
- data/vendor/plugins/login_engine/app/views/user_notify/change_password.rhtml +10 -0
- data/vendor/plugins/login_engine/app/views/user_notify/delete.rhtml +5 -0
- data/vendor/plugins/login_engine/app/views/user_notify/forgot_password.rhtml +11 -0
- data/vendor/plugins/login_engine/app/views/user_notify/pending_delete.rhtml +9 -0
- data/vendor/plugins/login_engine/app/views/user_notify/signup.rhtml +12 -0
- data/vendor/plugins/login_engine/db/schema.rb +25 -0
- data/vendor/plugins/login_engine/init_engine.rb +10 -0
- data/vendor/plugins/login_engine/lib/login_engine/authenticated_system.rb +107 -0
- data/vendor/plugins/login_engine/lib/login_engine/authenticated_user.rb +149 -0
- data/vendor/plugins/login_engine/lib/login_engine.rb +58 -0
- data/vendor/plugins/login_engine/public/stylesheets/login_engine.css +81 -0
- data/vendor/plugins/login_engine/tasks/tasks.rake +4 -0
- data/vendor/plugins/login_engine/test/fixtures/templates/users.yml +41 -0
- data/vendor/plugins/login_engine/test/fixtures/users.yml +41 -0
- data/vendor/plugins/login_engine/test/functional/user_controller_test.rb +533 -0
- data/vendor/plugins/login_engine/test/mocks/mail.rb +14 -0
- data/vendor/plugins/login_engine/test/mocks/time.rb +19 -0
- data/vendor/plugins/login_engine/test/test_helper.rb +15 -0
- data/vendor/plugins/login_engine/test/unit/user_test.rb +94 -0
- metadata +276 -0
@@ -0,0 +1,239 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require_dependency 'account_controller'
|
3
|
+
require 'breakpoint'
|
4
|
+
|
5
|
+
# ADD to fix advance_by_days= problem
|
6
|
+
require File.dirname(__FILE__) + '/../mocks/test/time'
|
7
|
+
|
8
|
+
# Raise errors beyond the default web-based presentation
|
9
|
+
class AccountController; def rescue_action(e) raise e end; end
|
10
|
+
|
11
|
+
class AccountControllerTest < Test::Unit::TestCase
|
12
|
+
|
13
|
+
fixtures :people, LoginEngine.config(:user_table).to_sym
|
14
|
+
|
15
|
+
def setup
|
16
|
+
LoginEngine::CONFIG[:salt] = "test-salt"
|
17
|
+
|
18
|
+
@controller = AccountController.new
|
19
|
+
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
|
20
|
+
@request.host = "localhost"
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
""" _ _
|
25
|
+
_ __ ___ ___ _ _ __| | ___ ___ _ __ | |_ _
|
26
|
+
| '_ \/ __|/ _ \ | | |/ _` |/ _ \ / _ \| '_ \| | | | |
|
27
|
+
| |_) \__ \ __/ |_| | (_| | (_) | | (_) | | | | | |_| |
|
28
|
+
| .__/|___/\___|\__,_|\__,_|\___/ \___/|_| |_|_|\__, |
|
29
|
+
|_| |___/
|
30
|
+
"""
|
31
|
+
def test_signup
|
32
|
+
post :login, :person => { :name => "my_bob", :email => "" },
|
33
|
+
:user => { :password => "" }
|
34
|
+
assert_session_has :person
|
35
|
+
assert_session_has_no :user
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_login_logoff_no_password
|
39
|
+
post :login, :person => { :name => "bob_other", :email => "" },
|
40
|
+
:user => { :password => "" }
|
41
|
+
assert_equal people(:bob_other), @request.session[:person]
|
42
|
+
assert_session_has_no :user
|
43
|
+
get :logout
|
44
|
+
assert_session_has_no :person
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_bad_pseudo
|
48
|
+
post :login, :person => { :name => "yo", :email => "" },
|
49
|
+
:user => { :password => "" }
|
50
|
+
assert_invalid_column_on_record "person", :name
|
51
|
+
assert_success
|
52
|
+
assert_session_has_no :person
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
""" _
|
57
|
+
_ __ __ _ ___ _____ _____ _ __ __| |
|
58
|
+
| '_ \ / _` / __/ __\ \ /\ / / _ \| '__/ _` |
|
59
|
+
| |_) | (_| \__ \__ \\ V V / (_) | | | (_| |
|
60
|
+
| .__/ \__,_|___/___/ \_/\_/ \___/|_| \__,_|
|
61
|
+
|_|
|
62
|
+
"""
|
63
|
+
def test_password_protect
|
64
|
+
post :login, :person => { :name => "bob_another", :email => "" },
|
65
|
+
:user => { :password => "atest" }
|
66
|
+
assert_session_has :person
|
67
|
+
assert_session_has :user
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_auth_bob
|
71
|
+
post :login, :person => { :name => "bob", :email => "" },
|
72
|
+
:user => { :password => "atest" }
|
73
|
+
assert_equal people(:bob), @response.session[:person]
|
74
|
+
assert_session_has :person
|
75
|
+
assert_session_has :user
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_bad_password
|
79
|
+
post :login, :person => { :name => "newbob", :email => "" },
|
80
|
+
:user => { :password => "newpassword", :password_confirmation => "wrong" }
|
81
|
+
assert_invalid_column_on_record "user", :password
|
82
|
+
assert_success
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_login_logoff_password
|
86
|
+
post :login, :person => { :name => "my_bob", :email => "" },
|
87
|
+
:user => { :password => "my_bob" }
|
88
|
+
assert_session_has :person
|
89
|
+
get :logout
|
90
|
+
assert_session_has_no :person
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_invalid_password
|
94
|
+
post :login, :person => { :name => "my_bob", :email => "" },
|
95
|
+
:user => { :password => "my_bob" }
|
96
|
+
assert_session_has :person
|
97
|
+
assert_session_has :user
|
98
|
+
get :logout
|
99
|
+
post :login, :person => { :name => "my_bob", :email => "" },
|
100
|
+
:user => { :password => "my_bo" }
|
101
|
+
assert_session_has_no :person
|
102
|
+
assert_session_has_no :user
|
103
|
+
#assert_template_has "login"
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
""" _ _
|
108
|
+
___ _ __ ___ __ _(_) |
|
109
|
+
/ _ \ '_ ` _ \ / _` | | |
|
110
|
+
| __/ | | | | | (_| | | |
|
111
|
+
\___|_| |_| |_|\__,_|_|_|
|
112
|
+
"""
|
113
|
+
def test_password_and_email_protect
|
114
|
+
post :login, :person => { :name => "my_bob", :email => "manu@noos.fr" },
|
115
|
+
:user => { :password => "my_bob" }
|
116
|
+
assert_session_has :person
|
117
|
+
assert_session_has :user
|
118
|
+
assert_equal "my_bob", @request.session[:person].name
|
119
|
+
assert_equal "manu@noos.fr", @request.session[:user].email
|
120
|
+
assert_not_equal @request.session[:person].email, @request.session[:user].email
|
121
|
+
assert_not_nil @request.session[:user].security_token
|
122
|
+
end
|
123
|
+
|
124
|
+
def invalid_email
|
125
|
+
post :login, :person => { :name => "bob", :email => "" },
|
126
|
+
:user => { :password => "not_correct" }
|
127
|
+
|
128
|
+
assert_session_has_no :person
|
129
|
+
assert_session_has_no :user
|
130
|
+
|
131
|
+
assert_template_has "login"
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
def test_email_protect
|
136
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
137
|
+
|
138
|
+
ActionMailer::Base.deliveries = []
|
139
|
+
|
140
|
+
#@request.session['return-to'] = "/bogus/location"
|
141
|
+
|
142
|
+
assert_equal 5, User.count
|
143
|
+
post :login, :person => { :name => "newbob", :email => "newbob@test.com" },
|
144
|
+
:user => { :password => "newpassword" }
|
145
|
+
assert_session_has :person
|
146
|
+
assert_session_has :user
|
147
|
+
assert_equal 6, User.count
|
148
|
+
|
149
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
150
|
+
mail = ActionMailer::Base.deliveries[0]
|
151
|
+
assert_equal "newbob@test.com", mail.to_addrs[0].to_s
|
152
|
+
assert_match /login:\s+\w+\n/, mail.encoded
|
153
|
+
assert_match /password:\s+\w+\n/, mail.encoded
|
154
|
+
mail.encoded =~ /key=(.*?)"/
|
155
|
+
key = $1
|
156
|
+
|
157
|
+
user = User.find_by_email("newbob@test.com")
|
158
|
+
person = Person.find_by_name(user.login)
|
159
|
+
assert_not_nil user
|
160
|
+
assert_not_nil person
|
161
|
+
assert_equal 1, user.verified
|
162
|
+
assert_not_equal user.email, person.email
|
163
|
+
|
164
|
+
# First past the expiration.
|
165
|
+
Time.advance_by_days = 1
|
166
|
+
get :check_key, :user=> { :id => "#{user.id}" }, :key => "#{key}"
|
167
|
+
Time.advance_by_days = 0
|
168
|
+
user = User.find_by_email("newbob@test.com")
|
169
|
+
person = Person.find_by_name(user.login)
|
170
|
+
assert_not_equal user.email, person.email
|
171
|
+
|
172
|
+
# Then a bogus key.
|
173
|
+
get :check_key, :user=> { :id => "#{user.id}" }, :key => "boguskey"
|
174
|
+
user = User.find_by_email("newbob@test.com")
|
175
|
+
person = Person.find_by_name(user.login) if user != nil
|
176
|
+
assert_not_equal user.email, person.email
|
177
|
+
|
178
|
+
# Now the real one.
|
179
|
+
get :check_key, :user=> { :id => "#{user.id}" }, :key => "#{key}"
|
180
|
+
user = User.find_by_email("newbob@test.com")
|
181
|
+
person = Person.find_by_name(user.login)
|
182
|
+
assert_equal user.email, person.email
|
183
|
+
|
184
|
+
post :login, :person => { :name => "newbob", :email => "" },
|
185
|
+
:user => { :password => "newpassword" }
|
186
|
+
assert_session_has :person
|
187
|
+
assert_session_has :user
|
188
|
+
get :logout
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_forgotten_password
|
192
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
193
|
+
|
194
|
+
ActionMailer::Base.deliveries = []
|
195
|
+
|
196
|
+
post :login, :person => { :name => "bob", :email => "bob@test.com" },
|
197
|
+
:user => { :password => "" }
|
198
|
+
assert_session_has_no :person
|
199
|
+
assert_session_has_no :user
|
200
|
+
|
201
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
202
|
+
mail = ActionMailer::Base.deliveries[0]
|
203
|
+
assert_equal "bob@test.com", mail.to_addrs[0].to_s
|
204
|
+
mail.encoded =~ /key=(.*?)"/
|
205
|
+
key = $1
|
206
|
+
|
207
|
+
# First past the expiration.
|
208
|
+
Time.advance_by_days = 1
|
209
|
+
post :login, :person => { :name => "bob", :email => key },
|
210
|
+
:user => { :password => "newpassword" }
|
211
|
+
assert_session_has_no :person
|
212
|
+
assert_session_has_no :user
|
213
|
+
Time.advance_by_days = 0
|
214
|
+
|
215
|
+
# Then a bogus key.
|
216
|
+
post :login, :person => { :name => "bob", :email => "boguskey" },
|
217
|
+
:user => { :password => "newpassword" }
|
218
|
+
assert_session_has_no :person
|
219
|
+
assert_session_has_no :user
|
220
|
+
|
221
|
+
# Now the real one.
|
222
|
+
post :login, :person => { :name => "bob", :email => key },
|
223
|
+
:user => { :password => "newpassword" }
|
224
|
+
assert_session_has :person
|
225
|
+
assert_session_has :user
|
226
|
+
get :logout
|
227
|
+
|
228
|
+
post :login, :person => { :name => "bob", :email => "" },
|
229
|
+
:user => { :password => "password" }
|
230
|
+
assert_session_has_no :person
|
231
|
+
assert_session_has_no :user
|
232
|
+
post :login, :person => { :name => "bob", :email => "" },
|
233
|
+
:user => { :password => "newpassword" }
|
234
|
+
assert_session_has :person
|
235
|
+
assert_session_has :user
|
236
|
+
get :logout
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require 'elt_controller'
|
3
|
+
|
4
|
+
# Re-raise errors caught by the controller.
|
5
|
+
class EltController; def rescue_action(e) raise e end; end
|
6
|
+
|
7
|
+
class EltControllerTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@controller = EltController.new
|
10
|
+
@request = ActionController::TestRequest.new
|
11
|
+
@response = ActionController::TestResponse.new
|
12
|
+
end
|
13
|
+
|
14
|
+
# Replace this with your real tests.
|
15
|
+
def test_truth
|
16
|
+
assert true
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
Time.class_eval {
|
4
|
+
@@advance_by_days = 0
|
5
|
+
cattr_accessor :advance_by_days
|
6
|
+
|
7
|
+
class << Time
|
8
|
+
alias now_old now
|
9
|
+
def now
|
10
|
+
if Time.advance_by_days != 0
|
11
|
+
return Time.at(now_old.to_i + Time.advance_by_days * 60 * 60 * 24 + 1)
|
12
|
+
else
|
13
|
+
now_old
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'models/user_notify.rb'
|
2
|
+
|
3
|
+
ActionMailer::Base.class_eval {
|
4
|
+
@@inject_one_error = false
|
5
|
+
cattr_accessor :inject_one_error
|
6
|
+
|
7
|
+
private
|
8
|
+
def perform_delivery_test(mail)
|
9
|
+
if inject_one_error
|
10
|
+
ActionMailer::Base::inject_one_error = false
|
11
|
+
raise "Failed to send email" if raise_delivery_errors
|
12
|
+
else
|
13
|
+
deliveries << mail
|
14
|
+
end
|
15
|
+
end
|
16
|
+
}
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
|
+
require 'test_help'
|
4
|
+
|
5
|
+
class Test::Unit::TestCase
|
6
|
+
# Transactional fixtures accelerate your tests by wrapping each test method
|
7
|
+
# in a transaction that's rolled back on completion. This ensures that the
|
8
|
+
# test database remains unchanged so your fixtures don't have to be reloaded
|
9
|
+
# between every test method. Fewer database queries means faster tests.
|
10
|
+
#
|
11
|
+
# Read Mike Clark's excellent walkthrough at
|
12
|
+
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
13
|
+
#
|
14
|
+
# Every Active Record database supports transactions except MyISAM tables
|
15
|
+
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
16
|
+
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
17
|
+
# is recommended.
|
18
|
+
self.use_transactional_fixtures = true
|
19
|
+
|
20
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
21
|
+
# would need people(:david). If you don't want to migrate your existing
|
22
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
23
|
+
# instantiated fixtures translates to a database query per test method),
|
24
|
+
# then set this back to true.
|
25
|
+
self.use_instantiated_fixtures = false
|
26
|
+
|
27
|
+
# Add more helper methods to be used by all tests here...
|
28
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class AttachmentTest < Test::Unit::TestCase
|
4
|
+
fixtures :elts, :attachments, :mails
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@attachment = Attachment.find(0)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Replace this with your real tests.
|
11
|
+
def test_truth
|
12
|
+
assert_kind_of Attachment, @attachment
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class EltTest < Test::Unit::TestCase
|
4
|
+
fixtures :elts, :attachments, :mails
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@elt = Elt.find(1)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Replace this with your real tests.
|
11
|
+
def test_truth
|
12
|
+
assert_kind_of Elt, @elt
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class MailTest < Test::Unit::TestCase
|
4
|
+
fixtures :elts, :mails, :attachments
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@mail = Mail.find(1)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Replace this with your real tests.
|
11
|
+
def test_truth
|
12
|
+
assert_kind_of Mail, @mail
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require 'notifier'
|
3
|
+
|
4
|
+
class NotifierTest < Test::Unit::TestCase
|
5
|
+
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
|
6
|
+
CHARSET = "utf-8"
|
7
|
+
|
8
|
+
include ActionMailer::Quoting
|
9
|
+
|
10
|
+
def setup
|
11
|
+
ActionMailer::Base.delivery_method = :test
|
12
|
+
ActionMailer::Base.perform_deliveries = true
|
13
|
+
ActionMailer::Base.deliveries = []
|
14
|
+
|
15
|
+
@expected = TMail::Mail.new
|
16
|
+
@expected.set_content_type "text", "plain", { "charset" => CHARSET }
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_truth
|
20
|
+
assert true
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def read_fixture(action)
|
25
|
+
IO.readlines("#{FIXTURES_PATH}/notifier/#{action}")
|
26
|
+
end
|
27
|
+
|
28
|
+
def encode(subject)
|
29
|
+
quoted_printable(subject, CHARSET)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class PersonTest < Test::Unit::TestCase
|
4
|
+
fixtures :people, LoginEngine.config(:user_table).to_sym
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@person = Person.find(:first)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Replace this with your real tests.
|
11
|
+
def test_truth
|
12
|
+
assert_kind_of Person, @person
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_collision
|
16
|
+
p = Person.new
|
17
|
+
p.name = "bob10"
|
18
|
+
assert p.save
|
19
|
+
|
20
|
+
p = Person.new
|
21
|
+
p.name = "bob10"
|
22
|
+
assert !p.save
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class UserTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
fixtures :people, LoginEngine.config(:user_table).to_sym
|
6
|
+
|
7
|
+
def setup
|
8
|
+
LoginEngine::CONFIG[:salt] = "test-salt"
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_auth
|
12
|
+
assert_equal fixture_object(LoginEngine.config(:user_table), :bob), User.authenticate("bob", "atest")
|
13
|
+
|
14
|
+
assert_nil User.authenticate("nonbob", "atest")
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def test_passwordchange
|
19
|
+
@longbob = users(:longbob)
|
20
|
+
@longbob.change_password("nonbobpasswd")
|
21
|
+
@longbob.save
|
22
|
+
assert_equal @longbob, User.authenticate("longbob", "nonbobpasswd")
|
23
|
+
assert_nil User.authenticate("longbob", "alongtest")
|
24
|
+
@longbob.change_password("alongtest")
|
25
|
+
@longbob.save
|
26
|
+
assert_equal @longbob, User.authenticate("longbob", "alongtest")
|
27
|
+
assert_nil User.authenticate("longbob", "nonbobpasswd")
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_disallowed_passwords
|
31
|
+
u = User.new
|
32
|
+
u.login = "first"
|
33
|
+
|
34
|
+
u.change_password("tiny")
|
35
|
+
assert !u.save
|
36
|
+
assert u.errors.invalid?('password')
|
37
|
+
|
38
|
+
u.change_password("hugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehuge")
|
39
|
+
assert !u.save
|
40
|
+
assert u.errors.invalid?('password')
|
41
|
+
|
42
|
+
u.change_password("")
|
43
|
+
assert !u.save
|
44
|
+
assert u.errors.invalid?('password')
|
45
|
+
|
46
|
+
u.change_password("bobs_secure_password")
|
47
|
+
assert u.save
|
48
|
+
assert u.errors.empty?
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_bad_logins
|
52
|
+
|
53
|
+
u = User.new
|
54
|
+
u.change_password("bobs_secure_password")
|
55
|
+
|
56
|
+
u.login = "bo"
|
57
|
+
assert !u.save
|
58
|
+
assert u.errors.invalid?('login')
|
59
|
+
|
60
|
+
u.login = "hugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhug"
|
61
|
+
assert !u.save
|
62
|
+
assert u.errors.invalid?('login')
|
63
|
+
|
64
|
+
u.login = ""
|
65
|
+
assert !u.save
|
66
|
+
assert u.errors.invalid?('login')
|
67
|
+
|
68
|
+
u.login = "bob2"
|
69
|
+
assert u.save
|
70
|
+
assert u.errors.empty?
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def test_collision
|
76
|
+
u = User.new
|
77
|
+
u.login = people('bob').name
|
78
|
+
u.change_password("bobs_secure_password")
|
79
|
+
assert !u.save
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def test_create
|
84
|
+
p = Person.new
|
85
|
+
p.name = "otherbob"
|
86
|
+
p.save
|
87
|
+
|
88
|
+
u = User.new
|
89
|
+
u.login = p.name
|
90
|
+
u.change_password("bobs_secure_password")
|
91
|
+
|
92
|
+
assert u.save
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
*SVN*
|
2
|
+
|
3
|
+
- Added preliminary tests for the config() methods module
|
4
|
+
|
5
|
+
- Fixed copyright notices to point to DHH, rather than me.
|
6
|
+
- Moved extension require statements into lib/engines.rb, so the will be loaded if another module/file calls require 'engines
|
7
|
+
- Added a CHANGELOG file (this file)
|
@@ -0,0 +1,128 @@
|
|
1
|
+
= Gentlemen, Start your Engines!
|
2
|
+
|
3
|
+
=== Quickstart
|
4
|
+
|
5
|
+
1. Install the Rails Engines plugin into your plugins directory
|
6
|
+
|
7
|
+
2. Install your engine into the plugins directory (note both of these steps will soon be made somewhat <i>automagic</i> by the new Rails script/plugin command coming in Rails 1.0)
|
8
|
+
|
9
|
+
3. Create the RDoc for the engine so you know what's going on:
|
10
|
+
$ cd vendor/plugins/my_engine
|
11
|
+
$ rake rdoc
|
12
|
+
|
13
|
+
4. Initialize any database schema provided:
|
14
|
+
$ rake db_schema_import # (still within the plugin/my_engine directory)
|
15
|
+
Beware that this might affect any existing database tables you have installed! You are STRONGLY recommended to inspect the <tt>db/schema.rb</tt> file to see exactly what
|
16
|
+
running it might change.
|
17
|
+
|
18
|
+
5. Add configuration to <tt>environment.rb</tt>:
|
19
|
+
e.g.
|
20
|
+
# Add your application configuration here
|
21
|
+
module MyEngine
|
22
|
+
config :top_speed, "MegaTurboFast"
|
23
|
+
end
|
24
|
+
|
25
|
+
Engine.start :my_engine
|
26
|
+
|
27
|
+
6. Run your server!
|
28
|
+
$ script/server
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
= Background
|
33
|
+
Rails Engines are a way of dropping in whole chunks of functionality into your
|
34
|
+
existing application without affecting *any* of your existing code. The could also be described as mini-applications, or vertical application slices - top-to-bottom units which provide full MVC coverage for a certain, specific application function.
|
35
|
+
|
36
|
+
As an example, the Login Engine provides a full user login subsystem, including:
|
37
|
+
* controllers to manage user accounts;
|
38
|
+
* helpers for you to interact with account information from other
|
39
|
+
parts of your application;
|
40
|
+
* the model objects and schemas to create the required tables;
|
41
|
+
* stylesheets and javascript files to enhance the views;
|
42
|
+
* and any other library files required.
|
43
|
+
|
44
|
+
Once the Rails Core team decides on a suitable method for packaging plugins, Engines can be distributed using the same mechanisms. If you are developing engines yourself for use across multiple projects, linking them as svn externals allows seamless updating of bugfixes across multiple applications.
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
= Building an Engine
|
49
|
+
In your Rails application, you should have a directory called 'engines' in the vendor directory (alongside plugins). This directory will contain one subdirectory for each engine. Here's a sample rails application with a detailed listing of an example engines as a concrete example:
|
50
|
+
|
51
|
+
RAILS_ROOT
|
52
|
+
|- app
|
53
|
+
|- lib
|
54
|
+
|- config
|
55
|
+
|- <... other directories ...>
|
56
|
+
|- vendor
|
57
|
+
|-plugins
|
58
|
+
|- engines <-- the engines plugin
|
59
|
+
|- some_other_plugin
|
60
|
+
|- my_engine <-- our example engine
|
61
|
+
|- init_engine.rb
|
62
|
+
|- app
|
63
|
+
| |- controllers
|
64
|
+
| |- model
|
65
|
+
| |- helpers
|
66
|
+
| |- views
|
67
|
+
|- db
|
68
|
+
|- tasks
|
69
|
+
|- lib
|
70
|
+
|- public
|
71
|
+
| |- javascripts
|
72
|
+
| |- stylesheets
|
73
|
+
|- test
|
74
|
+
|
75
|
+
|
76
|
+
The internal structure of an engine mirrors the familiar core of a Rails application, with most of the engine within the <tt>app</tt> subdirectory. Within <tt>app</tt>, the controllers, views and model objects behave just as you might expect if there in teh top-level <tt>app</tt> directory.
|
77
|
+
|
78
|
+
When you call <tt>Engines.start :my_engine</tt> in <tt>environment.rb</tt> a few important bits of black magic voodoo happen:
|
79
|
+
* the engine's controllers, views and modesl are mixed in to your running Rails application;
|
80
|
+
* files in the <tt>lib</tt> directory of your engine (and subdirectories) are made available
|
81
|
+
to the rest of your system
|
82
|
+
* any directory structure in the folder <tt>public/</tt> within your engine is made available to the webserver
|
83
|
+
* the file <tt>init_engine.rb</tt> is loaded from within the engine (just like a plugin - the reason why engines need an init_engine.rb rather than an init.rb is because Rails' default plugin system might try and load an engine before the Engines plugin has been loaded, resulting in all manner of badness. Instead, Rails' skips over any engine plugins, and the Engines plugin handles initializing your Engines plugins when you 'start' each engine).
|
84
|
+
|
85
|
+
From within <tt>init_engine.rb</tt> you should load any libraries from your <tt>lib</tt> directory that your engine might need to function. You can also perform any configuration required.
|
86
|
+
|
87
|
+
=== Loading all Engines
|
88
|
+
|
89
|
+
Calling either Engines.start (with no arguments) or Engines.start_all will load all engines available. Please note that your plugin can only be detected as an engine by the presence of an 'init_engine.rb' file, or if the engine is in a directory named <something>_engine. If neither of these conditions hold, then your engine will not be loaded by Engines.start() or Engines.start_all().
|
90
|
+
|
91
|
+
|
92
|
+
=== Configuring Engines
|
93
|
+
Often your engine will require a number of configuration parameters set, some of which should be alterable by the user to reflect their particular needs. For example, a Login System might need a unique Salt value set to encrypt user passwords. This value should be unique to each application.
|
94
|
+
|
95
|
+
Engines provides a simple mechanism to handle this, and it's already been hinted at above. Within any module, a new method is now available: <tt>config</tt>. This method creates a special <tt>CONFIG</tt> Hash object within the Module it is called, and can be used to store your parameters. For a user to set these parameters, they should reopen the module (before the corresponding Engine.start call), as follows:
|
96
|
+
|
97
|
+
module MyModule
|
98
|
+
config :some_option, "really_important_value"
|
99
|
+
end
|
100
|
+
Engine.start :my_engine
|
101
|
+
|
102
|
+
Because this config value has been set before the Engine is started, subsequent attempts to set this config value will be ignored and the user-specified value used instead. Of course, there are situations where you *really* want to set the config value, even if it already exists. In such cases the config call can be changed to:
|
103
|
+
|
104
|
+
config :some_option, "no_THIS_really_important_value", :force
|
105
|
+
|
106
|
+
The additional parameter will force the new value to be used. For more information, see Module#config.
|
107
|
+
|
108
|
+
= Tweaking Engines
|
109
|
+
One of the best things about Engines is that if you don't like the default behaviour of any component, you can override it without needing to overhaul the whole engine. This makes adding your customisations to engines almost painless, and allows for upgrading/updating engine code without affecting the specialisations you need for your particular application.
|
110
|
+
|
111
|
+
|
112
|
+
=== View Tweaks
|
113
|
+
These are the simplest - just drop your customised view (or partial) into you <tt>/app/views</tt> directory in the corresponding location for the engine, and your view will be used in preference to the engine view. For example, if we have a ItemController with an action 'show', it will (normally) expect to find its view as <tt>report/show.rhtml</tt> in the <tt>views</tt> directory. The view is found in the engine at <tt>/vendor/engines/my_engine/app/views/report/show.rhtml</tt>. However, if you create the file <tt>/app/views/report/show.rhtml</tt>, that file will be used instead! The same goes for partials.
|
114
|
+
|
115
|
+
|
116
|
+
=== Controller Tweaks
|
117
|
+
You can override controller behaviour by replacing individual controller methods with your custom behaviour. Lets say that our ItemController's 'show' method isn't up to scratch, but the rest of it behaves just fine. To override the single method, create <tt>/app/controllers/item_controller.rb</tt>, just as if it were going to be a new controller in a regular Rails application. then, implement your show method as you would like it to happen.
|
118
|
+
|
119
|
+
... and that's it. Your custom code will be mixed in to the engine controller, replacing its old method with your custom code.
|
120
|
+
|
121
|
+
|
122
|
+
=== Model Tweaks
|
123
|
+
Alas, tweaking model objects isn't quite so easy (yet). If you need to change the behaviour of model objects, you'll need to copy the model file from the engine into <tt>/app/models</tt> and edit the methods yourself. We're working on improving this.
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
= TODO / Future Work
|
128
|
+
* some kind of testing? Integrate with the testing stuff at http://techno-weenie.net/svn/projects/test/ maybe?
|