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
@@ -1,148 +1,148 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Authorizations" do
3
+ describe "Authorizations" do
4
4
  with_controllers
5
-
5
+
6
6
  isolate :config
7
-
8
- before :all do
7
+
8
+ before :all do
9
9
  @permissions = {
10
10
  'call_controller_level' => [],
11
11
  'call_business_logic_level' => [],
12
12
  'call_with_owner' => []
13
13
  }
14
-
14
+
15
15
  class ::AuthorizationController
16
16
  inherit Rad::Controller::Http
17
-
17
+
18
18
  inherit Rad::Controller::Authorized
19
-
19
+
20
20
  require_permission :call_controller_level, only: :controller_level
21
-
21
+
22
22
  def unprotected
23
23
  render_ok
24
24
  end
25
-
25
+
26
26
  def controller_level
27
27
  render_ok
28
28
  end
29
-
29
+
30
30
  def business_logic_level
31
31
  require_permission :call_business_logic_level
32
32
  render_ok
33
33
  end
34
-
34
+
35
35
  def with_owner
36
36
  require_permission :call_with_owner, owned_object
37
37
  render_ok
38
38
  end
39
-
39
+
40
40
  def with_owner_controller_level
41
41
  render_ok
42
42
  end
43
43
  require_permission :call_with_owner, only: :with_owner_controller_level do
44
44
  owned_object
45
45
  end
46
-
47
- protected
46
+
47
+ protected
48
48
  def owned_object
49
49
  @@owned_object
50
50
  end
51
-
51
+
52
52
  def self.owned_object= o
53
53
  @@owned_object = o
54
54
  end
55
55
  end
56
-
56
+
57
57
  rad.router.configure do |c|
58
- c.resource :authorization_controllers, class_name: 'AuthorizationController'
58
+ c.resource :authorization_controllers, class_name: 'AuthorizationController'
59
59
  end
60
-
60
+
61
61
  I18n.locale = :en
62
- end
63
-
62
+ end
63
+
64
64
  after :all do
65
65
  remove_constants %w(AuthorizationController)
66
66
  end
67
-
67
+
68
68
  before do
69
69
  AuthorizationController.owned_object = nil
70
-
70
+
71
71
  rad.config.permissions = @permissions
72
-
72
+
73
73
  @user = Models::User.new
74
74
  rad.user = @user
75
75
  end
76
-
76
+
77
77
  def raise_authorization_error
78
78
  raise_error(UserError, /Access Denied/)
79
79
  end
80
-
80
+
81
81
  it "should allow to call unprotected methods" do
82
82
  call('/authorization_controllers/unprotected')
83
83
  response.body.should == "ok"
84
84
  end
85
-
86
- it "should allow declarative authorization at controller level" do
85
+
86
+ it "should allow declarative authorization at controller level" do
87
87
  @user.stub!(:can?).and_return(false)
88
88
  lambda{
89
89
  call '/authorization_controllers/controller_level'
90
90
  }.should raise_authorization_error
91
91
  # response.should be_redirect
92
-
92
+
93
93
  @user.stub!(:can?).and_return(true)
94
94
  call '/authorization_controllers/controller_level'
95
95
  response.body.should == "ok"
96
96
  end
97
-
98
- it "should allow declarative authorization at business logic level" do
97
+
98
+ it "should allow declarative authorization at business logic level" do
99
99
  @user.stub!(:can?).and_return(false)
100
100
  lambda{
101
101
  call '/authorization_controllers/business_logic_level'
102
102
  }.should raise_authorization_error
103
103
  # response.should be_redirect
104
-
104
+
105
105
  @user.stub!(:can?).and_return(true)
106
106
  call '/authorization_controllers/business_logic_level'
107
107
  response.body.should == "ok"
108
108
  end
109
-
109
+
110
110
  it "should use owner if provided" do
111
111
  @user.stub!(:can?){false}
112
112
  lambda{
113
113
  call '/authorization_controllers/with_owner'
114
114
  }.should raise_authorization_error
115
115
  # response.should be_redirect
116
-
117
-
116
+
117
+
118
118
  o = Object.new
119
119
  o.stub!(:owner_name){@user.name}
120
- AuthorizationController.owned_object = o
121
-
122
- @user.stub!(:can?) do |operation, object|
120
+ AuthorizationController.owned_object = o
121
+
122
+ @user.stub!(:can?) do |operation, object|
123
123
  object and object.owner_name == @user.name
124
124
  end
125
-
125
+
126
126
  call '/authorization_controllers/with_owner'
127
127
  response.body.should == "ok"
128
128
  end
129
-
130
- it "should use owner if provided (action level)" do
129
+
130
+ it "should use owner if provided (action level)" do
131
131
  @user.stub!(:can?){false}
132
132
  lambda{
133
133
  call '/authorization_controllers/with_owner_controller_level'
134
134
  }.should raise_authorization_error
135
135
  # response.should be_redirect
136
-
137
-
136
+
137
+
138
138
  o = Object.new
139
139
  o.stub!(:owner_name){@user.name}
140
140
  AuthorizationController.owned_object = o
141
-
142
- @user.stub!(:can?) do |operation, object|
141
+
142
+ @user.stub!(:can?) do |operation, object|
143
143
  object and object.owner_name == @user.name
144
144
  end
145
-
145
+
146
146
  call '/authorization_controllers/with_owner_controller_level'
147
147
  response.body.should == "ok"
148
148
  end
@@ -4,63 +4,63 @@ describe "Captcha" do
4
4
  before :all do
5
5
  class TheController
6
6
  inherit Rad::Controller::Http, Rad::Controller::Captcha
7
-
7
+
8
8
  def action
9
9
  render inline: 'ok'
10
10
  end
11
- end
12
- end
11
+ end
12
+ end
13
13
  after(:all){remove_constants :TheController}
14
-
14
+
15
15
  before do
16
16
  rad.captcha.stub!(:enabled).and_return(true)
17
17
 
18
18
  @request = Rad::Http::Request.stub
19
19
  @request.stub!(:from_browser?).and_return(true)
20
-
20
+
21
21
  @params = Rad::Conveyors::Params.new
22
-
22
+
23
23
  @controller = TheController.new
24
24
  @controller.stub!(:request).and_return(@request)
25
25
  @controller.stub!(:params).and_return(@params)
26
26
  end
27
-
27
+
28
28
  it "should allow get for anyone" do
29
29
  @request.stub!(:get?).and_return(true)
30
-
30
+
31
31
  rad.user = Factory.build :anonymous
32
32
  @controller.call(:action).should == 'ok'
33
-
33
+
34
34
  rad.user = Factory.build :registered
35
35
  @controller.call(:action).should == 'ok'
36
36
  end
37
-
37
+
38
38
  it "shouldn't allow non-get for anonymous" do
39
39
  @request.stub!(:get?).and_return(false)
40
-
40
+
41
41
  rad.user = Factory.build :anonymous
42
42
  -> {@controller.call(:action)}.should raise_error(UserError)
43
-
43
+
44
44
  rad.user = Factory.build :registered
45
45
  @controller.call(:action).should == 'ok'
46
46
  end
47
-
47
+
48
48
  it "should display captcha form for anonymous if format is :js" do
49
- @request.stub!(:get?).and_return(false)
49
+ @request.stub!(:get?).and_return(false)
50
50
  @params.format = 'js'
51
51
  rad.captcha.stub!(:verify).and_return(false)
52
52
  rad.user = Factory.build :anonymous
53
53
  @controller.stub!(:render).and_return('form')
54
-
54
+
55
55
  @controller.call(:action).should == 'form'
56
56
  end
57
-
57
+
58
58
  it "should allow anonymous access if it solved captcha" do
59
- @request.stub!(:get?).and_return(false)
59
+ @request.stub!(:get?).and_return(false)
60
60
  @params.format = 'js'
61
61
  rad.captcha.stub!(:verify).and_return(true)
62
62
  rad.user = Factory.build :anonymous
63
-
63
+
64
64
  @controller.call(:action).should == 'ok'
65
65
  end
66
66
  end
@@ -4,51 +4,53 @@ describe "Comments" do
4
4
  with_controllers
5
5
  set_controller Controllers::Comments
6
6
  login_as :user
7
-
7
+
8
8
  before do
9
9
  @item = Factory.create :item
10
10
  end
11
-
11
+
12
12
  def create_comment original_text = 'text'
13
13
  Factory.create :comment, item: @item, owner: @user
14
14
  end
15
-
15
+
16
16
  it "should display new dialog" do
17
17
  call :new, format: 'js', item_id: @item.to_param
18
18
  response.should be_ok
19
19
  end
20
-
20
+
21
21
  it "should create Comment" do
22
22
  comment_attributes = Factory.attributes_for :comment
23
23
  pcall :create, format: 'js', item_id: @item.to_param, model: comment_attributes
24
24
  response.should be_ok
25
-
26
- Models::Comment.count.should == 1
27
- comment = Models::Comment.first
25
+
26
+ Models::Comment.count(_class: 'Models::Comment').should == 1
27
+ comment = Models::Comment.first(_class: 'Models::Comment')
28
+
28
29
  comment.original_text.should == comment_attributes[:original_text]
29
- comment.owner.should == @user
30
- comment.item.should == @item
30
+
31
+ comment.owner.name.should == @user.name
32
+ comment.item.name.should == @item.name
31
33
  end
32
-
34
+
33
35
  it "should display edit dialog" do
34
36
  comment = create_comment
35
37
  call :edit, format: 'js', id: comment.to_param
36
38
  response.should be_ok
37
39
  end
38
-
40
+
39
41
  it "should update Comment" do
40
42
  comment = create_comment
41
43
  new_attributes = {original_text: 'new text'}
42
44
  pcall :update, format: 'js', id: comment.to_param, model: new_attributes
43
45
  response.should be_ok
44
-
46
+
45
47
  comment.reload
46
48
  comment.original_text.should == 'new text'
47
49
  end
48
-
50
+
49
51
  it "should delete Comment" do
50
52
  comment = create_comment
51
53
  pcall :destroy, format: 'js', id: comment.to_param
52
- Models::Comment.count.should == 0
54
+ Models::Comment.count(_class: 'Models::Comment').should == 0
53
55
  end
54
56
  end
@@ -3,43 +3,42 @@ require 'spec_helper'
3
3
  describe "Items" do
4
4
  with_controllers
5
5
  login_as :manager, name: 'auser'
6
-
6
+
7
7
  describe "Basic" do
8
8
  set_controller Controllers::Items
9
-
10
- it "should update layout" do
9
+
10
+ it "should update layout" do
11
11
  @item = Factory.create :item
12
12
  @item.layout.should == nil
13
-
14
- pcall :layout, id: @item.to_param, value: 'home', format: 'js'
13
+
14
+ pcall :layout, id: @item.to_param, value: 'home', format: 'js'
15
15
  response.should be_ok
16
-
16
+
17
17
  @item.reload
18
18
  @item.layout.should == 'home'
19
19
  end
20
-
20
+
21
21
  it 'viewers, add_roles' do
22
22
  @item = Factory.create :item
23
23
  @item.viewers.should == %w{manager user:auser}
24
24
  @item.owner_name.should == @user.name
25
-
25
+
26
26
  pcall :viewers, id: @item.to_param, add_roles: 'user', format: 'js'
27
- response.should be_ok
28
-
27
+ response.should be_ok
28
+
29
29
  @item.reload
30
30
  @item.viewers.should == %w{manager member user user:auser}
31
31
  end
32
-
32
+
33
33
  it "should redirect to /items if no default_url specified" do
34
34
  call :redirect
35
35
  response.should redirect_to(rad.router.default_url)
36
36
  end
37
-
38
- it "should display :all"
39
- # do
40
- # call :all
41
- # response.should be_ok
42
- # end
37
+
38
+ it "should display :all" do
39
+ call :all
40
+ response.should be_ok
41
+ end
43
42
 
44
43
  end
45
44
  end
@@ -6,23 +6,23 @@ describe 'I18n' do
6
6
  before :all do
7
7
  rad.web
8
8
  rad.reset :conveyors
9
-
9
+
10
10
  I18n.load_path += Dir["#{spec_dir}/locales/*/*.{rb,yml}"]
11
11
  end
12
-
12
+
13
13
  def t *args
14
14
  I18n.t *args
15
15
  end
16
-
16
+
17
17
  it "basic" do
18
18
  I18n.locale = 'en'
19
19
  t(:name).should == "Name"
20
20
  t(:name).is_a?(String).should be_true
21
-
21
+
22
22
  I18n.locale = 'ru'
23
23
  t(:name).should == "Имя"
24
24
  end
25
-
25
+
26
26
  it "pluggable pluralization" do
27
27
  I18n.locale = 'ru'
28
28
  t(:comments_count, count: 1).should == "1 комментарий"
@@ -1,21 +1,21 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "TextUtils with Kit extensions" do
4
- it "should truncate" do
4
+ it "should truncate" do
5
5
  TextUtils.truncate('lorem ipsum', 10).should == 'lorem ...'
6
6
  end
7
-
7
+
8
8
  it "should process markdown (should qualify markdown format automatically)" do
9
9
  TextUtils.markup('lorem **ipsum**').should == '<p>lorem <strong>ipsum</strong></p>'
10
10
  end
11
-
11
+
12
12
  it "should process html (should qualify html format automatically)" do
13
13
  TextUtils.markup('<p>lorem **ipsum**</p>').should == '<p>lorem **ipsum**</p>'
14
14
  end
15
-
15
+
16
16
  it "code highlight" do
17
17
  rad.config.stub!(:use_code_highlighter).and_return(true)
18
-
18
+
19
19
  markdown = <<MARKDOWN
20
20
  code
21
21