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,49 +3,53 @@ require 'spec_helper'
3
3
  describe "item" do
4
4
  with_models
5
5
  login_as :user
6
-
6
+
7
7
  it 'slug validation (from error)' do
8
8
  i = Factory.create :item
9
9
  i.slug = 'space '
10
10
  i.should_not be_valid
11
11
  end
12
-
13
- describe 'safe_query' do
14
- it "general case" do
15
- Models::Item.safe_query(
16
- name: 'name',
17
- created_at: '10/11/2000',
18
- order: "state asc",
19
- owner_name: 'name',
20
- state: ['state'],
21
- tags: 'tag',
22
- _type: 'Note',
23
- updated_at: ['10/11/2000'],
24
-
25
- viewers: 'role',
26
- collaborators: 'role'
27
- ).should == [{
28
- "name"=>"name",
29
- "created_at" => "10/11/2000".to_time,
30
- "order" => "state asc",
31
- "owner_name" => "name",
32
- "state" => ["state"],
33
- "tags" => "tag",
34
- "_type" => "Note",
35
- "updated_at" => ["10/11/2000".to_time]
36
- }, true]
37
- end
38
-
39
- it "should allow only one-level order and only indexed keywords" do
40
- Models::Item.safe_query(order: "name").should == [{'order' => "name"}, false]
41
- Models::Item.safe_query(order: "name desc").should == [{'order' => "name desc"}, false]
42
- Models::Item.safe_query(order: "name asc").should == [{'order' => "name asc"}, false]
43
-
44
- Models::Item.safe_query(order: "dependent").should == [{}, true] # not indexed
45
-
46
- # two level order
47
- Models::Item.safe_query(order: "name created_at").should == [{'order' => 'name'}, true]
48
- Models::Item.safe_query(order: "name created_at desc").should == [{'order' => 'name'}, true]
49
- end
50
- end
12
+
13
+ # describe 'safe_query' do
14
+ # it "general case" do
15
+ # Models::Item.safe_query(
16
+ # name: 'name',
17
+ # created_at: '10/11/2000',
18
+ # sort: [['state', -1]], #"state asc",
19
+ # owner_name: 'name',
20
+ # state: ['state'],
21
+ # tags: 'tag',
22
+ # # _class: 'Note',
23
+ # updated_at: ['10/11/2000'],
24
+ #
25
+ # viewers: 'role',
26
+ # collaborators: 'role'
27
+ # ).should == [{
28
+ # "name"=>"name",
29
+ # "created_at" => "10/11/2000".to_time,
30
+ # # "order" => "state asc",
31
+ # "owner_name" => "name",
32
+ # "state" => ["state"],
33
+ # "tags" => "tag",
34
+ # # "_class" => "Note",
35
+ # "updated_at" => ["10/11/2000".to_time]
36
+ # },
37
+ # {
38
+ # 'sort' => [['state', -1]]
39
+ # },
40
+ # true]
41
+ # end
42
+ #
43
+ # # it "should allow only one-level order and only indexed keywords" do
44
+ # # Models::Item.safe_query(order: "name").should == [{'order' => "name"}, false]
45
+ # # Models::Item.safe_query(order: "name desc").should == [{'order' => "name desc"}, false]
46
+ # # Models::Item.safe_query(order: "name asc").should == [{'order' => "name asc"}, false]
47
+ # #
48
+ # # Models::Item.safe_query(order: "dependent").should == [{}, true] # not indexed
49
+ # #
50
+ # # # two level order
51
+ # # Models::Item.safe_query(order: "name created_at").should == [{'order' => 'name'}, true]
52
+ # # Models::Item.safe_query(order: "name created_at desc").should == [{'order' => 'name'}, true]
53
+ # # end
54
+ # end
51
55
  end
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Role" do
3
+ describe "Role" do
4
4
  with_models
5
-
5
+
6
6
  it "normalization" do
7
7
  Role.normalize_roles(%w{manager member specific_role user:user1}).should == %w{member specific_role user:user1}
8
8
  end
9
-
9
+
10
10
  it "denormalization to higher roles" do
11
11
  Role.denormalize_to_higher_roles(%w{member specific_role user:user1}).should == %w{manager member specific_role user:user1}
12
12
  end
13
-
13
+
14
14
  it "denormalization to lower roles" do
15
15
  Role.denormalize_to_lower_roles(%w{member specific_role user:user1}).should == %w{member specific_role user user:user1}
16
16
  end
@@ -3,42 +3,68 @@ require 'spec_helper'
3
3
  describe "Tags" do
4
4
  with_models
5
5
  login_as :user
6
-
6
+
7
+ it "contextual tags" do
8
+ tags = Models::Tags.new ['a', 'b', 'viewers:alex']
9
+ tags.as_string.should == 'a, b, viewers:alex'
10
+
11
+ tags.topic.should == ['a', 'b']
12
+ tags.topic.as_string.should == 'a, b'
13
+
14
+ tags.viewers.should == ['viewers:alex']
15
+ tags.viewers.as_string.should == 'viewers:alex'
16
+
17
+ tags.topic = 'c, d, other:a'
18
+ tags.should == ['c', 'd', 'viewers:alex']
19
+
20
+ tags.viewers = 'viewers:john, a'
21
+ tags.should == ['c', 'd', 'viewers:john']
22
+ end
23
+
7
24
  it "should create tags with constructor initializer (from error)" do
8
- item = Models::Item.new name: 'item', tags: ['a', 'b']
25
+ item = Models::Item.new name: 'item'
26
+ item.tags = ['a', 'b']
9
27
  item.save!
10
-
28
+
11
29
  item.reload
12
- item.tags.should == ['a', 'b']
13
- Models::Tag.count.should == 2
14
- Models::Tag.all.collect(&:name).sort.should == ['a', 'b']
30
+ item.tags.topic.should == ['a', 'b']
31
+ all_tags = Models::Tag.all.collect(&:name)
32
+ all_tags.should include('a')
33
+ all_tags.should include('b')
15
34
  end
16
-
35
+
17
36
  it "should create tags" do
18
- item = Factory.create :item, tags_as_string: 'a, b'
37
+ item = Factory.create :item, topics_as_string: 'a, b'
19
38
  Models::Item.count.should == 1
20
39
  item.reload
21
- item.tags.should == ['a', 'b']
22
-
23
- Models::Tag.count.should == 2
24
- Models::Tag.all.collect(&:name).sort.should == ['a', 'b']
40
+ item.tags.topic.should == ['a', 'b']
41
+
42
+ all_tags = Models::Tag.all.collect(&:name)
43
+ all_tags.should include('a')
44
+ all_tags.should include('b')
25
45
  end
26
-
46
+
27
47
  it "should update tags after item update" do
28
- item = Factory.create :item, tags_as_string: 'a, b'
29
- Models::Tag.count.should == 2
30
-
48
+ item = Factory.create :item, topics_as_string: 'a, b'
49
+ all_tags = Models::Tag.all.collect(&:name)
50
+ all_tags.should include('a')
51
+ all_tags.should include('b')
52
+
31
53
  item.tags = ['a', 'c']
32
54
  item.save!
33
55
 
34
- Models::Tag.count.should == 2
35
- Models::Tag.all.collect(&:name).sort.should == ['a', 'c']
56
+ all_tags = Models::Tag.all.collect(&:name)
57
+ all_tags.should include('a')
58
+ all_tags.should_not include('b')
59
+ all_tags.should include('c')
36
60
  end
37
-
61
+
38
62
  it "should update tags after item deletion" do
39
- item = Factory.create :item, tags_as_string: 'a, b'
40
- Models::Tag.count.should == 2
63
+ item = Factory.create :item, topics_as_string: 'a, b'
64
+ Models::Tag.count.should > 0
41
65
  item.destroy
42
66
  Models::Tag.count.should == 0
43
67
  end
68
+
69
+
44
70
  end
@@ -1,38 +1,28 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe "Uploading" do
5
- with_tmp_spec_dir
6
- with_mongoid
7
- with_files
4
+ describe "Uploading" do
5
+ with_mongo_model
6
+ with_file_model
8
7
 
9
8
  before :all do
10
- class TheImageUploader < Models::FileUploader
9
+ class TheFile < Models::BaseFile
11
10
  end
12
-
11
+
13
12
  class ThePost
14
- include Mongoid::Document
13
+ inherit Mongo::Model, Mongo::Model::FileModel
15
14
 
16
- field :name, type: String, default: ""
17
- validates_uniqueness_of :name
18
-
19
- mount_uploader :image, TheImageUploader
20
- end
21
- end
22
- after(:all){remove_constants :ThePost, :TheImageUploader}
15
+ mount_file :file, TheFile
16
+ end
17
+ end
18
+ after(:all){remove_constants :ThePost, :TheFile}
23
19
 
24
20
  it "should preserve spaces and unicode characters in filename" do
25
21
  File.open "#{spec_dir}/файл с пробелами.txt" do |f|
26
- ship = ThePost.new image: f
22
+ post = ThePost.create! file: f
27
23
 
28
- ship.image.url.should =~ /\/файл с пробелами\.txt/
29
- ship.image.filename =~ /файл с пробелами\.txt/
30
- ship.image.path =~ /\/файл с пробелами\.txt/
31
-
32
- # ship.smart_url.should =~ /files\/file with spaces\/file with spaces\.txt\?\d/
33
- # f.smart_url.should =~ /files\/data\/ship\?\d+/
34
- # f.smart_url(:icon).should =~ /images\/mime\/dat_icon\.png/
35
- # f.smart_url(:thumb).should =~ /images\/mime\/dat_thumb\.png/
24
+ post.file.url.should =~ /\/файл с пробелами\.txt/
25
+ post.file.file.path =~ /файл с пробелами\.txt/
36
26
  end
37
27
  end
38
28
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Rad Mongoid basics" do
4
+ with_mongo_model
5
+ after(:all){remove_constants :Post}
6
+
7
+ it "to_rson" do
8
+ class Post
9
+ inherit Mongo::Model
10
+
11
+ attr_accessor :text
12
+ available_as_markup :text
13
+
14
+ validates_presence_of :text
15
+ end
16
+
17
+ post = Post.new
18
+ post.valid?.should be_false
19
+ post.errors[:original_text].should be_present
20
+
21
+ post = Post.new
22
+ post.original_text = "<h1>Hello</h1>"
23
+ post.text.should == "<h1>Hello</h1>"
24
+ post.save.should be_true
25
+ end
26
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,13 +3,15 @@ require 'rspec_ext'
3
3
  require 'rad'
4
4
  require 'rad/spec'
5
5
 
6
- require 'kit/spec'
7
-
8
- # rad.config.runtime_path = 'tmp'
9
6
  rad.kit
10
7
 
8
+ require 'kit/spec'
11
9
  require 'kit/factories'
12
10
 
13
11
  require 'spec_helper/user.rb'
14
12
  require 'spec_helper/controller'
15
- require 'spec_helper/factories'
13
+ require 'spec_helper/factories'
14
+
15
+ def logout_path; '' end
16
+ def login_path; '' end
17
+ def signup_path; '' end
@@ -1,14 +1,14 @@
1
1
  require 'factory_girl'
2
2
 
3
- #
3
+ #
4
4
  # User
5
- #
5
+ #
6
6
  Factory.define :anonymous, class: 'Models::User' do |u|
7
7
  u.name 'anonymous'
8
8
  end
9
9
 
10
10
  Factory.define :user, class: 'Models::User' do |u|
11
- u.sequence(:name){|i| "user#{i}"}
11
+ u.sequence(:name){|i| "user#{i}"}
12
12
  end
13
13
 
14
14
  Factory.define :registered, parent: :user do |u|
@@ -1,16 +1,13 @@
1
1
  class Models::User
2
- include Mongoid::Document
2
+ inherit Mongo::Model
3
3
 
4
- field :name, type: String
4
+ attr_accessor :name
5
5
 
6
- include Mongoid::Authorized
7
-
8
- # def self.anonymous_name; 'anonymous' end
9
- # def anonymous?; name == self.class.anonymous_name end
6
+ inherit Models::Authorized
10
7
 
11
8
  class << self
12
9
  def avatar_url *a; end
13
-
10
+
14
11
  inject current: :user
15
12
  end
16
13
  end
@@ -2,28 +2,28 @@ require 'text_utils/spec_helper'
2
2
 
3
3
  describe "Markdown" do
4
4
  include RSpec::TextUtilsHelper
5
-
5
+
6
6
  before do
7
7
  @processor = TextUtils::CodeHighlighter.new
8
8
  @options = {format: :html}
9
9
  end
10
-
10
+
11
11
  it_should_behave_like 'text processor'
12
-
12
+
13
13
  it "basic" do
14
14
  process(%{<p> text </p><code lang='ruby'>class A; p "Hello World" end</code><p> text </p>}).should =~ /span/i
15
15
  process(%{<p> text </p><code language='ruby'>class A; p "Hello World" end</code><p> text </p>}).should =~ /span/i
16
16
  process(%{<code lang='ruby'>\nclass A \n def p\n 10\n end\nend \n</code>}).should =~ /span/i
17
17
  end
18
-
18
+
19
19
  it "should works with < and > in code" do
20
20
  process(%{<code lang='ruby'>class A < ClassB; end</code>}).should include('ClassB')
21
21
  end
22
-
22
+
23
23
  it 'should preserve custom classes in <code>' do
24
24
  process(%{<code lang='ruby' class='my_code'>\nclass A \n def p\n 10\n end\nend \n</code>}).should =~ /my_code/i
25
25
  end
26
-
26
+
27
27
  it 'markdown' do
28
28
  markdown = <<MARKDOWN
29
29
  text
@@ -32,7 +32,7 @@ text
32
32
  print "Hello World"
33
33
  ```
34
34
  MARKDOWN
35
-
35
+
36
36
  process(markdown).should =~ /span/i
37
37
  end
38
38
  end
@@ -2,15 +2,15 @@ require 'text_utils/spec_helper'
2
2
 
3
3
  describe "Markdown" do
4
4
  include RSpec::TextUtilsHelper
5
-
5
+
6
6
  before do
7
7
  markdown = TextUtils::Markdown.new
8
8
  @processor = TextUtils::CustomMarkdown.new markdown
9
9
  @options = {format: :markdown}
10
10
  end
11
-
11
+
12
12
  it_should_behave_like 'text processor'
13
-
13
+
14
14
  it "should apply markup inside of html elements (from error)" do
15
15
  html = <<HTML
16
16
  <div class='right'>
@@ -19,16 +19,16 @@ describe "Markdown" do
19
19
 
20
20
  [img]: /some_link
21
21
  HTML
22
-
22
+
23
23
  to_doc(html).css('.right img').size.should == 1
24
24
  end
25
-
25
+
26
26
  it "should leave existing links intact" do
27
27
  doc = to_doc(%{<a href="http://some_domain.com">http://some_domain.com</a>})
28
28
  doc.css('a').size.should == 1
29
29
  doc.css('a').first['href'].should == "http://some_domain.com"
30
- end
31
-
30
+ end
31
+
32
32
  describe 'image box' do
33
33
  it "should use simplifyed syntax for image boxes (!![img_thumb] => [![img_thumb]][img_full_version])" do
34
34
  html = <<HTML
@@ -45,10 +45,10 @@ HTML
45
45
  doc = to_doc html
46
46
  doc.css('a').first.to_fuzzy_hash.should == {href: "/some_prefix/image_name.png"}
47
47
  doc.css('a img').first.to_fuzzy_hash.should == {src: "/some_prefix/image_name.thumb.png"}
48
-
48
+
49
49
  doc.css('a').last.to_fuzzy_hash.should == {href: "/some_prefix/image_name2.png"}
50
50
  doc.css('a img').last.to_fuzzy_hash.should == {src: "/some_prefix/image_name2.icon.png"}
51
-
51
+
52
52
  doc.css('img').size.should == 4
53
53
  end
54
54
 
@@ -61,19 +61,19 @@ HTML
61
61
  # discarded
62
62
  # it "clear div" do
63
63
  # html = "[clear]"
64
- #
64
+ #
65
65
  # doc = to_doc html
66
66
  # doc.css('div.clear').size.should == 1
67
67
  # end
68
-
68
+
69
69
  # discarded
70
70
  # it "space div" do
71
71
  # html = "[space]"
72
- #
72
+ #
73
73
  # doc = to_doc html
74
74
  # doc.css('div.space').size.should == 1
75
- # end
76
-
75
+ # end
76
+
77
77
  # discarded
78
78
  # it "should skip empty paragraphs" do
79
79
  # html = "line 1\n\nline 2\n\n\n\nline 3"