lolita 3.4.2 → 3.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +36 -36
- data/Gemfile +29 -29
- data/README.md +147 -147
- data/Rakefile +6 -6
- data/app/assets/javascripts/lolita/application.js +6 -6
- data/app/assets/javascripts/lolita/tab.js +100 -100
- data/app/assets/stylesheets/lolita/PIE-custom.htc +87 -87
- data/app/assets/stylesheets/lolita/PIE.htc +81 -81
- data/app/assets/stylesheets/lolita/application.css +6 -6
- data/app/assets/stylesheets/lolita/default.css.erb +169 -169
- data/app/assets/stylesheets/lolita/jquery-ui-1.8.16.lolita.css.erb +567 -567
- data/app/assets/stylesheets/lolita/style.css.erb +553 -553
- data/app/helpers/components/lolita/configuration/list_component.rb +10 -10
- data/app/helpers/components/lolita/configuration_component.rb +20 -20
- data/app/views/components/lolita/configuration/column/_first.html.haml +1 -1
- data/app/views/components/lolita/configuration/column/header/_first.html.haml +1 -1
- data/app/views/components/lolita/configuration/column/header/_sort.html.haml +6 -6
- data/app/views/components/lolita/configuration/columns/header/_display.html.haml +5 -5
- data/app/views/components/lolita/configuration/field/array/checkbox/_display.html.haml +7 -7
- data/app/views/components/lolita/configuration/field/string/text/_display.html.haml +7 -7
- data/app/views/components/lolita/configuration/search/_display.html.haml +2 -2
- data/app/views/components/lolita/configuration/tab/_display.html.haml +3 -3
- data/app/views/components/lolita/configuration/tabs/_form.html.haml +6 -6
- data/app/views/kaminari/lolita/_first_page.html.erb +11 -11
- data/app/views/kaminari/lolita/_gap.html.erb +8 -8
- data/app/views/kaminari/lolita/_last_page.html.erb +11 -11
- data/app/views/kaminari/lolita/_next_page.html.erb +11 -11
- data/app/views/kaminari/lolita/_page.html.erb +12 -12
- data/app/views/kaminari/lolita/_paginator.html.erb +23 -23
- data/app/views/kaminari/lolita/_prev_page.html.erb +11 -11
- data/app/views/lolita/info/index.html.erb +232 -232
- data/author +1 -1
- data/config/routes.rb +6 -6
- data/lib/generators/lolita/install_generator.rb +19 -19
- data/lib/generators/lolita/uninstall_generator.rb +70 -70
- data/lib/generators/templates/lolita.rb +13 -13
- data/lib/lolita.rb +140 -140
- data/lib/lolita/adapter/abstract_adapter.rb +15 -15
- data/lib/lolita/adapter/active_record.rb +227 -227
- data/lib/lolita/adapter/common_helper.rb +221 -221
- data/lib/lolita/adapter/field_helper.rb +18 -18
- data/lib/lolita/adapter/mongoid.rb +241 -241
- data/lib/lolita/components/base.rb +11 -11
- data/lib/lolita/configuration.rb +60 -60
- data/lib/lolita/configuration/column.rb +181 -181
- data/lib/lolita/configuration/field/big_decimal.rb +12 -12
- data/lib/lolita/configuration/field/boolean.rb +12 -12
- data/lib/lolita/configuration/field/date.rb +12 -12
- data/lib/lolita/configuration/field/hidden.rb +12 -12
- data/lib/lolita/configuration/field/integer.rb +11 -11
- data/lib/lolita/configuration/field/string.rb +16 -16
- data/lib/lolita/configuration/field/time.rb +13 -13
- data/lib/lolita/configuration/field_set.rb +25 -25
- data/lib/lolita/configuration/filter.rb +116 -116
- data/lib/lolita/configuration/list.rb +200 -200
- data/lib/lolita/configuration/search.rb +104 -104
- data/lib/lolita/controllers/component_helpers.rb +156 -156
- data/lib/lolita/controllers/internal_helpers.rb +71 -71
- data/lib/lolita/controllers/url_helpers.rb +7 -7
- data/lib/lolita/dbi/base.rb +56 -56
- data/lib/lolita/hooks/named_hook.rb +125 -125
- data/lib/lolita/lazy_loader.rb +54 -54
- data/lib/lolita/navigation/tree.rb +132 -132
- data/lib/lolita/rails/engine.rb +23 -23
- data/lib/lolita/rails/routes.rb +129 -129
- data/lib/lolita/ruby_ext/accessors.rb +26 -26
- data/lib/lolita/search/simple.rb +75 -75
- data/lib/lolita/support/formatter.rb +62 -62
- data/lib/lolita/support/formatter/rails.rb +56 -56
- data/lib/lolita/system_configuration/base.rb +178 -178
- data/lib/lolita/test/matchers.rb +77 -77
- data/lib/lolita/version.rb +30 -30
- data/lib/tasks/tinymce-assets.rake +6 -6
- data/lolita.gemspec +34 -34
- data/spec/adapter/common_helper_spec.rb +95 -95
- data/spec/adapter_helper.rb +42 -42
- data/spec/builder_spec.rb +120 -120
- data/spec/configuration/base_spec.rb +22 -22
- data/spec/configuration/field_spec.rb +118 -118
- data/spec/configuration/filter_spec.rb +131 -131
- data/spec/configuration/tab_spec.rb +187 -187
- data/spec/configuration/tabs_spec.rb +120 -120
- data/spec/generators/lolita/install_generator_spec.rb +54 -54
- data/spec/generators/lolita/uninstall_generator_spec.rb +48 -48
- data/spec/orm/mongoid.rb +12 -12
- data/spec/rails_app/app/controllers/application_controller.rb +3 -3
- data/spec/rails_app/app/helpers/application_helper.rb +3 -3
- data/spec/rails_app/app/mongoid/address.rb +7 -7
- data/spec/rails_app/app/mongoid/category.rb +18 -18
- data/spec/rails_app/app/mongoid/comment.rb +5 -5
- data/spec/rails_app/app/mongoid/post.rb +30 -30
- data/spec/rails_app/app/mongoid/preference.rb +5 -5
- data/spec/rails_app/app/mongoid/profile.rb +13 -13
- data/spec/rails_app/app/mongoid/tag.rb +3 -3
- data/spec/rails_app/app/views/components/lolita/configuration/list/_body_cell.html.erb +1 -1
- data/spec/rails_app/config/application.rb +33 -33
- data/spec/rails_app/config/boot.rb +7 -7
- data/spec/rails_app/config/environment.rb +5 -5
- data/spec/rails_app/config/environments/development.rb +23 -23
- data/spec/rails_app/config/environments/production.rb +37 -37
- data/spec/rails_app/config/environments/test.rb +37 -37
- data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -7
- data/spec/rails_app/config/initializers/inflections.rb +2 -2
- data/spec/rails_app/config/initializers/secret_token.rb +1 -1
- data/spec/rails_app/config/routes.rb +2 -2
- data/spec/rails_app/lib/lolita/configuration/field/my_custom_collection.rb +13 -13
- data/spec/rails_app/public/javascripts/jquery-1.5.1.min.js +15 -15
- data/spec/rails_app/public/javascripts/lolita/main.js +6 -6
- data/spec/rails_app/public/javascripts/modernizr-1.7.min.js +1 -1
- data/spec/rails_app/public/javascripts/rails.js +137 -137
- data/spec/rails_app/public/javascripts/tinymce/langs/en.js +221 -221
- data/spec/rails_app/public/javascripts/tinymce/license.txt +504 -504
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/about.htm +52 -52
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/anchor.htm +26 -26
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/charmap.htm +51 -51
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/color_picker.htm +74 -74
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/editor_template_src.js +1328 -1328
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/image.htm +80 -80
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/about.js +73 -73
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/anchor.js +42 -42
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/charmap.js +354 -354
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/color_picker.js +329 -329
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/image.js +247 -247
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/link.js +153 -153
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/js/source_editor.js +56 -56
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/langs/en.js +68 -68
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/langs/en_dlg.js +53 -53
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/link.htm +57 -57
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/shortcuts.htm +47 -47
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/content.css +66 -66
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/dialog.css +117 -117
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/skins/cirkuit/ui.css +988 -988
- data/spec/rails_app/public/javascripts/tinymce/themes/advanced/source_editor.htm +25 -25
- data/spec/rails_app/public/javascripts/tinymce/tiny_mce_popup.js +4 -4
- data/spec/rails_app/public/stylesheets/lolita/default.css +169 -169
- data/spec/rails_app/public/stylesheets/lolita/style.css +214 -214
- data/spec/spec_helper.rb +51 -51
- data/vendor/assets/javascripts/application_vendor_lolita.js +4 -4
- data/vendor/assets/javascripts/jquery-numeric.js +279 -279
- data/vendor/assets/javascripts/modernizr_1_7_min.js +1 -1
- data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/content.css +66 -66
- data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/dialog.css +117 -117
- data/vendor/assets/javascripts/tinymce/themes/advanced/skins/cirkuit/ui.css +988 -988
- data/vendor/assets/stylesheets/jquery-ui-1.8.16.custom.css +567 -567
- metadata +4 -3
data/spec/adapter_helper.rb
CHANGED
@@ -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
|
data/spec/builder_spec.rb
CHANGED
@@ -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
|
+
|