radiant-reader-extension 0.9.2

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 (116) hide show
  1. data/.gitignore +2 -0
  2. data/README.md +89 -0
  3. data/Rakefile +140 -0
  4. data/VERSION +1 -0
  5. data/app/controllers/admin/messages_controller.rb +20 -0
  6. data/app/controllers/admin/reader_settings_controller.rb +92 -0
  7. data/app/controllers/admin/readers_controller.rb +28 -0
  8. data/app/controllers/password_resets_controller.rb +64 -0
  9. data/app/controllers/reader_action_controller.rb +84 -0
  10. data/app/controllers/reader_activations_controller.rb +60 -0
  11. data/app/controllers/reader_sessions_controller.rb +56 -0
  12. data/app/controllers/readers_controller.rb +131 -0
  13. data/app/helpers/admin/reader_settings_helper.rb +36 -0
  14. data/app/models/message.rb +108 -0
  15. data/app/models/message_function.rb +37 -0
  16. data/app/models/message_reader.rb +13 -0
  17. data/app/models/reader.rb +146 -0
  18. data/app/models/reader_notifier.rb +34 -0
  19. data/app/models/reader_session.rb +3 -0
  20. data/app/views/admin/messages/_form.html.haml +29 -0
  21. data/app/views/admin/messages/_help.html.haml +41 -0
  22. data/app/views/admin/messages/_message_description.html.haml +3 -0
  23. data/app/views/admin/messages/edit.html.haml +16 -0
  24. data/app/views/admin/messages/new.html.haml +16 -0
  25. data/app/views/admin/reader_settings/_setting.html.haml +24 -0
  26. data/app/views/admin/reader_settings/edit.html.haml +10 -0
  27. data/app/views/admin/reader_settings/index.html.haml +35 -0
  28. data/app/views/admin/reader_settings/show.html.haml +1 -0
  29. data/app/views/admin/readers/_avatar.html.haml +3 -0
  30. data/app/views/admin/readers/_form.html.haml +50 -0
  31. data/app/views/admin/readers/_list_head.html.haml +9 -0
  32. data/app/views/admin/readers/_listed.html.haml +22 -0
  33. data/app/views/admin/readers/_password_fields.html.haml +18 -0
  34. data/app/views/admin/readers/edit.html.haml +8 -0
  35. data/app/views/admin/readers/index.html.haml +17 -0
  36. data/app/views/admin/readers/new.html.haml +7 -0
  37. data/app/views/admin/readers/remove.html.haml +18 -0
  38. data/app/views/admin/sites/_choose_reader_layout.html.haml +7 -0
  39. data/app/views/password_resets/create.html.haml +13 -0
  40. data/app/views/password_resets/edit.html.haml +71 -0
  41. data/app/views/password_resets/new.html.haml +31 -0
  42. data/app/views/reader_activations/_activation_required.html.haml +34 -0
  43. data/app/views/reader_activations/_on_activation.html.haml +4 -0
  44. data/app/views/reader_activations/show.html.haml +41 -0
  45. data/app/views/reader_notifier/message.html.haml +1 -0
  46. data/app/views/reader_sessions/_login_form.html.haml +59 -0
  47. data/app/views/reader_sessions/new.html.haml +38 -0
  48. data/app/views/readers/_contributions.html.haml +2 -0
  49. data/app/views/readers/_controls.html.haml +25 -0
  50. data/app/views/readers/_extra_controls.html.haml +0 -0
  51. data/app/views/readers/_flasher.html.haml +6 -0
  52. data/app/views/readers/_form.html.haml +73 -0
  53. data/app/views/readers/create.html.haml +28 -0
  54. data/app/views/readers/edit.html.haml +47 -0
  55. data/app/views/readers/index.html.haml +16 -0
  56. data/app/views/readers/login.html.haml +15 -0
  57. data/app/views/readers/new.html.haml +41 -0
  58. data/app/views/readers/permission_denied.html.haml +23 -0
  59. data/app/views/readers/show.html.haml +35 -0
  60. data/app/views/wrappers/_field_errors.html.haml +5 -0
  61. data/config/routes.rb +22 -0
  62. data/config/settings.rb +9 -0
  63. data/db/migrate/001_create_readers.rb +31 -0
  64. data/db/migrate/002_extend_sites.rb +17 -0
  65. data/db/migrate/003_reader_honorifics.rb +12 -0
  66. data/db/migrate/004_user_readers.rb +11 -0
  67. data/db/migrate/005_last_login.rb +15 -0
  68. data/db/migrate/007_adapt_for_authlogic.rb +27 -0
  69. data/db/migrate/20090921125653_reader_messages.rb +27 -0
  70. data/db/migrate/20090924164413_functional_messages.rb +9 -0
  71. data/db/migrate/20090925081225_standard_messages.rb +106 -0
  72. data/db/migrate/20091006102438_message_visibility.rb +9 -0
  73. data/db/migrate/20091010083503_registration_config.rb +10 -0
  74. data/db/migrate/20091019124021_message_functions.rb +9 -0
  75. data/db/migrate/20091020133533_forenames.rb +9 -0
  76. data/db/migrate/20091020135152_contacts.rb +23 -0
  77. data/db/migrate/20091111090819_ensure_functional_messages_visible.rb +9 -0
  78. data/db/migrate/20091119092936_messages_have_layout.rb +9 -0
  79. data/db/migrate/20100922152338_lock_versions.rb +9 -0
  80. data/db/migrate/20100927095703_default_settings.rb +14 -0
  81. data/db/migrate/20101004074945_unlock_version.rb +9 -0
  82. data/lib/config_extensions.rb +5 -0
  83. data/lib/controller_extensions.rb +77 -0
  84. data/lib/reader_admin_ui.rb +64 -0
  85. data/lib/reader_helper.rb +36 -0
  86. data/lib/reader_site.rb +10 -0
  87. data/lib/reader_tags.rb +297 -0
  88. data/lib/rfc822.rb +29 -0
  89. data/lib/tasks/reader_extension_tasks.rake +28 -0
  90. data/pkg/radiant-reader-extension-0.9.0.gem +0 -0
  91. data/public/images/admin/chk_off.png +0 -0
  92. data/public/images/admin/chk_on.png +0 -0
  93. data/public/images/admin/new-message.png +0 -0
  94. data/public/images/admin/new-reader.png +0 -0
  95. data/public/javascripts/admin/messages.js +13 -0
  96. data/public/stylesheets/sass/admin/reader.sass +95 -0
  97. data/radiant-reader-extension.gemspec +184 -0
  98. data/reader_extension.rb +55 -0
  99. data/spec/controllers/admin/messages_controller_spec.rb +38 -0
  100. data/spec/controllers/admin/readers_controller_spec.rb +14 -0
  101. data/spec/controllers/password_resets_controller_spec.rb +140 -0
  102. data/spec/controllers/reader_activations_controller_spec.rb +45 -0
  103. data/spec/controllers/readers_controller_spec.rb +193 -0
  104. data/spec/datasets/messages_dataset.rb +49 -0
  105. data/spec/datasets/reader_layouts_dataset.rb +26 -0
  106. data/spec/datasets/reader_sites_dataset.rb +10 -0
  107. data/spec/datasets/readers_dataset.rb +51 -0
  108. data/spec/lib/reader_admin_ui_spec.rb +35 -0
  109. data/spec/lib/reader_site_spec.rb +18 -0
  110. data/spec/matchers/reader_login_system_matcher.rb +35 -0
  111. data/spec/models/message_spec.rb +109 -0
  112. data/spec/models/reader_notifier_spec.rb +34 -0
  113. data/spec/models/reader_spec.rb +155 -0
  114. data/spec/spec.opts +5 -0
  115. data/spec/spec_helper.rb +48 -0
  116. metadata +267 -0
@@ -0,0 +1,184 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{radiant-reader-extension}
8
+ s.version = "0.9.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["spanner"]
12
+ s.date = %q{2010-10-04}
13
+ s.description = %q{Centralises reader/member/user registration and management tasks for the benefit of other extensions}
14
+ s.email = %q{will@spanner.org}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README.md",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "app/controllers/admin/messages_controller.rb",
24
+ "app/controllers/admin/reader_settings_controller.rb",
25
+ "app/controllers/admin/readers_controller.rb",
26
+ "app/controllers/password_resets_controller.rb",
27
+ "app/controllers/reader_action_controller.rb",
28
+ "app/controllers/reader_activations_controller.rb",
29
+ "app/controllers/reader_sessions_controller.rb",
30
+ "app/controllers/readers_controller.rb",
31
+ "app/helpers/admin/reader_settings_helper.rb",
32
+ "app/models/message.rb",
33
+ "app/models/message_function.rb",
34
+ "app/models/message_reader.rb",
35
+ "app/models/reader.rb",
36
+ "app/models/reader_notifier.rb",
37
+ "app/models/reader_session.rb",
38
+ "app/views/admin/messages/_form.html.haml",
39
+ "app/views/admin/messages/_help.html.haml",
40
+ "app/views/admin/messages/_message_description.html.haml",
41
+ "app/views/admin/messages/edit.html.haml",
42
+ "app/views/admin/messages/new.html.haml",
43
+ "app/views/admin/reader_settings/_setting.html.haml",
44
+ "app/views/admin/reader_settings/edit.html.haml",
45
+ "app/views/admin/reader_settings/index.html.haml",
46
+ "app/views/admin/reader_settings/show.html.haml",
47
+ "app/views/admin/readers/_avatar.html.haml",
48
+ "app/views/admin/readers/_form.html.haml",
49
+ "app/views/admin/readers/_list_head.html.haml",
50
+ "app/views/admin/readers/_listed.html.haml",
51
+ "app/views/admin/readers/_password_fields.html.haml",
52
+ "app/views/admin/readers/edit.html.haml",
53
+ "app/views/admin/readers/index.html.haml",
54
+ "app/views/admin/readers/new.html.haml",
55
+ "app/views/admin/readers/remove.html.haml",
56
+ "app/views/admin/sites/_choose_reader_layout.html.haml",
57
+ "app/views/password_resets/create.html.haml",
58
+ "app/views/password_resets/edit.html.haml",
59
+ "app/views/password_resets/new.html.haml",
60
+ "app/views/reader_activations/_activation_required.html.haml",
61
+ "app/views/reader_activations/_on_activation.html.haml",
62
+ "app/views/reader_activations/show.html.haml",
63
+ "app/views/reader_notifier/message.html.haml",
64
+ "app/views/reader_sessions/_login_form.html.haml",
65
+ "app/views/reader_sessions/new.html.haml",
66
+ "app/views/readers/_contributions.html.haml",
67
+ "app/views/readers/_controls.html.haml",
68
+ "app/views/readers/_extra_controls.html.haml",
69
+ "app/views/readers/_flasher.html.haml",
70
+ "app/views/readers/_form.html.haml",
71
+ "app/views/readers/create.html.haml",
72
+ "app/views/readers/edit.html.haml",
73
+ "app/views/readers/index.html.haml",
74
+ "app/views/readers/login.html.haml",
75
+ "app/views/readers/new.html.haml",
76
+ "app/views/readers/permission_denied.html.haml",
77
+ "app/views/readers/show.html.haml",
78
+ "app/views/wrappers/_field_errors.html.haml",
79
+ "config/routes.rb",
80
+ "config/settings.rb",
81
+ "db/migrate/001_create_readers.rb",
82
+ "db/migrate/002_extend_sites.rb",
83
+ "db/migrate/003_reader_honorifics.rb",
84
+ "db/migrate/004_user_readers.rb",
85
+ "db/migrate/005_last_login.rb",
86
+ "db/migrate/007_adapt_for_authlogic.rb",
87
+ "db/migrate/20090921125653_reader_messages.rb",
88
+ "db/migrate/20090924164413_functional_messages.rb",
89
+ "db/migrate/20090925081225_standard_messages.rb",
90
+ "db/migrate/20091006102438_message_visibility.rb",
91
+ "db/migrate/20091010083503_registration_config.rb",
92
+ "db/migrate/20091019124021_message_functions.rb",
93
+ "db/migrate/20091020133533_forenames.rb",
94
+ "db/migrate/20091020135152_contacts.rb",
95
+ "db/migrate/20091111090819_ensure_functional_messages_visible.rb",
96
+ "db/migrate/20091119092936_messages_have_layout.rb",
97
+ "db/migrate/20100922152338_lock_versions.rb",
98
+ "db/migrate/20100927095703_default_settings.rb",
99
+ "db/migrate/20101004074945_unlock_version.rb",
100
+ "lib/config_extensions.rb",
101
+ "lib/controller_extensions.rb",
102
+ "lib/reader_admin_ui.rb",
103
+ "lib/reader_helper.rb",
104
+ "lib/reader_site.rb",
105
+ "lib/reader_tags.rb",
106
+ "lib/rfc822.rb",
107
+ "lib/tasks/reader_extension_tasks.rake",
108
+ "pkg/radiant-reader-extension-0.9.0.gem",
109
+ "public/images/admin/chk_off.png",
110
+ "public/images/admin/chk_on.png",
111
+ "public/images/admin/new-message.png",
112
+ "public/images/admin/new-reader.png",
113
+ "public/javascripts/admin/messages.js",
114
+ "public/stylesheets/sass/admin/reader.sass",
115
+ "radiant-reader-extension.gemspec",
116
+ "reader_extension.rb",
117
+ "spec/controllers/admin/messages_controller_spec.rb",
118
+ "spec/controllers/admin/readers_controller_spec.rb",
119
+ "spec/controllers/password_resets_controller_spec.rb",
120
+ "spec/controllers/reader_activations_controller_spec.rb",
121
+ "spec/controllers/readers_controller_spec.rb",
122
+ "spec/datasets/messages_dataset.rb",
123
+ "spec/datasets/reader_layouts_dataset.rb",
124
+ "spec/datasets/reader_sites_dataset.rb",
125
+ "spec/datasets/readers_dataset.rb",
126
+ "spec/lib/reader_admin_ui_spec.rb",
127
+ "spec/lib/reader_site_spec.rb",
128
+ "spec/matchers/reader_login_system_matcher.rb",
129
+ "spec/models/message_spec.rb",
130
+ "spec/models/reader_notifier_spec.rb",
131
+ "spec/models/reader_spec.rb",
132
+ "spec/spec.opts",
133
+ "spec/spec_helper.rb"
134
+ ]
135
+ s.homepage = %q{http://github.com/spanner/radiant-reader-extension}
136
+ s.rdoc_options = ["--charset=UTF-8"]
137
+ s.require_paths = ["lib"]
138
+ s.rubygems_version = %q{1.3.7}
139
+ s.summary = %q{User-services extension for Radiant CMS}
140
+ s.test_files = [
141
+ "spec/controllers/admin/messages_controller_spec.rb",
142
+ "spec/controllers/admin/readers_controller_spec.rb",
143
+ "spec/controllers/password_resets_controller_spec.rb",
144
+ "spec/controllers/reader_activations_controller_spec.rb",
145
+ "spec/controllers/readers_controller_spec.rb",
146
+ "spec/datasets/messages_dataset.rb",
147
+ "spec/datasets/reader_layouts_dataset.rb",
148
+ "spec/datasets/reader_sites_dataset.rb",
149
+ "spec/datasets/readers_dataset.rb",
150
+ "spec/lib/reader_admin_ui_spec.rb",
151
+ "spec/lib/reader_site_spec.rb",
152
+ "spec/matchers/reader_login_system_matcher.rb",
153
+ "spec/models/message_spec.rb",
154
+ "spec/models/reader_notifier_spec.rb",
155
+ "spec/models/reader_spec.rb",
156
+ "spec/spec_helper.rb"
157
+ ]
158
+
159
+ if s.respond_to? :specification_version then
160
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
161
+ s.specification_version = 3
162
+
163
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
164
+ s.add_runtime_dependency(%q<radiant>, [">= 0.9.0"])
165
+ s.add_runtime_dependency(%q<radiant-layouts-extension>, [">= 0"])
166
+ s.add_runtime_dependency(%q<radiant-mailer_layouts-extension>, [">= 0"])
167
+ s.add_runtime_dependency(%q<authlogic>, [">= 0"])
168
+ s.add_runtime_dependency(%q<sanitize>, [">= 0"])
169
+ else
170
+ s.add_dependency(%q<radiant>, [">= 0.9.0"])
171
+ s.add_dependency(%q<radiant-layouts-extension>, [">= 0"])
172
+ s.add_dependency(%q<radiant-mailer_layouts-extension>, [">= 0"])
173
+ s.add_dependency(%q<authlogic>, [">= 0"])
174
+ s.add_dependency(%q<sanitize>, [">= 0"])
175
+ end
176
+ else
177
+ s.add_dependency(%q<radiant>, [">= 0.9.0"])
178
+ s.add_dependency(%q<radiant-layouts-extension>, [">= 0"])
179
+ s.add_dependency(%q<radiant-mailer_layouts-extension>, [">= 0"])
180
+ s.add_dependency(%q<authlogic>, [">= 0"])
181
+ s.add_dependency(%q<sanitize>, [">= 0"])
182
+ end
183
+ end
184
+
@@ -0,0 +1,55 @@
1
+ require_dependency 'application_controller'
2
+
3
+ class ReaderExtension < Radiant::Extension
4
+ version "0.9.2"
5
+ description "Provides reader/member/user registration and management functions"
6
+ url "http://spanner.org/radiant/reader"
7
+
8
+ extension_config do |config|
9
+ config.gem 'authlogic'
10
+ config.gem 'sanitize'
11
+ config.gem 'will_paginate'
12
+ end
13
+
14
+ def activate
15
+ Reader
16
+ ApplicationController.send :include, ControllerExtensions # hooks up reader authentication and layout-chooser
17
+ ApplicationHelper.send :include, ReaderHelper # display usefulness including error-wrapper
18
+ Site.send :include, ReaderSite if defined? Site # adds site scope and site-based layout-chooser
19
+ Page.send :include, ReaderTags # a few mailmerge-like radius tags for use in messages, or for greeting readers on (uncached) pages
20
+ Radiant::Config.send :include, ConfigExtensions # .boolean?
21
+ UserActionObserver.instance.send :add_observer!, Reader
22
+ UserActionObserver.instance.send :add_observer!, Message
23
+
24
+ unless defined? admin.reader
25
+ Radiant::AdminUI.send :include, ReaderAdminUI
26
+ Radiant::AdminUI.load_reader_extension_regions
27
+ admin.reader = Radiant::AdminUI.load_default_reader_regions
28
+ admin.message = Radiant::AdminUI.load_default_message_regions
29
+ admin.reader_setting = Radiant::AdminUI.load_default_reader_setting_regions
30
+ if defined? admin.sites
31
+ admin.sites.edit.add :form, "admin/sites/choose_reader_layout", :after => "edit_homepage"
32
+ end
33
+ end
34
+
35
+ if respond_to?(:tab)
36
+ tab("Readers") do
37
+ add_item("Readers", "/admin/readers")
38
+ add_item("Settings", "/admin/readers/reader_settings")
39
+ end
40
+ tab("Settings") do
41
+ add_item("Reader", "/admin/readers/reader_settings")
42
+ end
43
+ else
44
+ admin.tabs.add "Readers", "/admin/readers", :after => "Layouts", :visibility => [:all]
45
+ if admin.tabs['Readers'].respond_to?(:add_link)
46
+ admin.tabs['Readers'].add_link('readers', '/admin/readers')
47
+ admin.tabs['Readers'].add_link('settings', '/admin/readers/reader_settings')
48
+ end
49
+ end
50
+ end
51
+
52
+ def deactivate
53
+ admin.tabs.remove "Readers" unless respond_to? :tab
54
+ end
55
+ end
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+
3
+ describe Admin::MessagesController do
4
+ dataset :messages
5
+
6
+ it "should be a ResourceController" do
7
+ controller.should be_kind_of(Admin::ResourceController)
8
+ end
9
+
10
+ it "should handle Messages" do
11
+ controller.class.model_class.should == Message
12
+ end
13
+
14
+ describe "on index" do
15
+ before do
16
+ login_as :existing
17
+ end
18
+
19
+ it "should redirect to the settings page" do
20
+ get :index
21
+ response.should be_redirect
22
+ response.should redirect_to(admin_reader_settings_url)
23
+ end
24
+ end
25
+
26
+ describe "on update" do
27
+ before do
28
+ login_as :existing
29
+ end
30
+
31
+ it "should redirect to the settings page" do
32
+ put :update, :id => message_id(:normal), :subject => 'testing'
33
+ response.should be_redirect
34
+ response.should redirect_to(admin_reader_settings_url)
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+
3
+ describe Admin::ReadersController do
4
+ dataset :users
5
+ dataset :readers
6
+
7
+ it "should be a ResourceController" do
8
+ controller.should be_kind_of(Admin::ResourceController)
9
+ end
10
+
11
+ it "should handle Readers" do
12
+ controller.class.model_class.should == Reader
13
+ end
14
+ end
@@ -0,0 +1,140 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe PasswordResetsController do
4
+ dataset :readers, :messages
5
+
6
+ before do
7
+ controller.stub!(:request).and_return(request)
8
+ Page.current_site = sites(:test) if defined? Site
9
+ request.env["HTTP_REFERER"] = 'http://test.host/referer!'
10
+ end
11
+
12
+ describe "with a forgot-my-password request" do
13
+ it "should ask for an email address" do
14
+ get :new
15
+ response.should be_success
16
+ response.should render_template("new")
17
+ end
18
+ end
19
+
20
+ describe "with a submitted email address" do
21
+ describe "that we recognise" do
22
+ before do
23
+ post :create, :email => 'normal@spanner.org'
24
+ @reader = readers(:normal)
25
+ end
26
+
27
+ it "should give instructions" do
28
+ response.should be_success
29
+ response.should render_template("create")
30
+ end
31
+
32
+ end
33
+
34
+ describe "for an account not yet activated" do
35
+ before do
36
+ post :create, :email => 'inactive@spanner.org'
37
+ @reader = readers(:inactive)
38
+ end
39
+
40
+ it "should redirect to the please-activate page" do
41
+ response.should be_redirect
42
+ response.should redirect_to(new_reader_activation_url)
43
+ end
44
+ end
45
+
46
+ describe "that we don't recognise" do
47
+ before do
48
+ post :create, :email => 'abinormal@spanner.org'
49
+ end
50
+
51
+ it 'should grumble' do
52
+ response.should be_success
53
+ response.should render_template("new")
54
+ flash[:error].should_not be_blank
55
+ end
56
+ it 'should not send a message' do
57
+ ActionMailer::Base.deliveries.last.should be_nil
58
+ end
59
+
60
+ end
61
+ end
62
+
63
+ describe "with a confirmation" do
64
+ describe "where the code is correct" do
65
+ before do
66
+ @reader = readers(:normal)
67
+ get :edit, :id => @reader.id, :confirmation_code => @reader.perishable_token
68
+ end
69
+
70
+ it 'should show the new-password form' do
71
+ response.should be_success
72
+ response.should render_template("edit")
73
+ flash[:error].should be_nil
74
+ end
75
+ end
76
+
77
+ describe "where the code is wrong" do
78
+ before do
79
+ @reader = readers(:normal)
80
+ get :edit, :id => @reader.id, :confirmation_code => 'anyoldstringwillnotdo'
81
+ end
82
+ it 'should grumble' do
83
+ response.should be_success
84
+ response.should render_template("edit")
85
+ flash[:error].should_not be_blank
86
+ end
87
+ end
88
+ end
89
+
90
+ describe "with a new password" do
91
+
92
+ describe "where the confirmation code is correct and the password confirmed" do
93
+ before do
94
+ reader = readers(:normal)
95
+ post :update, :id => reader.id, :confirmation_code => reader.perishable_token, :reader => {:password => 'testify', :password_confirmation => 'testify'}
96
+ end
97
+
98
+ it "should update the reader" do
99
+ readers(:normal).valid_password?('testify').should be_true
100
+ end
101
+
102
+ it "should log the reader in" do
103
+ controller.send(:current_reader).should == readers(:normal)
104
+ end
105
+ end
106
+
107
+ describe "where the confirmation code is correct but the password not confirmed" do
108
+ before do
109
+ @reader = readers(:normal)
110
+ post :update, :id => @reader.id, :confirmation_code => @reader.perishable_token, :reader => {:password => 'testify', :password_confirmation => 'testy'}
111
+ end
112
+
113
+ it 'should grumble' do
114
+ flash[:error].should_not be_blank
115
+ end
116
+
117
+ it "should return the password form again" do
118
+ response.should be_success
119
+ response.should render_template("edit")
120
+ end
121
+ end
122
+
123
+ describe "where the confirmation code is wrong" do
124
+ before do
125
+ @reader = readers(:normal)
126
+ post :update, :id => @reader.id, :confirmation_code => 'dingbat', :reader => {:password => 'testify', :password_confirmation => 'testify'}
127
+ end
128
+
129
+ it 'should grumble' do
130
+ response.should be_success
131
+ response.should render_template("edit")
132
+ flash[:error].should_not be_blank
133
+ end
134
+
135
+ it 'should not change the password' do
136
+ readers(:normal).valid_password?('testify').should be_false
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe ReaderActivationsController do
4
+ dataset :messages
5
+
6
+ before do
7
+ controller.stub!(:request).and_return(request)
8
+ Page.current_site = sites(:test) if defined? Site
9
+ request.env["HTTP_REFERER"] = 'http://test.host/referer!'
10
+ end
11
+
12
+ describe "with a correct activation" do
13
+ before do
14
+ @newreader = readers(:inactive)
15
+ put :update, :id => @newreader.id, :activation_code => @newreader.perishable_token
16
+ @reader = Reader.find_by_name('Inactive')
17
+ end
18
+
19
+ it "should activate the reader" do
20
+ @reader.activated?.should be_true
21
+ @reader.activated_at.should be_close((Time.now).utc, 1.minute)
22
+ end
23
+
24
+ it "should redirect to a confirmation page" do
25
+ response.should be_redirect
26
+ end
27
+ end
28
+
29
+ describe "with an incorrect activation" do
30
+ before do
31
+ @newreader = readers(:inactive)
32
+ put :update, :id => @newreader.id, :activation_code => 'down perishcope'
33
+ end
34
+
35
+ it "should render the please-activate page" do
36
+ response.should be_success
37
+ response.should render_template("show")
38
+ end
39
+
40
+ it "should flash an error" do
41
+ flash[:error].should_not be_nil
42
+ end
43
+ end
44
+
45
+ end