radiant-reader-extension 1.3.13 → 2.0.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/Rakefile +0 -19
- data/app/controllers/admin/group_invitations_controller.rb +78 -0
- data/app/controllers/admin/groups_controller.rb +8 -0
- data/app/controllers/admin/memberships_controller.rb +42 -0
- data/app/controllers/admin/messages_controller.rb +8 -3
- data/app/controllers/admin/permissions_controller.rb +42 -0
- data/app/controllers/admin/reader_configuration_controller.rb +0 -1
- data/app/controllers/admin/readers_controller.rb +1 -1
- data/app/controllers/password_resets_controller.rb +5 -5
- data/app/controllers/reader_action_controller.rb +13 -33
- data/app/controllers/reader_activations_controller.rb +4 -8
- data/app/controllers/reader_sessions_controller.rb +15 -26
- data/app/controllers/readers_controller.rb +26 -9
- data/app/helpers/reader_helper.rb +45 -17
- data/app/models/group.rb +80 -0
- data/app/models/membership.rb +13 -0
- data/app/models/message.rb +10 -7
- data/app/models/permission.rb +11 -0
- data/app/models/reader.rb +79 -35
- data/app/models/reader_notifier.rb +1 -0
- data/app/views/admin/group_invitations/new.html.haml +31 -0
- data/app/views/admin/group_invitations/preview.html.haml +58 -0
- data/app/views/admin/groups/_add_readers.html.haml +0 -0
- data/app/views/admin/groups/_form.html.haml +26 -0
- data/app/views/admin/groups/_list_head.html.haml +12 -0
- data/app/views/admin/groups/edit.html.haml +9 -0
- data/app/views/admin/groups/index.html.haml +44 -0
- data/app/views/admin/groups/new.html.haml +7 -0
- data/app/views/admin/groups/remove.html.haml +31 -0
- data/app/views/admin/groups/show.html.haml +74 -0
- data/app/views/admin/memberships/_reader.html.haml +9 -0
- data/app/views/admin/messages/_function.haml +31 -0
- data/app/views/admin/messages/_list_function.haml +7 -3
- data/app/views/admin/messages/_list_notes.html.haml +9 -0
- data/app/views/admin/messages/_message_description.html.haml +5 -1
- data/app/views/admin/messages/_message_group.html.haml +5 -0
- data/app/views/admin/messages/index.haml +4 -4
- data/app/views/admin/messages/show.html.haml +15 -15
- data/app/views/admin/pages/_listed.html.haml +16 -0
- data/app/views/admin/pages/_page_groups.html.haml +13 -0
- data/app/views/admin/permissions/_page.html.haml +24 -0
- data/app/views/admin/reader_configuration/edit.html.haml +3 -1
- data/app/views/admin/reader_configuration/show.html.haml +4 -2
- data/app/views/admin/readers/_form.html.haml +7 -7
- data/app/views/admin/readers/_password_fields.html.haml +6 -6
- data/app/views/admin/readers/_reader_groups.html.haml +7 -0
- data/app/views/admin/readers/edit.html.haml +2 -1
- data/app/views/admin/readers/index.html.haml +5 -2
- data/app/views/password_resets/create.html.haml +13 -8
- data/app/views/password_resets/edit.html.haml +26 -26
- data/app/views/password_resets/new.html.haml +28 -25
- data/app/views/reader_activations/_activation_required.haml +2 -2
- data/app/views/reader_activations/show.html.haml +11 -13
- data/app/views/reader_sessions/_login_form.html.haml +13 -12
- data/app/views/reader_sessions/new.html.haml +6 -8
- data/app/views/readers/_controls.html.haml +11 -9
- data/app/views/readers/_form.html.haml +32 -33
- data/app/views/readers/_memberships.html.haml +11 -0
- data/app/views/readers/edit.html.haml +11 -11
- data/app/views/readers/index.html.haml +9 -10
- data/app/views/readers/login.html.haml +10 -12
- data/app/views/readers/new.html.haml +11 -13
- data/app/views/readers/permission_denied.html.haml +7 -7
- data/app/views/readers/show.html.haml +7 -8
- data/app/views/shared/_standard_reader_parts.html.haml +14 -0
- data/app/views/site/not_allowed.html.haml +4 -0
- data/config/initializers/authlogic_connect_config.rb +12 -0
- data/config/initializers/radiant_config.rb +1 -0
- data/config/locales/en.yml +217 -177
- data/config/routes.rb +5 -0
- data/db/migrate/20090921125654_group_messages.rb +35 -0
- data/db/migrate/20091120083119_groups_public.rb +11 -0
- data/db/migrate/20110214101339_multiple_ownership.rb +13 -0
- data/lib/controller_extensions.rb +1 -1
- data/lib/group_tags.rb +65 -0
- data/lib/grouped_model.rb +125 -0
- data/lib/grouped_page.rb +39 -0
- data/lib/message_tags.rb +183 -0
- data/lib/radiant-reader-extension.rb +8 -0
- data/lib/reader_admin_ui.rb +29 -6
- data/lib/reader_tags.rb +7 -183
- data/lib/sanitize/config/generous.rb +49 -0
- data/lib/site_controller_extensions.rb +35 -0
- data/public/javascripts/reader.js +1 -1
- data/public/stylesheets/sass/reader.sass +18 -8
- data/radiant-reader-extension.gemspec +30 -176
- data/reader_extension.rb +31 -23
- data/spec/controllers/admin/messages_controller_spec.rb +1 -1
- data/spec/controllers/admin/readers_controller_spec.rb +0 -1
- data/spec/controllers/password_resets_controller_spec.rb +1 -1
- data/spec/controllers/reader_activations_controller_spec.rb +1 -1
- data/spec/controllers/readers_controller_spec.rb +67 -40
- data/spec/controllers/site_controller_spec.rb +63 -0
- data/spec/datasets/readers_dataset.rb +100 -11
- data/spec/models/group_spec.rb +46 -0
- data/spec/models/message_spec.rb +40 -15
- data/spec/models/page_spec.rb +81 -0
- data/spec/models/reader_notifier_spec.rb +1 -1
- data/spec/models/reader_spec.rb +17 -12
- metadata +99 -67
- data/.gitignore +0 -2
- data/VERSION +0 -1
- data/app/views/readers/_standard_parts.html.haml +0 -23
- data/spec/datasets/messages_dataset.rb +0 -49
- data/spec/datasets/reader_layouts_dataset.rb +0 -26
- data/spec/datasets/reader_sites_dataset.rb +0 -10
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe SiteController do
|
4
|
+
dataset :readers
|
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 no reader" do
|
13
|
+
before do
|
14
|
+
logout_reader
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "getting an ungrouped page" do
|
18
|
+
it "should render the page" do
|
19
|
+
get :show_page, :url => ''
|
20
|
+
response.should be_success
|
21
|
+
response.body.should == 'Hello world!'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "getting a grouped page" do
|
26
|
+
it "should redirect to login" do
|
27
|
+
get :show_page, :url => 'parent/'
|
28
|
+
response.should be_redirect
|
29
|
+
response.should redirect_to(reader_login_url)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "with a reader" do
|
35
|
+
before do
|
36
|
+
login_as_reader(:normal)
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "getting an ungrouped page" do
|
40
|
+
it "should render the page" do
|
41
|
+
get :show_page, :url => ''
|
42
|
+
response.should be_success
|
43
|
+
response.body.should == 'Hello world!'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "getting a grouped page to which she has access" do
|
48
|
+
it "should render the page" do
|
49
|
+
get :show_page, :url => 'parent/'
|
50
|
+
response.should be_success
|
51
|
+
response.body.should == 'Parent body.'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "getting a grouped page to which she doesn't have access" do
|
56
|
+
it "should redirect to the permission-denied page" do
|
57
|
+
get :show_page, :url => 'news/'
|
58
|
+
response.should be_redirect
|
59
|
+
response.should redirect_to(reader_permission_denied_url)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -1,25 +1,78 @@
|
|
1
1
|
require "authlogic/test_case"
|
2
|
+
require 'digest/sha1'
|
2
3
|
|
3
4
|
class ReadersDataset < Dataset::Base
|
4
|
-
|
5
|
-
datasets << :reader_sites if defined? Site
|
6
|
-
uses *datasets
|
5
|
+
uses :users, :pages
|
7
6
|
|
8
7
|
def load
|
9
8
|
create_reader "Normal"
|
9
|
+
create_reader "Another"
|
10
10
|
create_reader "Visible"
|
11
|
+
create_reader "Ungrouped"
|
11
12
|
create_reader "User", :user_id => user_id(:existing)
|
12
13
|
create_reader "Inactive", :activated_at => nil
|
14
|
+
|
15
|
+
create_group "Normal"
|
16
|
+
create_group "Special"
|
17
|
+
create_group "Homed", :homepage_id => page_id(:parent)
|
18
|
+
create_group "Elsewhere", :site_id => site_id(:elsewhere) if defined? Site
|
19
|
+
|
20
|
+
create_message "Normal"
|
21
|
+
create_message "Grouped", :function_id => "group_welcome"
|
22
|
+
create_message "Filtered", :filter_id => 'Textile', :body => 'this is a *filtered* message'
|
23
|
+
create_message "Welcome", :filter_id => 'Textile', :body => 'Hi', :function_id => 'welcome'
|
24
|
+
create_message "Activation", :filter_id => 'Textile', :body => 'Hi?', :function_id => 'activation'
|
25
|
+
create_message "Invitation", :filter_id => 'Textile', :body => 'Hi!', :function_id => 'invitation'
|
26
|
+
create_message "Password", :filter_id => 'Textile', :body => 'Oh', :function_id => 'password_reset'
|
27
|
+
create_message "Taggy", :filter_id => 'Textile', :body => %{
|
28
|
+
To <r:recipient:name />
|
29
|
+
|
30
|
+
Ying Tong Iddle I Po.
|
31
|
+
|
32
|
+
From <r:sender:name />
|
33
|
+
}
|
34
|
+
|
35
|
+
create_layout "Main"
|
36
|
+
create_layout "Other"
|
37
|
+
create_layout "email", :content => %{
|
38
|
+
<html>
|
39
|
+
<head><title><r:title /></title></head>
|
40
|
+
<body>
|
41
|
+
<p>header</p>
|
42
|
+
<r:content />
|
43
|
+
<p>footer</p>
|
44
|
+
</body>
|
45
|
+
<html>
|
46
|
+
}
|
47
|
+
|
48
|
+
admit_to_group :homed, [readers(:normal)]
|
49
|
+
admit_to_group :normal, [readers(:normal), readers(:inactive)]
|
50
|
+
admit_to_group :special, [readers(:another)]
|
51
|
+
restrict_to_group :homed, [pages(:parent), pages(:childless)]
|
52
|
+
restrict_to_group :special, [pages(:news)]
|
53
|
+
restrict_to_group :normal, [messages(:grouped)]
|
13
54
|
end
|
14
55
|
|
15
56
|
helpers do
|
16
57
|
def create_reader(name, attributes={})
|
17
|
-
|
18
|
-
reader = create_model Reader, name.symbolize, attributes
|
58
|
+
reader = create_model Reader, name.symbolize, default_reader_attributes(name).merge(attributes)
|
19
59
|
end
|
20
60
|
|
21
|
-
def
|
22
|
-
|
61
|
+
def create_group(name, attributes={})
|
62
|
+
group = create_record Group, name.symbolize, default_group_attributes(name).merge(attributes)
|
63
|
+
end
|
64
|
+
|
65
|
+
def create_message(subject, attributes={})
|
66
|
+
message = create_model Message, subject.symbolize, default_message_attributes(subject).merge(attributes)
|
67
|
+
message.update_attribute(:created_by, users(:existing)) # otherwise this is blanked by the absence of a current_user, and we need it for preview rendering
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_layout(name, attributes={})
|
71
|
+
attributes[:site] ||= sites(:test) if Layout.reflect_on_association(:site)
|
72
|
+
create_model :layout, name.symbolize, attributes.update(:name => name)
|
73
|
+
end
|
74
|
+
|
75
|
+
def default_reader_attributes(name="John Doe")
|
23
76
|
symbol = name.symbolize
|
24
77
|
attributes = {
|
25
78
|
:name => name,
|
@@ -27,13 +80,31 @@ class ReadersDataset < Dataset::Base
|
|
27
80
|
:login => "#{symbol}@spanner.org",
|
28
81
|
:activated_at => Time.now - 1.week,
|
29
82
|
:password_salt => "golly",
|
30
|
-
:password => '
|
31
|
-
:password_confirmation => '
|
32
|
-
}
|
83
|
+
:password => 'passw0rd',
|
84
|
+
:password_confirmation => 'passw0rd'
|
85
|
+
}
|
33
86
|
attributes[:site] = sites(:test) if defined? Site
|
34
87
|
attributes
|
35
88
|
end
|
36
89
|
|
90
|
+
def default_group_attributes(name="Group")
|
91
|
+
attributes = {
|
92
|
+
:name => name,
|
93
|
+
:description => "#{name} group"
|
94
|
+
}
|
95
|
+
attributes[:site_id] ||= site_id(:test) if defined? Site
|
96
|
+
attributes
|
97
|
+
end
|
98
|
+
|
99
|
+
def default_message_attributes(subject="Message")
|
100
|
+
attributes = {
|
101
|
+
:subject => subject,
|
102
|
+
:body => "This is the #{subject} message"
|
103
|
+
}
|
104
|
+
attributes[:site] = sites(:test) if defined? Site
|
105
|
+
attributes
|
106
|
+
end
|
107
|
+
|
37
108
|
def login_as_reader(reader)
|
38
109
|
activate_authlogic
|
39
110
|
login_reader = reader.is_a?(Reader) ? reader : readers(reader)
|
@@ -46,6 +117,24 @@ class ReadersDataset < Dataset::Base
|
|
46
117
|
session.destroy
|
47
118
|
end
|
48
119
|
end
|
120
|
+
|
121
|
+
def restrict_to_group(g, these)
|
122
|
+
g = groups(g) unless g.is_a? Group
|
123
|
+
these.each {|thing| thing.permit(g) }
|
124
|
+
end
|
125
|
+
|
126
|
+
def admit_to_group(g, readers)
|
127
|
+
g = groups(g) unless g.is_a? Group
|
128
|
+
readers.each {|r| g.admit(r) }
|
129
|
+
end
|
130
|
+
|
131
|
+
def seem_to_send(message, reader)
|
132
|
+
message = messages(message) unless message.is_a?(Message)
|
133
|
+
reader = readers(reader) unless reader.is_a?(Reader)
|
134
|
+
sending = MessageReader.find_or_create_by_message_id_and_reader_id(message.id, reader.id)
|
135
|
+
sending.sent_at = 10.minutes.ago
|
136
|
+
sending.save
|
137
|
+
end
|
138
|
+
|
49
139
|
end
|
50
|
-
|
51
140
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Group do
|
4
|
+
dataset :readers
|
5
|
+
|
6
|
+
describe "on validation" do
|
7
|
+
before do
|
8
|
+
@group = Group.new :name => "Unique Test Group"
|
9
|
+
@group.should be_valid
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should require a name" do
|
13
|
+
@group.name = nil
|
14
|
+
@group.should_not be_valid
|
15
|
+
@group.errors.on(:name).should_not be_empty
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should require a unique name" do
|
19
|
+
duplicate = Group.new :name => "Normal"
|
20
|
+
duplicate.should_not be_valid
|
21
|
+
duplicate.errors.on(:name).should_not be_empty
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have a homepage association" do
|
26
|
+
Group.reflect_on_association(:homepage).should_not be_nil
|
27
|
+
group = groups(:homed)
|
28
|
+
group.homepage.should be_a(Page)
|
29
|
+
group.homepage = pages(:child)
|
30
|
+
group.homepage.should == pages(:child)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have a group of readers" do
|
34
|
+
group = groups(:normal)
|
35
|
+
group.respond_to?(:readers).should be_true
|
36
|
+
group.readers.any?.should be_true
|
37
|
+
group.readers.size.should == 2
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have a group of pages" do
|
41
|
+
group = groups(:homed)
|
42
|
+
group.respond_to?(:pages).should be_true
|
43
|
+
group.pages.any?.should be_true
|
44
|
+
group.pages.size.should == 2
|
45
|
+
end
|
46
|
+
end
|
data/spec/models/message_spec.rb
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
3
|
describe Message do
|
4
|
-
dataset :
|
4
|
+
dataset :readers
|
5
5
|
|
6
6
|
before do
|
7
7
|
|
8
8
|
end
|
9
9
|
|
10
|
+
it "should have a groups association" do
|
11
|
+
Message.reflect_on_association(:groups).should_not be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should normally list only the ungrouped messages" do
|
15
|
+
Message.visible.count.should == 7
|
16
|
+
end
|
17
|
+
|
10
18
|
describe "on validation" do
|
11
19
|
before do
|
12
20
|
@message = messages(:normal)
|
@@ -45,21 +53,18 @@ describe Message do
|
|
45
53
|
end
|
46
54
|
end
|
47
55
|
|
48
|
-
describe "
|
56
|
+
describe "on delivery" do
|
49
57
|
before do
|
50
58
|
@message = messages(:normal)
|
51
|
-
@message.readers << readers(:normal)
|
52
59
|
end
|
53
60
|
|
54
|
-
describe "
|
61
|
+
describe "previously unsent" do
|
55
62
|
it "should know to whom it can belong" do
|
56
|
-
@message.possible_readers.count.should == Reader.
|
63
|
+
@message.possible_readers.count.should == Reader.count
|
64
|
+
@message.active_readers.count.should == Reader.active.count
|
65
|
+
@message.inactive_readers.count.should == Reader.inactive.count
|
57
66
|
end
|
58
67
|
|
59
|
-
it "should know to whom it does belong" do
|
60
|
-
@message.readers.include?(readers(:normal)).should be_true
|
61
|
-
end
|
62
|
-
|
63
68
|
it "should report itself unsent to anyone" do
|
64
69
|
@message.delivered?.should be_false
|
65
70
|
end
|
@@ -76,7 +81,6 @@ describe Message do
|
|
76
81
|
describe "already sent to one reader" do
|
77
82
|
before do
|
78
83
|
seem_to_send(messages(:normal), readers(:normal))
|
79
|
-
@message.readers << readers(:visible)
|
80
84
|
end
|
81
85
|
|
82
86
|
it "should report itself delivered" do
|
@@ -88,7 +92,7 @@ describe Message do
|
|
88
92
|
end
|
89
93
|
|
90
94
|
it "should know to whom it has yet to be sent" do
|
91
|
-
@message.undelivered_readers.should
|
95
|
+
@message.undelivered_readers.should =~ Reader.all - @message.recipients
|
92
96
|
end
|
93
97
|
|
94
98
|
it "should report itself delivered to that reader" do
|
@@ -96,13 +100,34 @@ describe Message do
|
|
96
100
|
end
|
97
101
|
|
98
102
|
it "should report itself not yet sent to other readers" do
|
99
|
-
@message.readers.include?(readers(:visible)).should be_true
|
100
103
|
@message.delivered_to?(readers(:visible)).should be_false
|
101
104
|
end
|
105
|
+
end
|
102
106
|
|
107
|
+
describe "with a group" do
|
108
|
+
it "should report itself visible to a reader who is a group member" do
|
109
|
+
messages(:grouped).visible_to?(readers(:normal)).should be_true
|
110
|
+
end
|
111
|
+
it "should report itself invisible to a reader who is not a group member" do
|
112
|
+
messages(:grouped).visible_to?(readers(:ungrouped)).should be_false
|
113
|
+
end
|
114
|
+
it "should list only group members as possible readers" do
|
115
|
+
messages(:grouped).possible_readers.include?(readers(:normal)).should be_true
|
116
|
+
messages(:grouped).possible_readers.include?(readers(:ungrouped)).should be_false
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "without a group" do
|
121
|
+
it "should report itself visible to everyone" do
|
122
|
+
messages(:normal).visible_to?(readers(:normal)).should be_true
|
123
|
+
messages(:normal).visible_to?(readers(:ungrouped)).should be_true
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should list all readers as possible readers" do
|
127
|
+
messages(:normal).possible_readers.include?(readers(:normal)).should be_true
|
128
|
+
messages(:normal).possible_readers.include?(readers(:ungrouped)).should be_true
|
129
|
+
end
|
103
130
|
end
|
104
|
-
|
105
|
-
|
106
131
|
end
|
107
|
-
|
132
|
+
|
108
133
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Page do
|
4
|
+
dataset :readers
|
5
|
+
|
6
|
+
before do
|
7
|
+
@site = Page.current_site = sites(:test) if defined? Site
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "listed" do
|
11
|
+
describe "for nobody in particular" do
|
12
|
+
it "should not include private pages" do
|
13
|
+
Page.visible.include?(pages(:news)).should be_false
|
14
|
+
end
|
15
|
+
it "should include non-private pages" do
|
16
|
+
Page.visible.include?(pages(:first)).should be_true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "for a reader without group memberships" do
|
21
|
+
it "should not include private pages" do
|
22
|
+
Page.visible_to(readers(:ungrouped)).include?(pages(:news)).should be_false
|
23
|
+
end
|
24
|
+
it "should include non-private pages" do
|
25
|
+
Page.visible_to(readers(:ungrouped)).include?(pages(:first)).should be_true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "for a reader with group memberships" do
|
30
|
+
it "should include private pages" do
|
31
|
+
Page.visible_to(readers(:another)).include?(pages(:news)).should be_true
|
32
|
+
end
|
33
|
+
it "should include non-private pages" do
|
34
|
+
Page.visible_to(readers(:another)).include?(pages(:first)).should be_true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "with groups" do
|
40
|
+
before do
|
41
|
+
@page = pages(:parent)
|
42
|
+
end
|
43
|
+
it "should have some groups" do
|
44
|
+
@page.groups.any?.should be_true
|
45
|
+
@page.groups.size.should == 1
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should be visible to group members" do
|
49
|
+
@page.visible_to?(readers(:normal)).should be_true
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not be visible to non-members" do
|
53
|
+
@page.visible_to?(readers(:ungrouped)).should be_false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "with inherited groups" do
|
58
|
+
before do
|
59
|
+
@page = pages(:child)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should be visible to group members" do
|
63
|
+
@page.visible_to?(readers(:normal)).should be_true
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should not be visible to non-members" do
|
67
|
+
@page.visible_to?(readers(:ungrouped)).should be_false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "without groups" do
|
72
|
+
before do
|
73
|
+
@page = pages(:home)
|
74
|
+
end
|
75
|
+
it "should be visible to everyone" do
|
76
|
+
@page.visible_to?(readers(:ungrouped)).should be_true
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
data/spec/models/reader_spec.rb
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
3
|
describe Reader do
|
4
|
-
dataset :
|
5
|
-
dataset :reader_layouts
|
4
|
+
dataset :readers
|
6
5
|
activate_authlogic
|
7
6
|
|
8
7
|
before do
|
9
8
|
@existing_reader = readers(:normal)
|
10
9
|
end
|
11
10
|
|
11
|
+
it "should have some groups" do
|
12
|
+
reader = readers(:normal)
|
13
|
+
reader.groups.any?.should be_true
|
14
|
+
reader.groups.size.should == 2
|
15
|
+
end
|
16
|
+
|
12
17
|
describe "on validation" do
|
13
18
|
before do
|
14
|
-
@reader = Reader.new :name => "Test Reader", :email => 'test@spanner.org', :login => 'test', :password => '
|
19
|
+
@reader = Reader.new :name => "Test Reader", :email => 'test@spanner.org', :login => 'test', :password => 'passw0rd', :password_confirmation => 'passw0rd'
|
15
20
|
@reader.should be_valid
|
16
21
|
end
|
17
22
|
|
@@ -47,7 +52,7 @@ describe Reader do
|
|
47
52
|
|
48
53
|
describe "on creation" do
|
49
54
|
before do
|
50
|
-
@reader = Reader.create :name => "Test Reader", :email => 'test@spanner.org', :login => 'test', :password => '
|
55
|
+
@reader = Reader.create :name => "Test Reader", :email => 'test@spanner.org', :login => 'test', :password => 'passw0rd', :password_confirmation => 'passw0rd'
|
51
56
|
end
|
52
57
|
|
53
58
|
it 'should await activation' do
|
@@ -62,7 +67,7 @@ describe Reader do
|
|
62
67
|
|
63
68
|
describe "on create_for_user" do
|
64
69
|
it "should return the existing reader if there is one" do
|
65
|
-
reader = Reader.
|
70
|
+
reader = Reader.for_user(users(:existing))
|
66
71
|
reader.should == readers(:user)
|
67
72
|
reader.is_user?.should be_true
|
68
73
|
reader.is_admin?.should be_false
|
@@ -70,7 +75,7 @@ describe Reader do
|
|
70
75
|
|
71
76
|
it "should create a matching reader if necessary" do
|
72
77
|
user = users(:admin)
|
73
|
-
reader = Reader.
|
78
|
+
reader = Reader.for_user(user)
|
74
79
|
[:name, :email, :login, :created_at, :notes].each do |att|
|
75
80
|
reader.send(att).should == user.send(att)
|
76
81
|
end
|
@@ -106,16 +111,16 @@ describe Reader do
|
|
106
111
|
|
107
112
|
it "should update the user's credentials" do
|
108
113
|
reader = readers(:user)
|
109
|
-
reader.password = reader.password_confirmation = '
|
114
|
+
reader.password = reader.password_confirmation = 'bl0tto'
|
110
115
|
reader.save!
|
111
|
-
ReaderSession.new(:login => reader.login, :password => '
|
112
|
-
reader.user.authenticated?('
|
116
|
+
ReaderSession.new(:login => reader.login, :password => 'bl0tto').should be_valid
|
117
|
+
reader.user.authenticated?('bl0tto').should be_true
|
113
118
|
end
|
114
119
|
end
|
115
120
|
|
116
121
|
describe "on activation" do
|
117
122
|
before do
|
118
|
-
@reader = Reader.create :name => "Test Reader", :email => 'test@spanner.org', :login => 'another_login', :password => '
|
123
|
+
@reader = Reader.create :name => "Test Reader", :email => 'test@spanner.org', :login => 'another_login', :password => 'passw0rd', :password_confirmation => 'passw0rd', :trusted => 1
|
119
124
|
end
|
120
125
|
|
121
126
|
it 'should be retrieved by id and activation code' do
|
@@ -136,12 +141,12 @@ describe Reader do
|
|
136
141
|
|
137
142
|
describe "on login" do
|
138
143
|
before do
|
139
|
-
@reader = Reader.create :name => "Test Reader", :email => 'test@spanner.org', :login => 'test', :password => '
|
144
|
+
@reader = Reader.create :name => "Test Reader", :email => 'test@spanner.org', :login => 'test', :password => 'h00haa', :password_confirmation => 'h00haa'
|
140
145
|
@reader.activate!
|
141
146
|
end
|
142
147
|
|
143
148
|
it 'should authenticate' do
|
144
|
-
ReaderSession.new(:login => 'test', :password => '
|
149
|
+
ReaderSession.new(:login => 'test', :password => 'h00haa').should be_valid
|
145
150
|
end
|
146
151
|
|
147
152
|
it 'should not authenticate with bad password' do
|