rad_kit 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/lib/components/captcha.rb +4 -4
  2. data/lib/components/kit.rb +5 -5
  3. data/lib/components/kit.yml +0 -2
  4. data/lib/components/models.rb +2 -5
  5. data/lib/components/models.yml +3 -0
  6. data/lib/kit/controller/authorized.rb +9 -8
  7. data/lib/kit/controller/captcha.rb +6 -6
  8. data/lib/kit/controller/localized.rb +2 -2
  9. data/lib/kit/gems.rb +12 -8
  10. data/lib/kit/i18n.rb +3 -3
  11. data/lib/kit/i18n/locales/ru/pluralization.rb +3 -3
  12. data/lib/kit/kit.rb +7 -7
  13. data/lib/kit/kit_text_utils.rb +6 -6
  14. data/lib/kit/misc/prepare_model.rb +4 -4
  15. data/lib/kit/models.rb +22 -5
  16. data/lib/kit/models/attachment_file.rb +27 -0
  17. data/lib/kit/models/{attachments_uploader_helper.rb → attachments_helper.rb} +34 -28
  18. data/lib/kit/models/authorized.rb +64 -63
  19. data/lib/kit/models/authorized_object.rb +70 -73
  20. data/lib/kit/models/base_file.rb +37 -0
  21. data/lib/kit/models/config.rb +30 -0
  22. data/lib/kit/models/indexes.rb +30 -0
  23. data/lib/kit/models/miscellaneous.rb +7 -1
  24. data/lib/kit/models/role.rb +17 -17
  25. data/lib/kit/models/tags.rb +71 -0
  26. data/lib/kit/models/tags_mixin.rb +39 -0
  27. data/lib/kit/mongodb_model.rb +13 -0
  28. data/lib/kit/mongodb_model/text_processor.rb +32 -0
  29. data/lib/kit/spec.rb +30 -30
  30. data/lib/kit/spec/items_controller_crud.rb +9 -9
  31. data/lib/kit/support.rb +1 -1
  32. data/lib/kit/tasks.rb +3 -7
  33. data/lib/text_utils.rb +2 -2
  34. data/lib/text_utils/code_highlighter.rb +17 -17
  35. data/lib/text_utils/custom_markdown.rb +7 -7
  36. data/lib/text_utils/ensure_utf.rb +3 -3
  37. data/lib/text_utils/format_qualifier.rb +2 -2
  38. data/lib/text_utils/html_sanitizer.rb +9 -9
  39. data/lib/text_utils/markdown.rb +9 -9
  40. data/lib/text_utils/pipe.rb +1 -1
  41. data/lib/text_utils/processor.rb +3 -3
  42. data/lib/text_utils/support.rb +3 -3
  43. data/lib/text_utils/truncate.rb +4 -4
  44. data/readme.md +3 -1
  45. data/spec/controller/authorization_spec.rb +45 -45
  46. data/spec/controller/captcha_spec.rb +18 -18
  47. data/spec/controller/comments_spec.rb +16 -14
  48. data/spec/controller/items_spec.rb +16 -17
  49. data/spec/i18n/i18n_spec.rb +5 -5
  50. data/spec/misc/kit_text_utils_spec.rb +5 -5
  51. data/spec/misc/prepare_model_spec.rb +6 -6
  52. data/spec/misc/user_error_spec.rb +8 -8
  53. data/spec/models/{attachments_uploader_helper_spec.rb → attachments_helper_spec.rb} +46 -50
  54. data/spec/models/{attachments_uploader_helper_spec → attachments_helper_spec}/v1/a.txt +0 -0
  55. data/spec/models/{attachments_uploader_helper_spec → attachments_helper_spec}/v1/b.txt +0 -0
  56. data/spec/models/{attachments_uploader_helper_spec → attachments_helper_spec}/v2/a.txt +0 -0
  57. data/spec/models/attachments_spec.rb +4 -7
  58. data/spec/models/authorization_spec.rb +15 -15
  59. data/spec/models/authorized_object_spec.rb +75 -75
  60. data/spec/models/item_spec.rb +44 -40
  61. data/spec/models/role_spec.rb +4 -4
  62. data/spec/models/tags_spec.rb +47 -21
  63. data/spec/models/uploader_spec.rb +13 -23
  64. data/spec/mongodb_model/text_processor_spec.rb +26 -0
  65. data/spec/spec_helper.rb +6 -4
  66. data/spec/spec_helper/factories.rb +3 -3
  67. data/spec/spec_helper/user.rb +4 -7
  68. data/spec/text_utils/code_highlighter_spec.rb +7 -7
  69. data/spec/text_utils/custom_markdown_spec.rb +14 -14
  70. data/spec/text_utils/format_qualifier_spec.rb +6 -6
  71. data/spec/text_utils/html_sanitizer_spec.rb +15 -15
  72. data/spec/text_utils/markdown_spec.rb +17 -17
  73. data/spec/text_utils/pipe_spec.rb +5 -5
  74. data/spec/text_utils/spec_helper.rb +1 -1
  75. data/spec/text_utils/text_processor_shared.rb +1 -1
  76. data/spec/text_utils/truncate_spec.rb +5 -5
  77. metadata +118 -114
  78. data/lib/kit/models/attachment_uploader.rb +0 -15
  79. data/lib/kit/models/file_uploader.rb +0 -26
  80. data/lib/kit/models_after.rb +0 -27
  81. data/lib/kit/mongoid.rb +0 -22
  82. data/lib/kit/mongoid/rad_miscellaneous.rb +0 -36
  83. data/lib/kit/mongoid/text_processor.rb +0 -44
  84. data/spec/mongoid/basic_spec.rb +0 -36
@@ -3,29 +3,29 @@ require "spec_helper"
3
3
  describe "User Error" do
4
4
  isolate :conveyors, :router, before: :all
5
5
 
6
- before :all do
6
+ before :all do
7
7
  rad.delete :conveyors
8
8
  rad.conveyors.web do |web|
9
9
  web.use Rad::Controller::Processors::ControllerCaller
10
10
  end
11
-
11
+
12
12
  class ::SomeModel
13
13
  def self.find! id
14
14
  id.should == 'some id'
15
15
  SomeModel.new
16
16
  end
17
17
  end
18
- end
18
+ end
19
19
  after :all do
20
20
  remove_constants %w(SomeModel ControllerSpec)
21
21
  end
22
-
22
+
23
23
  it "user error" do
24
24
  class ::ControllerSpec
25
25
  inherit Rad::Controller::Http
26
-
26
+
27
27
  prepare_model SomeModel, id: :some_model, variable: 'some_model'
28
-
28
+
29
29
  def action
30
30
  @some_model.should_not == nil
31
31
  render inline: 'ok'
@@ -1,27 +1,27 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "User Error" do
3
+ describe "User Error" do
4
4
  isolate :conveyors, :router, before: :all
5
-
5
+
6
6
  before(:all) do
7
7
  rad.delete :conveyors
8
8
  rad.conveyors.web do |web|
9
9
  web.use Rad::Controller::Processors::ControllerCaller
10
10
  end
11
11
  end
12
-
12
+
13
13
  after :all do
14
14
  remove_constants %w(UserErrorSpec)
15
15
  end
16
-
16
+
17
17
  it "user error" do
18
18
  class ::UserErrorSpec
19
19
  inherit Rad::Controller::Http
20
-
20
+
21
21
  def action
22
22
  raise_user_error "some error"
23
- end
24
-
23
+ end
24
+
25
25
  protected
26
26
  def catch_user_error
27
27
  begin
@@ -32,7 +32,7 @@ describe "User Error" do
32
32
  end
33
33
  around :catch_user_error
34
34
  end
35
-
35
+
36
36
  ccall(UserErrorSpec, :action).should == "Catched some error"
37
37
  end
38
38
  end
@@ -1,50 +1,46 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Attachments" do
4
- with_tmp_spec_dir
5
- with_mongoid
6
- with_files
3
+ describe "Attachments" do
4
+ with_models
7
5
 
8
6
  before :all do
9
- class TheFileUploader < Models::FileUploader
7
+ class TheBaseFile < Models::BaseFile
10
8
  end
11
-
9
+
12
10
  class TheFile
13
- include Mongoid::Document
14
-
15
- embedded_in :post, class_name: 'ThePost'
16
- mount_uploader :file, TheFileUploader
17
- end
18
-
11
+ inherit Mongo::Model, Mongo::Model::FileModel
12
+
13
+ mount_file :file, TheBaseFile
14
+ end
15
+
19
16
  class ThePost
20
- include Mongoid::Document
17
+ inherit Mongo::Model
18
+
19
+ def files; @files ||= [] end
20
+ mount_attachments(:files, :file){TheFile.new}
21
21
 
22
- embeds_many :files, class_name: 'TheFile'
23
- mount_embedded_uploader :files, :file
24
- mount_attachments_uploader :files, :file
25
-
26
22
  def sorted_files
27
- files.sort{|a, b| a.file.url <=> b.file.url}
23
+ files.sort{|a, b| a.file.file.name <=> b.file.file.name}
28
24
  end
29
- end
30
- end
31
- after(:all){remove_constants :ThePost, :TheImage, :TheImageUploader}
32
-
25
+ end
26
+ end
27
+ after(:all){remove_constants :ThePost, :TheFile, :TheBaseFile}
28
+
33
29
  before do
34
30
  @a = File.open("#{spec_dir}/v1/a.txt")
35
31
  @b = File.open("#{spec_dir}/v1/b.txt")
36
32
  @a_v2 = File.open("#{spec_dir}/v2/a.txt")
37
33
  end
38
- after do
34
+ after do
39
35
  @a.close if @a
40
36
  @b.close if @b
41
37
  @a_v2.close if @a_v2
42
38
  end
43
-
39
+
44
40
  def post_with_two_files
45
41
  params = {
46
42
  files_as_attachments: [@a, @b]
47
- }
43
+ }
48
44
 
49
45
  post = ThePost.new params
50
46
  post.save!
@@ -52,56 +48,56 @@ describe "Attachments" do
52
48
  post.files.size.should == 2
53
49
  post
54
50
  end
55
-
51
+
56
52
  it "should add files" do
57
53
  post = post_with_two_files
58
-
54
+
59
55
  post.files.size.should == 2
60
56
  a, b = post.sorted_files
61
- a.file.path.should =~ /\/a\.txt/
62
- b.file.path.should =~ /\/b\.txt/
57
+ a.file.file.path.should =~ /\/a\.txt/
58
+ b.file.file.path.should =~ /\/b\.txt/
63
59
  end
64
-
60
+
65
61
  it "should remove files" do
66
62
  post = post_with_two_files
67
63
  a, b = post.sorted_files
68
- File.should exist(b.file.path)
69
-
64
+ File.should exist(file_model_storage.path + b.file.file.path)
65
+
70
66
  params = {
71
67
  files_as_attachments: ['a.txt']
72
- }
73
- post.update_attributes(params).should be_true
68
+ }
69
+ post.set(params).save!
74
70
  post.reload
75
-
71
+
76
72
  post.files.size.should == 1
77
- post.files.first.file.path.should =~ /\/a\.txt/
78
-
73
+ post.files.first.file.file.path.should =~ /\/a\.txt/
74
+
79
75
  # should also remove physical file
80
- File.should_not exist(b.file.path)
76
+ File.should_not exist(file_model_storage.path + b.file.file.path)
81
77
  end
82
-
78
+
83
79
  it "should update files" do
84
80
  post = post_with_two_files
85
-
81
+
86
82
  params = {
87
83
  files_as_attachments: [@a_v2, 'b.txt']
88
- }
89
- post.update_attributes(params).should be_true
84
+ }
85
+
86
+ post.set(params).save!
90
87
  post.reload
91
-
92
- post.files.size.should == 2
88
+
93
89
  a, b = post.sorted_files
94
- a.file.path.should =~ /\/a\.txt/
95
- File.read(a.file.path).should == 'a v2'
96
- b.file.path.should =~ /\/b\.txt/
90
+ a.file.file.path.should =~ /\/a\.txt/
91
+ File.read(file_model_storage.path + a.file.file.path).should == 'a v2'
92
+ b.file.file.path.should =~ /\/b\.txt/
97
93
  end
98
-
94
+
99
95
  it "should provide :files_as_attachments getter" do
100
96
  post = post_with_two_files
101
97
  a, b = post.sorted_files
102
-
98
+
103
99
  post.files_as_attachments.should == [
104
- {name: 'a.txt', url: a.file.url},
100
+ {name: 'a.txt', url: a.file.url},
105
101
  {name: 'b.txt', url: b.file.url}
106
102
  ]
107
103
  end
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Attachments" do
4
- with_tmp_spec_dir
3
+ describe "Attachments" do
5
4
  with_models
6
- with_files
7
5
  login_as :user
8
6
 
9
7
  before do
@@ -12,13 +10,12 @@ describe "Attachments" do
12
10
  after do
13
11
  @a.close if @a
14
12
  end
15
-
13
+
16
14
  it "smoke test" do
17
15
  item = Factory.create :item, name: 'my note', attachments_as_attachments: [@a]
18
16
  item.reload
19
-
17
+
20
18
  item.attachments.size.should == 1
21
- # item.attachments.first.file.path.should =~ /\/my note\/a\.txt/
22
- item.attachments.first.file.path.should =~ /\/#{item.id}\/a\.txt/
19
+ item.attachments.first.file.file.path.should =~ /\/#{item._id}\/a\.txt/
23
20
  end
24
21
  end
@@ -1,30 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Authorization" do
4
- with_models
5
-
3
+ describe "Authorization" do
4
+ with_models
5
+
6
6
  describe "Roles" do
7
- it "user should have it's name in roles" do
7
+ it "user should have its name in roles" do
8
8
  user = Factory.build :user, name: 'some_name'
9
9
  user.roles.should include('user:some_name')
10
10
  end
11
-
11
+
12
12
  it ":anonymous, :registered, :user roles" do
13
13
  anonymous = Factory.build :anonymous
14
14
  anonymous.roles.should == %w{anonymous user user:anonymous}
15
-
15
+
16
16
  user = Factory.build :user, name: 'john'
17
17
  user.roles.should == %w{registered user user:john}
18
-
18
+
19
19
  admin = Factory.build :admin, name: 'john'
20
20
  admin.roles.should == %w{admin manager member registered user user:john}
21
21
  end
22
-
22
+
23
23
  it "all managers should also have the member role, always" do
24
24
  user = Factory.build :manager, name: 'john'
25
25
  user.roles.should == %w{manager member registered user user:john}
26
26
  end
27
-
27
+
28
28
  it "handy methods" do
29
29
  u = Factory.build :anonymous
30
30
  u.roles.anonymous?.should be_true
@@ -32,7 +32,7 @@ describe "Authorization" do
32
32
  u.roles.has?(:anonymous).should be_true
33
33
  u.should have_role(:anonymous)
34
34
  end
35
-
35
+
36
36
  it "add_role" do
37
37
  u = Factory.build :member, name: 'john'
38
38
  u.should_not have_role('manager')
@@ -40,8 +40,8 @@ describe "Authorization" do
40
40
  u.save!
41
41
  u.reload
42
42
  u.should have_role('manager')
43
- end
44
-
43
+ end
44
+
45
45
  it "remove_role" do
46
46
  u = Factory.build :manager, name: 'john'
47
47
  u.remove_role :member
@@ -50,14 +50,14 @@ describe "Authorization" do
50
50
  u.should_not have_role('manager')
51
51
  u.should_not have_role('member')
52
52
  end
53
-
53
+
54
54
  it "should add also all lover roles" do
55
55
  u = Factory.build :user, name: 'john'
56
56
  u.roles.should_not include('member')
57
57
  u.add_role :manager
58
58
  u.roles.should include('member')
59
59
  end
60
-
60
+
61
61
  it "special case, admin role" do
62
62
  u = Factory.build :user, name: 'john'
63
63
  u.should_not have_role('manager')
@@ -67,7 +67,7 @@ describe "Authorization" do
67
67
  u.should have_role('admin')
68
68
  u.should have_role('manager')
69
69
  end
70
-
70
+
71
71
  it "major_roles" do
72
72
  u = Factory.build :member, name: 'john'
73
73
  u.add_role :director
@@ -1,110 +1,110 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Authorized Object" do
3
+ describe "Authorized Object" do
4
4
  with_models
5
-
6
- before :all do
5
+
6
+ before :all do
7
7
  class ::AModel
8
- include Mongoid::Document
9
- include Mongoid::AuthorizedObject
10
- end
11
- end
8
+ inherit Mongo::Model
9
+ inherit Models::AuthorizedObject
10
+ end
11
+ end
12
12
  after(:all){remove_constants :AModel}
13
-
13
+
14
14
  def custom_permissions= value
15
- Mongoid::Authorized.custom_permissions = value
15
+ Models::Authorized.custom_permissions = value
16
16
  end
17
-
17
+
18
18
  after{self.custom_permissions = {}}
19
-
19
+
20
20
  describe "Owner, Viewers, Collaborators" do
21
- before do
21
+ before do
22
22
  rad.delete :user
23
23
  @user = Factory.create :user, name: 'auser'
24
24
  end
25
-
25
+
26
26
  it "should be abel to create objects (from error)" do
27
27
  rad.user = @user
28
28
  o = AModel.new
29
29
  o.save!
30
- end
31
-
30
+ end
31
+
32
32
  it "should by default set current user_name as owner_name if there is current user" do
33
33
  o = AModel.new
34
34
  o.owner_name.should be_nil
35
-
35
+
36
36
  rad.user = @user
37
37
  o = AModel.new
38
38
  o.owner_name.should == 'auser'
39
39
  end
40
-
40
+
41
41
  it "owner" do
42
42
  o = AModel.new
43
43
  o.owner = @user
44
- o.owner_name.should == @user.name
45
- o.viewers.should == %w{manager user:auser}
44
+ o.owner_name.should == @user.name
45
+ o.viewers.should == %w{manager user:auser}
46
46
  o.should be_valid
47
47
  end
48
-
48
+
49
49
  it 'viewers' do
50
50
  o = AModel.new
51
51
  o.owner = @user
52
52
  o.add_viewer :user
53
53
  o.viewers.should == %w{manager member user user:auser}
54
54
  o.should be_valid
55
-
55
+
56
56
  o.remove_viewer :user
57
57
  o.viewers.should == %w{manager user:auser}
58
58
  o.should be_valid
59
-
59
+
60
60
  o.add_viewer :member
61
61
  o.viewers.should == %w{manager member user:auser}
62
62
  o.should be_valid
63
-
63
+
64
64
  o.add_viewer :user
65
65
  o.viewers.should == %w{manager member user user:auser}
66
66
  o.should be_valid
67
67
  end
68
-
68
+
69
69
  it "duplicate roles (from error)" do
70
70
  o = AModel.new
71
71
  o.owner = @user
72
72
  o.save!
73
-
73
+
74
74
  o = AModel.first # don't use reload, it willn't catch this error
75
75
  o.viewers.should == %w{manager user:auser}
76
76
  end
77
-
77
+
78
78
  it "collaborators" do
79
79
  o = AModel.new
80
80
  o.owner = @user
81
81
  o.add_collaborator :member
82
82
  o.collaborators.should == %w{member}
83
83
  o.should be_valid
84
-
84
+
85
85
  o.add_collaborator :director
86
86
  o.collaborators.should == %w{member director}
87
87
  o.should be_valid
88
-
88
+
89
89
  o.remove_collaborator :member
90
90
  o.collaborators.should == %w{director}
91
91
  o.should be_valid
92
92
  end
93
-
93
+
94
94
  it "normalized_collaborators" do
95
95
  o = AModel.new
96
96
  o.owner = @user
97
97
  o.add_collaborator :member
98
98
  o.normalized_collaborators.should == %w{manager member user:auser}
99
99
  end
100
-
100
+
101
101
  it "anonymous should never be collaborator (from error)" do
102
102
  @user = Factory.build :anonymous
103
103
  o = AModel.new
104
104
  o.owner = @user
105
105
  o.normalized_collaborators.should == []
106
106
  end
107
-
107
+
108
108
  it "viewers and collaborators dependance" do
109
109
  o = AModel.new
110
110
  o.owner = @user
@@ -112,16 +112,16 @@ describe "Authorized Object" do
112
112
  o.collaborators.should == %w{user}
113
113
  o.viewers.should == %w{manager member user user:auser}
114
114
  o.should be_valid
115
-
115
+
116
116
  o.remove_viewer :member
117
117
  o.viewers.should == %w{manager user user:auser}
118
118
  o.collaborators.should == %w{user}
119
-
119
+
120
120
  o.remove_viewer :user
121
121
  o.viewers.should == %w{manager user:auser}
122
122
  o.collaborators.should == %w{}
123
123
  end
124
-
124
+
125
125
  it "major viewers" do
126
126
  o = AModel.new
127
127
  o.owner = @user
@@ -130,31 +130,31 @@ describe "Authorized Object" do
130
130
  o.viewers.should == %w{director manager member user:auser}
131
131
  o.minor_viewers.should == %w{director member user:auser}
132
132
  end
133
-
133
+
134
134
  it "collaborators should be able to change object (from error)" do
135
135
  col = Factory.create :member, name: 'collaborator'
136
-
136
+
137
137
  o = AModel.new
138
- o.owner = @user
138
+ o.owner = @user
139
139
  col.can?(:update, o).should be_false
140
-
140
+
141
141
  o.add_collaborator :member
142
- o.clear_cache
142
+ o._cache.clear
143
143
  col.can?(:update, o).should be_true
144
144
  @user.can?(:update, o).should be_true
145
-
145
+
146
146
  o.save!
147
- o = AModel.find o.id
147
+ o = AModel.by_id o._id
148
148
  col.can?(:update, o).should be_true
149
149
  @user.can?(:update, o).should be_true
150
150
  end
151
-
151
+
152
152
  it 'should allow to create public or private (by default) objects'
153
153
  end
154
-
154
+
155
155
  describe "Permissions" do
156
156
  describe "General" do
157
- before do
157
+ before do
158
158
  self.custom_permissions = {'manage' => %w{manager}}
159
159
  end
160
160
 
@@ -162,38 +162,38 @@ describe "Authorized Object" do
162
162
  u = Models::User.new
163
163
  u.can?(:manage, AModel)
164
164
  end
165
-
165
+
166
166
  it 'permissions' do
167
167
  u = Factory.create :user
168
168
  u.can?(:manage, AModel).should be_false
169
-
170
- u = Factory.create :manager
169
+
170
+ u = Factory.create :manager
171
171
  u.can?(:manage, AModel).should be_true
172
- end
172
+ end
173
173
  end
174
-
174
+
175
175
  describe "as Owner" do
176
176
  before do
177
177
  self.custom_permissions = {'manage' => %w{manager owner}}
178
-
179
- @user = Factory.create :user
180
-
181
- @object = AModel.new
178
+
179
+ @user = Factory.create :user
180
+
181
+ @object = AModel.new
182
182
  @owned_object = AModel.new
183
183
  @owned_object.owner = @user
184
184
  end
185
-
186
- it "owner?" do
185
+
186
+ it "owner?" do
187
187
  @user.should_not be_owner(@object)
188
- @user.should be_owner(@owned_object)
188
+ @user.should be_owner(@owned_object)
189
189
  end
190
-
190
+
191
191
  it "anonymous should never be owner of anything" do
192
192
  @user = Factory.build :anonymous
193
-
193
+
194
194
  @owned_object = AModel.new
195
195
  @owned_object.owner = @user
196
-
196
+
197
197
  @user.should_not be_owner(@owned_object)
198
198
  end
199
199
 
@@ -202,60 +202,60 @@ describe "Authorized Object" do
202
202
  @user.can?(:manage, @owned_object).should be_true
203
203
  end
204
204
  end
205
-
205
+
206
206
  describe "Special :view permission" do
207
- before do
207
+ before do
208
208
  # managers can see anything, always, it's hardcoded
209
209
  self.custom_permissions = {'view' => %w{manager}}
210
210
  end
211
-
211
+
212
212
  it "user (public) viewers" do
213
213
  user = Factory.create :user
214
-
214
+
215
215
  o = AModel.new
216
216
  o.stub!(:viewers){%w{user}}
217
-
217
+
218
218
  user.can?(:view, o).should be_true
219
219
  end
220
-
220
+
221
221
  it "member viewers" do
222
222
  self.custom_permissions = {'view' => []}
223
-
223
+
224
224
  user = Factory.create :user
225
225
  member = Factory.create :member
226
226
  manager = Factory.create :manager
227
-
227
+
228
228
  o = AModel.new
229
229
  o.stub!(:viewers).and_return(%w{member manager})
230
-
230
+
231
231
  user.can?(:view, o).should be_false
232
232
  member.can?(:view, o).should be_true
233
233
  manager.can?(:view, o).should be_true
234
234
  end
235
-
235
+
236
236
  it "owner (private) viewers" do
237
237
  self.custom_permissions = {'view' => []}
238
-
238
+
239
239
  owner = Factory.create :user, name: "aname"
240
240
  user = Factory.create :user
241
241
  member = Factory.create :member
242
242
  manager = Factory.create :manager
243
-
243
+
244
244
  o = AModel.new
245
245
  o.stub!(:owner_name){owner.name}
246
246
  o.stub!(:viewers){%w{user:aname manager}}
247
-
247
+
248
248
  owner.can?(:view, o).should be_true
249
249
  user.can?(:view, o).should be_false
250
250
  member.can?(:view, o).should be_false
251
251
  manager.can?(:view, o).should be_true
252
252
  end
253
-
253
+
254
254
  it "should correct works with non authorized objects (from error)" do
255
- user = Factory.create :user
255
+ user = Factory.create :user
256
256
  user.can?(:view, Object.new).should be_false
257
257
  end
258
258
  end
259
-
259
+
260
260
  end
261
261
  end