lolita 3.4.2 → 3.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +36 -36
  3. data/Gemfile +29 -29
  4. data/README.md +147 -147
  5. data/Rakefile +6 -6
  6. data/app/assets/javascripts/lolita/application.js +6 -6
  7. data/app/assets/javascripts/lolita/tab.js +100 -100
  8. data/app/assets/stylesheets/lolita/PIE-custom.htc +87 -87
  9. data/app/assets/stylesheets/lolita/PIE.htc +81 -81
  10. data/app/assets/stylesheets/lolita/application.css +6 -6
  11. data/app/assets/stylesheets/lolita/default.css.erb +169 -169
  12. data/app/assets/stylesheets/lolita/jquery-ui-1.8.16.lolita.css.erb +567 -567
  13. data/app/assets/stylesheets/lolita/style.css.erb +553 -553
  14. data/app/helpers/components/lolita/configuration/list_component.rb +10 -10
  15. data/app/helpers/components/lolita/configuration_component.rb +20 -20
  16. data/app/views/components/lolita/configuration/column/_first.html.haml +1 -1
  17. data/app/views/components/lolita/configuration/column/header/_first.html.haml +1 -1
  18. data/app/views/components/lolita/configuration/column/header/_sort.html.haml +6 -6
  19. data/app/views/components/lolita/configuration/columns/header/_display.html.haml +5 -5
  20. data/app/views/components/lolita/configuration/field/array/checkbox/_display.html.haml +7 -7
  21. data/app/views/components/lolita/configuration/field/string/text/_display.html.haml +7 -7
  22. data/app/views/components/lolita/configuration/search/_display.html.haml +2 -2
  23. data/app/views/components/lolita/configuration/tab/_display.html.haml +3 -3
  24. data/app/views/components/lolita/configuration/tabs/_form.html.haml +6 -6
  25. data/app/views/kaminari/lolita/_first_page.html.erb +11 -11
  26. data/app/views/kaminari/lolita/_gap.html.erb +8 -8
  27. data/app/views/kaminari/lolita/_last_page.html.erb +11 -11
  28. data/app/views/kaminari/lolita/_next_page.html.erb +11 -11
  29. data/app/views/kaminari/lolita/_page.html.erb +12 -12
  30. data/app/views/kaminari/lolita/_paginator.html.erb +23 -23
  31. data/app/views/kaminari/lolita/_prev_page.html.erb +11 -11
  32. data/app/views/lolita/info/index.html.erb +232 -232
  33. data/author +1 -1
  34. data/config/routes.rb +6 -6
  35. data/lib/generators/lolita/install_generator.rb +19 -19
  36. data/lib/generators/lolita/uninstall_generator.rb +70 -70
  37. data/lib/generators/templates/lolita.rb +13 -13
  38. data/lib/lolita.rb +140 -140
  39. data/lib/lolita/adapter/abstract_adapter.rb +15 -15
  40. data/lib/lolita/adapter/active_record.rb +227 -227
  41. data/lib/lolita/adapter/common_helper.rb +221 -221
  42. data/lib/lolita/adapter/field_helper.rb +18 -18
  43. data/lib/lolita/adapter/mongoid.rb +241 -241
  44. data/lib/lolita/components/base.rb +11 -11
  45. data/lib/lolita/configuration.rb +60 -60
  46. data/lib/lolita/configuration/column.rb +181 -181
  47. data/lib/lolita/configuration/field/big_decimal.rb +12 -12
  48. data/lib/lolita/configuration/field/boolean.rb +12 -12
  49. data/lib/lolita/configuration/field/date.rb +12 -12
  50. data/lib/lolita/configuration/field/hidden.rb +12 -12
  51. data/lib/lolita/configuration/field/integer.rb +11 -11
  52. data/lib/lolita/configuration/field/string.rb +16 -16
  53. data/lib/lolita/configuration/field/time.rb +13 -13
  54. data/lib/lolita/configuration/field_set.rb +25 -25
  55. data/lib/lolita/configuration/filter.rb +116 -116
  56. data/lib/lolita/configuration/list.rb +200 -200
  57. data/lib/lolita/configuration/search.rb +104 -104
  58. data/lib/lolita/controllers/component_helpers.rb +156 -156
  59. data/lib/lolita/controllers/internal_helpers.rb +71 -71
  60. data/lib/lolita/controllers/url_helpers.rb +7 -7
  61. data/lib/lolita/dbi/base.rb +56 -56
  62. data/lib/lolita/hooks/named_hook.rb +125 -125
  63. data/lib/lolita/lazy_loader.rb +54 -54
  64. data/lib/lolita/navigation/tree.rb +132 -132
  65. data/lib/lolita/rails/engine.rb +23 -23
  66. data/lib/lolita/rails/routes.rb +129 -129
  67. data/lib/lolita/ruby_ext/accessors.rb +26 -26
  68. data/lib/lolita/search/simple.rb +75 -75
  69. data/lib/lolita/support/formatter.rb +62 -62
  70. data/lib/lolita/support/formatter/rails.rb +56 -56
  71. data/lib/lolita/system_configuration/base.rb +178 -178
  72. data/lib/lolita/test/matchers.rb +77 -77
  73. data/lib/lolita/version.rb +30 -30
  74. data/lib/tasks/tinymce-assets.rake +6 -6
  75. data/lolita.gemspec +34 -34
  76. data/spec/adapter/common_helper_spec.rb +95 -95
  77. data/spec/adapter_helper.rb +42 -42
  78. data/spec/builder_spec.rb +120 -120
  79. data/spec/configuration/base_spec.rb +22 -22
  80. data/spec/configuration/field_spec.rb +118 -118
  81. data/spec/configuration/filter_spec.rb +131 -131
  82. data/spec/configuration/tab_spec.rb +187 -187
  83. data/spec/configuration/tabs_spec.rb +120 -120
  84. data/spec/generators/lolita/install_generator_spec.rb +54 -54
  85. data/spec/generators/lolita/uninstall_generator_spec.rb +48 -48
  86. data/spec/orm/mongoid.rb +12 -12
  87. data/spec/rails_app/app/controllers/application_controller.rb +3 -3
  88. data/spec/rails_app/app/helpers/application_helper.rb +3 -3
  89. data/spec/rails_app/app/mongoid/address.rb +7 -7
  90. data/spec/rails_app/app/mongoid/category.rb +18 -18
  91. data/spec/rails_app/app/mongoid/comment.rb +5 -5
  92. data/spec/rails_app/app/mongoid/post.rb +30 -30
  93. data/spec/rails_app/app/mongoid/preference.rb +5 -5
  94. data/spec/rails_app/app/mongoid/profile.rb +13 -13
  95. data/spec/rails_app/app/mongoid/tag.rb +3 -3
  96. data/spec/rails_app/app/views/components/lolita/configuration/list/_body_cell.html.erb +1 -1
  97. data/spec/rails_app/config/application.rb +33 -33
  98. data/spec/rails_app/config/boot.rb +7 -7
  99. data/spec/rails_app/config/environment.rb +5 -5
  100. data/spec/rails_app/config/environments/development.rb +23 -23
  101. data/spec/rails_app/config/environments/production.rb +37 -37
  102. data/spec/rails_app/config/environments/test.rb +37 -37
  103. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -7
  104. data/spec/rails_app/config/initializers/inflections.rb +2 -2
  105. data/spec/rails_app/config/initializers/secret_token.rb +1 -1
  106. data/spec/rails_app/config/routes.rb +2 -2
  107. data/spec/rails_app/lib/lolita/configuration/field/my_custom_collection.rb +13 -13
  108. data/spec/rails_app/public/javascripts/jquery-1.5.1.min.js +15 -15
  109. data/spec/rails_app/public/javascripts/lolita/main.js +6 -6
  110. data/spec/rails_app/public/javascripts/modernizr-1.7.min.js +1 -1
  111. data/spec/rails_app/public/javascripts/rails.js +137 -137
  112. data/spec/rails_app/public/javascripts/tinymce/langs/en.js +221 -221
  113. data/spec/rails_app/public/javascripts/tinymce/license.txt +504 -504
  114. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/about.htm +52 -52
  115. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/anchor.htm +26 -26
  116. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/charmap.htm +51 -51
  117. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/color_picker.htm +74 -74
  118. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/editor_template_src.js +1328 -1328
  119. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/image.htm +80 -80
  120. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/about.js +73 -73
  121. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/anchor.js +42 -42
  122. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/charmap.js +354 -354
  123. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/color_picker.js +329 -329
  124. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/image.js +247 -247
  125. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/link.js +153 -153
  126. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/source_editor.js +56 -56
  127. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/langs/en.js +68 -68
  128. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/langs/en_dlg.js +53 -53
  129. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/link.htm +57 -57
  130. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/shortcuts.htm +47 -47
  131. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/content.css +66 -66
  132. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/dialog.css +117 -117
  133. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/ui.css +988 -988
  134. data/spec/rails_app/public/javascripts/tinymce/themes/advanced/source_editor.htm +25 -25
  135. data/spec/rails_app/public/javascripts/tinymce/tiny_mce_popup.js +4 -4
  136. data/spec/rails_app/public/stylesheets/lolita/default.css +169 -169
  137. data/spec/rails_app/public/stylesheets/lolita/style.css +214 -214
  138. data/spec/spec_helper.rb +51 -51
  139. data/vendor/assets/javascripts/application_vendor_lolita.js +4 -4
  140. data/vendor/assets/javascripts/jquery-numeric.js +279 -279
  141. data/vendor/assets/javascripts/modernizr_1_7_min.js +1 -1
  142. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/content.css +66 -66
  143. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/dialog.css +117 -117
  144. data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/ui.css +988 -988
  145. data/vendor/assets/stylesheets/jquery-ui-1.8.16.custom.css +567 -567
  146. metadata +4 -3
@@ -1,43 +1,43 @@
1
- if ADAPTER=='mongoid'
2
- require 'mongoid'
3
- Mongoid.configure do |config|
4
- name = "lolita3_test"
5
- host = "localhost"
6
- config.master = Mongo::Connection.new.db(name)
7
- config.slaves = [
8
- Mongo::Connection.new(host, 27017, :slave_ok => true).db(name)
9
- ]
10
- config.persist_in_safe_mode = false
11
- end
12
- else
13
- require 'active_record'
14
- ActiveRecord::Base.establish_connection({ :database => ":memory:", :adapter => 'sqlite3', :timeout => 500 })
15
- ActiveRecord::Schema.define do
16
- create_table :posts, :force => true do |t|
17
- t.string :field_one
18
- end
19
- create_table :test_class2, :force => true do |t|
20
- t.string :field_one
21
- end
22
- create_table :pages,:force=>true do |t|
23
- t.string :name
24
- end
25
- end
26
-
27
- class Comment < ActiveRecord::Base
28
- belongs_to :test_class1, :class_name=>"Post"
29
- end
30
-
31
- class Post < ActiveRecord::Base
32
- has_many :pages
33
- include Lolita::Configuration
34
- lolita
35
- end
36
-
37
- class Profile < ActiveRecord::Base
38
- include Lolita::Configuration
39
- lolita do
40
-
41
- end
42
- end
1
+ if ADAPTER=='mongoid'
2
+ require 'mongoid'
3
+ Mongoid.configure do |config|
4
+ name = "lolita3_test"
5
+ host = "localhost"
6
+ config.master = Mongo::Connection.new.db(name)
7
+ config.slaves = [
8
+ Mongo::Connection.new(host, 27017, :slave_ok => true).db(name)
9
+ ]
10
+ config.persist_in_safe_mode = false
11
+ end
12
+ else
13
+ require 'active_record'
14
+ ActiveRecord::Base.establish_connection({ :database => ":memory:", :adapter => 'sqlite3', :timeout => 500 })
15
+ ActiveRecord::Schema.define do
16
+ create_table :posts, :force => true do |t|
17
+ t.string :field_one
18
+ end
19
+ create_table :test_class2, :force => true do |t|
20
+ t.string :field_one
21
+ end
22
+ create_table :pages,:force=>true do |t|
23
+ t.string :name
24
+ end
25
+ end
26
+
27
+ class Comment < ActiveRecord::Base
28
+ belongs_to :test_class1, :class_name=>"Post"
29
+ end
30
+
31
+ class Post < ActiveRecord::Base
32
+ has_many :pages
33
+ include Lolita::Configuration
34
+ lolita
35
+ end
36
+
37
+ class Profile < ActiveRecord::Base
38
+ include Lolita::Configuration
39
+ lolita do
40
+
41
+ end
42
+ end
43
43
  end
@@ -1,121 +1,121 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/simple_spec_helper')
2
-
3
- class SimpleObject
4
- include Lolita::Builder
5
- end
6
-
7
- describe Lolita::Builder::Custom do
8
- let(:object){SimpleObject.new}
9
- let(:builder){Lolita::Builder::Custom.new(object,{})}
10
- let(:klass){Lolita::Builder::Custom}
11
-
12
- it "should create new Custom builder" do
13
- builder = Lolita::Builder::Custom.new(object,{})
14
- end
15
-
16
- it "should set name and state" do
17
- builder = Lolita::Builder::Custom.new(object,{:name => "name", :state=>"state"})
18
- builder.instance_variable_get(:"@name").should == "name"
19
- builder.instance_variable_get(:"@state").should == "state"
20
- end
21
-
22
- it "should set default attributes" do
23
- builder = Lolita::Builder::Custom.new(object,{:name => "name"})
24
- builder.instance_variable_get(:"@state").should == :display
25
- end
26
-
27
- describe "build attributes" do
28
- it "should set through #with" do
29
- builder.with("name","state").build_attributes.should == {:name => "name", :state => "state"}
30
- builder.with({:name=>"name",:state=>"state"}).build_attributes.should == {:name => "name", :state=>"state"}
31
- builder.with("name",:state=>"state").build_attributes.should == {:name=>"name",:state=>"state"}
32
- end
33
- end
34
-
35
- it "should return default state when no build attributes given" do
36
- builder.state.should == :display
37
- end
38
-
39
- it "should return build attributes state when given" do
40
- builder.with(:state=>"state").state.should == :"state"
41
- end
42
-
43
- it "should return default name when no build name given" do
44
- builder.name.should == :"/simple_object"
45
- end
46
-
47
- it "should return build name when given" do
48
- builder.with(:name => "name").name.should == :"/simple_object/name"
49
- builder.with(:name => "/name").name.should == :"/name"
50
- end
51
-
52
- describe "#build" do
53
- it "should return array with name,state and options" do
54
- builder.build.should == [:"/simple_object",:"display",{}]
55
- builder.with({:display_value => 1}).build.should == [:"/simple_object",:display,{:display_value=>1}]
56
- end
57
- end
58
-
59
- describe "conditions" do
60
- it "should use given over default when there's no conditions" do
61
- builder = klass.new(object,:name => "/custom", :state => "special")
62
- builder.build.should == [:"/custom",:"special",{}]
63
- end
64
-
65
- it "should use given over default when conditions met" do
66
- builder = klass.new(object, :name => "/custom", :state=>"special", :unless=>{:state=>"display"})
67
- builder.build.should == [:"/simple_object",:"display",{}]
68
- builder.class_eval do
69
- def default_state
70
- :other
71
- end
72
- end
73
- builder.build.should == [:"/custom",:special,{}]
74
- end
75
-
76
- it "should use given over build given when conditions met" do
77
- builder = klass.new(object,:name => "/custom", :"state" => "special", :if=>{:state=>"default"})
78
- builder.with(:state => "other").build.should == [:"/simple_object",:other,{}]
79
- builder.with(:state => :default).build.should == [:"/custom",:special,{}]
80
- end
81
- end
82
- end
83
-
84
- describe Lolita::Builder do
85
-
86
- let(:object){SimpleObject.new}
87
-
88
- describe "#build" do
89
-
90
- describe "default path" do
91
-
92
- it "should be /:class_name/display" do
93
- info=object.build
94
- info.first.should == :"/simple_object"
95
- info[1].should == :display
96
- end
97
-
98
- it "should use given name when it starts with /" do
99
- object.builder = {:name =>"/custom"}
100
- info = object.build
101
- info.first.should == :"/custom"
102
- info[1].should == :display
103
- end
104
-
105
- it "should make name /:class_name/:custom_name when it doesn't start with /" do
106
- object.builder = {:name => "custom"}
107
- info = object.build
108
- info.first.should == :"/simple_object/custom"
109
- info[1].should == :display
110
- end
111
-
112
- end
113
-
114
- it "should use received name" do
115
- object.builder = {:name=>"/custom"}
116
- info = object.build("/other_custom")
117
- info.first.should == :"/other_custom"
118
- end
119
-
120
- end
1
+ require File.expand_path(File.dirname(__FILE__) + '/simple_spec_helper')
2
+
3
+ class SimpleObject
4
+ include Lolita::Builder
5
+ end
6
+
7
+ describe Lolita::Builder::Custom do
8
+ let(:object){SimpleObject.new}
9
+ let(:builder){Lolita::Builder::Custom.new(object,{})}
10
+ let(:klass){Lolita::Builder::Custom}
11
+
12
+ it "should create new Custom builder" do
13
+ builder = Lolita::Builder::Custom.new(object,{})
14
+ end
15
+
16
+ it "should set name and state" do
17
+ builder = Lolita::Builder::Custom.new(object,{:name => "name", :state=>"state"})
18
+ builder.instance_variable_get(:"@name").should == "name"
19
+ builder.instance_variable_get(:"@state").should == "state"
20
+ end
21
+
22
+ it "should set default attributes" do
23
+ builder = Lolita::Builder::Custom.new(object,{:name => "name"})
24
+ builder.instance_variable_get(:"@state").should == :display
25
+ end
26
+
27
+ describe "build attributes" do
28
+ it "should set through #with" do
29
+ builder.with("name","state").build_attributes.should == {:name => "name", :state => "state"}
30
+ builder.with({:name=>"name",:state=>"state"}).build_attributes.should == {:name => "name", :state=>"state"}
31
+ builder.with("name",:state=>"state").build_attributes.should == {:name=>"name",:state=>"state"}
32
+ end
33
+ end
34
+
35
+ it "should return default state when no build attributes given" do
36
+ builder.state.should == :display
37
+ end
38
+
39
+ it "should return build attributes state when given" do
40
+ builder.with(:state=>"state").state.should == :"state"
41
+ end
42
+
43
+ it "should return default name when no build name given" do
44
+ builder.name.should == :"/simple_object"
45
+ end
46
+
47
+ it "should return build name when given" do
48
+ builder.with(:name => "name").name.should == :"/simple_object/name"
49
+ builder.with(:name => "/name").name.should == :"/name"
50
+ end
51
+
52
+ describe "#build" do
53
+ it "should return array with name,state and options" do
54
+ builder.build.should == [:"/simple_object",:"display",{}]
55
+ builder.with({:display_value => 1}).build.should == [:"/simple_object",:display,{:display_value=>1}]
56
+ end
57
+ end
58
+
59
+ describe "conditions" do
60
+ it "should use given over default when there's no conditions" do
61
+ builder = klass.new(object,:name => "/custom", :state => "special")
62
+ builder.build.should == [:"/custom",:"special",{}]
63
+ end
64
+
65
+ it "should use given over default when conditions met" do
66
+ builder = klass.new(object, :name => "/custom", :state=>"special", :unless=>{:state=>"display"})
67
+ builder.build.should == [:"/simple_object",:"display",{}]
68
+ builder.class_eval do
69
+ def default_state
70
+ :other
71
+ end
72
+ end
73
+ builder.build.should == [:"/custom",:special,{}]
74
+ end
75
+
76
+ it "should use given over build given when conditions met" do
77
+ builder = klass.new(object,:name => "/custom", :"state" => "special", :if=>{:state=>"default"})
78
+ builder.with(:state => "other").build.should == [:"/simple_object",:other,{}]
79
+ builder.with(:state => :default).build.should == [:"/custom",:special,{}]
80
+ end
81
+ end
82
+ end
83
+
84
+ describe Lolita::Builder do
85
+
86
+ let(:object){SimpleObject.new}
87
+
88
+ describe "#build" do
89
+
90
+ describe "default path" do
91
+
92
+ it "should be /:class_name/display" do
93
+ info=object.build
94
+ info.first.should == :"/simple_object"
95
+ info[1].should == :display
96
+ end
97
+
98
+ it "should use given name when it starts with /" do
99
+ object.builder = {:name =>"/custom"}
100
+ info = object.build
101
+ info.first.should == :"/custom"
102
+ info[1].should == :display
103
+ end
104
+
105
+ it "should make name /:class_name/:custom_name when it doesn't start with /" do
106
+ object.builder = {:name => "custom"}
107
+ info = object.build
108
+ info.first.should == :"/simple_object/custom"
109
+ info[1].should == :display
110
+ end
111
+
112
+ end
113
+
114
+ it "should use received name" do
115
+ object.builder = {:name=>"/custom"}
116
+ info = object.build("/other_custom")
117
+ info.first.should == :"/other_custom"
118
+ end
119
+
120
+ end
121
121
  end
@@ -1,23 +1,23 @@
1
- require 'simple_spec_helper'
2
-
3
- describe Lolita::Configuration::Base do
4
- let(:klass){Lolita::Configuration::Base}
5
- let(:dbp){Object.new}
6
-
7
- it "should include Lolita::Builder" do
8
- klass.ancestors.should include(Lolita::Builder)
9
- end
10
-
11
- it "should respond to dbp" do
12
- klass.new(dbp).should respond_to(:dbp)
13
- end
14
-
15
- it "should respond to dbi" do
16
- klass.new(dbp).should respond_to(:dbi)
17
- end
18
-
19
- it "should call all args hash part keys as writer methods " do
20
- klass.any_instance.should_receive(:my_method=).with(1)
21
- klass.new(dbp, :my_method => 1)
22
- end
1
+ require 'simple_spec_helper'
2
+
3
+ describe Lolita::Configuration::Base do
4
+ let(:klass){Lolita::Configuration::Base}
5
+ let(:dbp){Object.new}
6
+
7
+ it "should include Lolita::Builder" do
8
+ klass.ancestors.should include(Lolita::Builder)
9
+ end
10
+
11
+ it "should respond to dbp" do
12
+ klass.new(dbp).should respond_to(:dbp)
13
+ end
14
+
15
+ it "should respond to dbi" do
16
+ klass.new(dbp).should respond_to(:dbi)
17
+ end
18
+
19
+ it "should call all args hash part keys as writer methods " do
20
+ klass.any_instance.should_receive(:my_method=).with(1)
21
+ klass.new(dbp, :my_method => 1)
22
+ end
23
23
  end
@@ -1,118 +1,118 @@
1
- require 'spec_helper'
2
-
3
- describe Lolita::Configuration::Field do
4
- before(:each) do
5
- @dbi=Lolita::DBI::Base.create(Post)
6
- @dbi2=Lolita::DBI::Base.create(Comment)
7
- end
8
-
9
- let(:field_class){Lolita::Configuration::Field::Base}
10
- let(:factory_class){Lolita::Configuration::Factory::Field}
11
-
12
- it "should create new field" do
13
- Lolita::Configuration::Field::Base.new(@dbi,:title,:string)
14
- end
15
-
16
- it "should create field when block given" do
17
- field=field_class.new(@dbi,:title,:string) do
18
-
19
- end
20
- field.name.should == :title
21
- end
22
-
23
- it "should raise error when no name specified" do
24
- lambda{
25
- field_class.new(@dbi,nil,nil)
26
- }.should raise_error Lolita::FieldNameError
27
- end
28
-
29
- it "should raise error when class don't respond to field method when not value specified" do
30
- # Lolita::Configuration::Field.new(@dbi,:title,:value=>"Field value")
31
- # lambda{
32
- # Lolita::Configuration::Field.new(@dbi,:noname)
33
- # }.should raise_error Lolita::FieldNameError
34
- end
35
-
36
- it "should always set field title if not specified" do
37
- field=field_class.new(@dbi,:title)
38
- field.title.size.should > 0
39
- end
40
-
41
- it "should raise error when field is nested in class that do not reference to field class" do
42
- lambda{
43
- field=field_class.new(@dbi,:title,:nested_in=>Lolita::DBI::Base.new(Address))
44
- }.should raise_error Lolita::ReferenceError
45
- end
46
-
47
- it "should detect if field is nested in" do
48
- field=field_class.new(@dbi2,:body,:nested_in=>@dbi)
49
- field.nested?.should be_true
50
- end
51
-
52
- it "should detect if field is nested in given class" do
53
- field=field_class.new(@dbi2,:body,:nested_in=>@dbi)
54
- field.nested_in?(@dbi.klass).should be_true
55
- end
56
-
57
- it "should detect type and create field with specified type" do
58
- require "rails_app/lib/lolita/configuration/field/my_custom_collection"
59
- field=Lolita::Configuration::Factory::Field.add(@dbi,:comments, :my_custom_collection)
60
- field.type.should == "my_custom_collection"
61
- end
62
-
63
- it "should fallback to string type if given type is not supported" do
64
- field=Lolita::Configuration::Factory::Field.add(@dbi,:is_public)
65
- field.type.should == "boolean"
66
- end
67
-
68
- it "should change field type for association columns if custom type is given" do
69
- pending
70
- end
71
-
72
- it "should set field title when not specified" do
73
- field=field_class.new(@dbi,:title)
74
- field.title.should == "Title"
75
- end
76
-
77
- it "should allow set field that is referenced in (belongs_to) any class" do
78
- field=Lolita::Configuration::Factory::Field.add(@dbi2,:post,:array)
79
- field.type.should == "array"
80
- field.association.macro.should == :one
81
- end
82
-
83
- it "should allow set field that references to (has_many or has_one) any class" do
84
- field=Lolita::Configuration::Factory::Field.add(@dbi,:comments,:array)
85
- field.type.to_s.should == "array"
86
- field.association.macro.should == :many
87
- end
88
-
89
- it "should match state with given record state" do
90
- field = factory_class.add(@dbi, :title, :string, :on => :create)
91
- field2 = factory_class.add(@dbi, :title, :string, :on => [:update])
92
- field3 = factory_class.add(@dbi, :title, :string)
93
- field4 = factory_class.add(@dbi, :title, :string, :on => Proc.new{|rec| rec.title == "title"})
94
- record = @dbi.klass.new
95
- field.match_state_of?(record).should be_true
96
- field2.match_state_of?(record).should_not be_true
97
- field3.match_state_of?(record).should be_true
98
- field4.match_state_of?(record).should_not be_true
99
- record2 = @dbi.klass.create!(:title => "title")
100
- field.match_state_of?(record2).should_not be_true
101
- field2.match_state_of?(record2).should be_true
102
- field3.match_state_of?(record2).should be_true
103
- field4.match_state_of?(record2).should be_true
104
- end
105
-
106
- it "should match :read state for record" do
107
- field = factory_class.add(@dbi,:title,:string, :on => :create)
108
- field2 = factory_class.add(@dbi,:title,:string, :on => :read)
109
- field3 = factory_class.add(@dbi,:title,:string)
110
- record = @dbi.klass.new
111
- @dbi.switch_record_state(record,:read)
112
- field.match_state_of?(record).should_not be_true
113
- field2.match_state_of?(record).should be_true
114
- field3.match_state_of?(record).should be_true
115
- end
116
-
117
- end
118
-
1
+ require 'spec_helper'
2
+
3
+ describe Lolita::Configuration::Field do
4
+ before(:each) do
5
+ @dbi=Lolita::DBI::Base.create(Post)
6
+ @dbi2=Lolita::DBI::Base.create(Comment)
7
+ end
8
+
9
+ let(:field_class){Lolita::Configuration::Field::Base}
10
+ let(:factory_class){Lolita::Configuration::Factory::Field}
11
+
12
+ it "should create new field" do
13
+ Lolita::Configuration::Field::Base.new(@dbi,:title,:string)
14
+ end
15
+
16
+ it "should create field when block given" do
17
+ field=field_class.new(@dbi,:title,:string) do
18
+
19
+ end
20
+ field.name.should == :title
21
+ end
22
+
23
+ it "should raise error when no name specified" do
24
+ lambda{
25
+ field_class.new(@dbi,nil,nil)
26
+ }.should raise_error Lolita::FieldNameError
27
+ end
28
+
29
+ it "should raise error when class don't respond to field method when not value specified" do
30
+ # Lolita::Configuration::Field.new(@dbi,:title,:value=>"Field value")
31
+ # lambda{
32
+ # Lolita::Configuration::Field.new(@dbi,:noname)
33
+ # }.should raise_error Lolita::FieldNameError
34
+ end
35
+
36
+ it "should always set field title if not specified" do
37
+ field=field_class.new(@dbi,:title)
38
+ field.title.size.should > 0
39
+ end
40
+
41
+ it "should raise error when field is nested in class that do not reference to field class" do
42
+ lambda{
43
+ field=field_class.new(@dbi,:title,:nested_in=>Lolita::DBI::Base.new(Address))
44
+ }.should raise_error Lolita::ReferenceError
45
+ end
46
+
47
+ it "should detect if field is nested in" do
48
+ field=field_class.new(@dbi2,:body,:nested_in=>@dbi)
49
+ field.nested?.should be_true
50
+ end
51
+
52
+ it "should detect if field is nested in given class" do
53
+ field=field_class.new(@dbi2,:body,:nested_in=>@dbi)
54
+ field.nested_in?(@dbi.klass).should be_true
55
+ end
56
+
57
+ it "should detect type and create field with specified type" do
58
+ require "rails_app/lib/lolita/configuration/field/my_custom_collection"
59
+ field=Lolita::Configuration::Factory::Field.add(@dbi,:comments, :my_custom_collection)
60
+ field.type.should == "my_custom_collection"
61
+ end
62
+
63
+ it "should fallback to string type if given type is not supported" do
64
+ field=Lolita::Configuration::Factory::Field.add(@dbi,:is_public)
65
+ field.type.should == "boolean"
66
+ end
67
+
68
+ it "should change field type for association columns if custom type is given" do
69
+ pending
70
+ end
71
+
72
+ it "should set field title when not specified" do
73
+ field=field_class.new(@dbi,:title)
74
+ field.title.should == "Title"
75
+ end
76
+
77
+ it "should allow set field that is referenced in (belongs_to) any class" do
78
+ field=Lolita::Configuration::Factory::Field.add(@dbi2,:post,:array)
79
+ field.type.should == "array"
80
+ field.association.macro.should == :one
81
+ end
82
+
83
+ it "should allow set field that references to (has_many or has_one) any class" do
84
+ field=Lolita::Configuration::Factory::Field.add(@dbi,:comments,:array)
85
+ field.type.to_s.should == "array"
86
+ field.association.macro.should == :many
87
+ end
88
+
89
+ it "should match state with given record state" do
90
+ field = factory_class.add(@dbi, :title, :string, :on => :create)
91
+ field2 = factory_class.add(@dbi, :title, :string, :on => [:update])
92
+ field3 = factory_class.add(@dbi, :title, :string)
93
+ field4 = factory_class.add(@dbi, :title, :string, :on => Proc.new{|rec| rec.title == "title"})
94
+ record = @dbi.klass.new
95
+ field.match_state_of?(record).should be_true
96
+ field2.match_state_of?(record).should_not be_true
97
+ field3.match_state_of?(record).should be_true
98
+ field4.match_state_of?(record).should_not be_true
99
+ record2 = @dbi.klass.create!(:title => "title")
100
+ field.match_state_of?(record2).should_not be_true
101
+ field2.match_state_of?(record2).should be_true
102
+ field3.match_state_of?(record2).should be_true
103
+ field4.match_state_of?(record2).should be_true
104
+ end
105
+
106
+ it "should match :read state for record" do
107
+ field = factory_class.add(@dbi,:title,:string, :on => :create)
108
+ field2 = factory_class.add(@dbi,:title,:string, :on => :read)
109
+ field3 = factory_class.add(@dbi,:title,:string)
110
+ record = @dbi.klass.new
111
+ @dbi.switch_record_state(record,:read)
112
+ field.match_state_of?(record).should_not be_true
113
+ field2.match_state_of?(record).should be_true
114
+ field3.match_state_of?(record).should be_true
115
+ end
116
+
117
+ end
118
+