lolita 3.2.0.rc.7 → 3.2.0.rc.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +31 -0
- data/Gemfile +15 -36
- data/History.rdoc +9 -3
- data/README.md +57 -30
- data/Rakefile +1 -44
- data/app/assets/javascripts/lolita/list.js +28 -0
- data/app/assets/javascripts/lolita/main.js +81 -12
- data/app/assets/javascripts/lolita/tab.js +37 -32
- data/app/assets/stylesheets/lolita/style.css.erb +58 -18
- data/app/controllers/lolita/field_data_controller.rb +13 -9
- data/app/controllers/lolita/info_controller.rb +3 -5
- data/app/controllers/lolita/rest_controller.rb +53 -24
- data/app/helpers/components/lolita/configuration_component.rb +1 -1
- data/app/views/components/lolita/configuration/action/_display.html.haml +1 -0
- data/app/views/components/lolita/configuration/column/_display.html.haml +4 -0
- data/app/views/components/lolita/configuration/column/_first.html.haml +2 -0
- data/app/views/components/lolita/configuration/column/_last.html.haml +5 -0
- data/app/views/components/lolita/configuration/column/header/_display.html.haml +5 -0
- data/app/views/components/lolita/configuration/column/header/_first.html.haml +1 -0
- data/app/views/components/lolita/configuration/column/header/_last.html.haml +1 -0
- data/app/views/components/lolita/configuration/column/header/_sort.html.haml +6 -0
- data/app/views/components/lolita/configuration/columns/_display.html.haml +2 -0
- data/app/views/components/lolita/configuration/columns/body/_display.html.haml +3 -0
- data/app/views/components/lolita/configuration/columns/body/row/_display.html.haml +5 -0
- data/app/views/components/lolita/configuration/columns/header/_display.html.haml +5 -0
- data/app/views/components/lolita/configuration/field/_display.html.haml +7 -0
- data/app/views/components/lolita/configuration/field/_label.html.haml +1 -0
- data/app/views/components/lolita/configuration/field/_object.html.haml +1 -0
- data/app/views/components/lolita/configuration/field/array/_display.html.haml +5 -0
- data/app/views/components/lolita/configuration/field/array/autocomplete/_display.html.haml +1 -1
- data/app/views/components/lolita/configuration/field/array/autocomplete/_input.html.haml +2 -2
- data/app/views/components/lolita/configuration/field/array/polymorphic/_display.html.haml +3 -3
- data/app/views/components/lolita/configuration/field/array/select/_display.html.haml +1 -0
- data/app/views/components/lolita/configuration/field/big_decimal/_display.html.haml +1 -0
- data/app/views/components/lolita/configuration/field/boolean/_display.html.haml +1 -0
- data/app/views/components/lolita/configuration/field/date/_display.html.haml +1 -0
- data/app/views/components/lolita/configuration/field/date_time/_display.html.haml +2 -0
- data/app/views/components/lolita/configuration/field/date_time/date/_display.html.haml +1 -0
- data/app/views/components/lolita/configuration/field/date_time/time/_display.html.haml +1 -0
- data/app/views/components/lolita/configuration/field/float/_display.html.haml +1 -0
- data/app/views/components/lolita/configuration/field/integer/_display.html.haml +1 -0
- data/app/views/components/lolita/configuration/field/string/_display.html.haml +1 -0
- data/app/views/components/lolita/configuration/field/string/disabled/_display.html.haml +2 -0
- data/app/views/components/lolita/configuration/field/string/hidden/_display.html.haml +1 -0
- data/app/views/components/lolita/configuration/field/string/password/_display.html.haml +1 -0
- data/app/views/components/lolita/configuration/field/string/text/_display.html.haml +7 -0
- data/app/views/components/lolita/configuration/field/time/_display.html.haml +1 -0
- data/app/views/components/lolita/configuration/field_set/_display.html.haml +3 -0
- data/app/views/components/lolita/configuration/filter/_display.html.haml +9 -0
- data/app/views/components/lolita/configuration/list/_display.html.haml +9 -0
- data/app/views/components/lolita/configuration/list/_new_resource.html.haml +4 -0
- data/app/views/components/lolita/configuration/list/_paginator.html.haml +1 -0
- data/app/views/components/lolita/configuration/list/_title.html.haml +6 -0
- data/app/views/components/lolita/configuration/nested_form/_display.html.haml +12 -0
- data/app/views/components/lolita/configuration/nested_form/_fields.html.haml +8 -0
- data/app/views/components/lolita/configuration/nested_list/_display.html.haml +7 -0
- data/app/views/components/lolita/configuration/nested_list/_paginator.html.haml +2 -0
- data/app/views/components/lolita/configuration/tab/_display.html.haml +4 -0
- data/app/views/components/lolita/configuration/tab/_error_msg.html.haml +14 -0
- data/app/views/components/lolita/configuration/tab/_fields.html.haml +6 -0
- data/app/views/components/lolita/configuration/tab/_form.html.haml +4 -0
- data/app/views/components/lolita/configuration/tab/_title.html.haml +3 -0
- data/app/views/components/lolita/configuration/tab/content/_display.html.haml +1 -0
- data/app/views/components/lolita/configuration/tab/default/_display.html.haml +2 -0
- data/app/views/components/lolita/configuration/tabs/_display.html.haml +10 -0
- data/app/views/components/lolita/configuration/tabs/_form.html.haml +7 -0
- data/app/views/components/lolita/navigation/_display.html.haml +2 -0
- data/app/views/components/lolita/navigation/_tree.html.haml +14 -0
- data/app/views/components/lolita/shared/_buttons.html.haml +6 -0
- data/app/views/components/lolita/shared/_flash.html.haml +3 -0
- data/app/views/components/lolita/shared/_header.html.haml +7 -0
- data/app/views/components/lolita/shared/_languages.html.haml +11 -0
- data/app/views/components/lolita/shared/_right_sidebar.html.haml +6 -0
- data/app/views/components/lolita/shared/_save_button.html.haml +1 -0
- data/app/views/layouts/lolita/application.html.haml +36 -0
- data/app/views/lolita/rest/form.html.haml +1 -0
- data/app/views/lolita/rest/index.html.haml +1 -0
- data/app/views/lolita/rest/index.js.erb +1 -0
- data/config/locales/en.yml +4 -0
- data/config/locales/lv.yml +5 -2
- data/lib/generators/lolita/uninstall_generator.rb +76 -0
- data/lib/lolita.rb +104 -170
- data/lib/lolita/adapter/abstract_adapter.rb +1 -0
- data/lib/lolita/adapter/active_record.rb +22 -55
- data/lib/lolita/adapter/common_helper.rb +252 -0
- data/lib/lolita/adapter/mongoid.rb +11 -55
- data/lib/lolita/base.rb +5 -0
- data/lib/lolita/builder.rb +3 -3
- data/lib/lolita/components/base.rb +12 -0
- data/lib/lolita/components/configuration/column_component.rb +31 -0
- data/lib/lolita/components/configuration/list_component.rb +11 -0
- data/lib/lolita/configuration.rb +61 -0
- data/lib/lolita/configuration/action.rb +53 -0
- data/lib/lolita/configuration/base.rb +23 -71
- data/lib/lolita/configuration/column.rb +50 -16
- data/lib/lolita/configuration/columns.rb +51 -23
- data/lib/lolita/configuration/core.rb +80 -0
- data/lib/lolita/configuration/factory/field.rb +8 -3
- data/lib/lolita/configuration/factory/tab.rb +12 -6
- data/lib/lolita/configuration/field.rb +8 -11
- data/lib/lolita/configuration/field/array.rb +7 -9
- data/lib/lolita/configuration/fields.rb +1 -1
- data/lib/lolita/configuration/filter.rb +26 -19
- data/lib/lolita/configuration/list.rb +143 -80
- data/lib/lolita/configuration/nested_list.rb +102 -0
- data/lib/lolita/configuration/search.rb +14 -0
- data/lib/lolita/configuration/tab.rb +13 -9
- data/lib/lolita/configuration/tab/content.rb +6 -0
- data/lib/lolita/configuration/tab/default.rb +2 -2
- data/lib/lolita/configuration/tabs.rb +35 -82
- data/lib/lolita/controller_additions.rb +4 -3
- data/lib/lolita/controllers.rb +13 -0
- data/lib/lolita/controllers/authentication_helpers.rb +17 -0
- data/lib/lolita/controllers/component_helpers.rb +9 -5
- data/lib/lolita/controllers/internal_helpers.rb +22 -97
- data/lib/lolita/controllers/rails_helpers.rb +132 -0
- data/lib/lolita/controllers/url_helpers.rb +1 -1
- data/lib/lolita/errors.rb +3 -0
- data/lib/lolita/extensions/authentication/default_adapter.rb +24 -0
- data/lib/lolita/extensions/authentication/devise_adapter.rb +58 -0
- data/lib/lolita/extensions/authentication/proxy.rb +60 -0
- data/lib/lolita/extensions/authorization/cancan_adapter.rb +45 -0
- data/lib/lolita/extensions/authorization/default_adapter.rb +29 -0
- data/lib/lolita/extensions/authorization/proxy.rb +48 -0
- data/lib/lolita/extensions/extensions.rb +66 -0
- data/lib/lolita/helpers.rb +12 -0
- data/lib/lolita/lazy_loader.rb +15 -10
- data/lib/lolita/mapping.rb +25 -19
- data/lib/lolita/navigation/branch.rb +29 -2
- data/lib/lolita/navigation/tree.rb +6 -0
- data/lib/lolita/observed_array.rb +1 -1
- data/lib/lolita/orm.rb +7 -0
- data/lib/lolita/processors/request_processor.rb +38 -0
- data/lib/lolita/rails/engine.rb +24 -0
- data/lib/lolita/{modules/rest.rb → rails/railtie.rb} +8 -2
- data/lib/lolita/rails/routes.rb +26 -29
- data/lib/lolita/register.rb +48 -0
- data/lib/lolita/ruby_ext/lolita_model_name.rb +37 -0
- data/lib/lolita/system_configuration/application.rb +1 -0
- data/lib/lolita/system_configuration/base.rb +12 -5
- data/lib/lolita/utils.rb +14 -0
- data/lib/lolita/version.rb +30 -0
- data/lolita.gemspec +26 -398
- data/spec/configuration/base_spec.rb +14 -35
- data/spec/configuration/column_spec.rb +51 -2
- data/spec/configuration/columns_spec.rb +13 -19
- data/spec/configuration/core_spec.rb +89 -0
- data/spec/configuration/field_spec.rb +17 -5
- data/spec/configuration/filter_spec.rb +76 -61
- data/spec/configuration/list_spec.rb +339 -45
- data/spec/configuration/nested_list_spec.rb +111 -0
- data/spec/configuration/search_spec.rb +1 -1
- data/spec/configuration/tabs_spec.rb +89 -74
- data/spec/controllers/configuration_spec.rb +15 -0
- data/spec/controllers/internal_helpers_spec.rb +1 -1
- data/spec/controllers/lolita_rest_spec.rb +31 -2
- data/spec/coverage_helper.rb +33 -0
- data/spec/extensions/authentication/default_adapter_spec.rb +34 -0
- data/spec/extensions/authentication/devise_adapter_spec.rb +94 -0
- data/spec/extensions/authentication/proxy_spec.rb +55 -0
- data/spec/extensions/authorization/cancan_adapter_spec.rb +94 -0
- data/spec/extensions/authorization/default_adapter_spec.rb +43 -0
- data/spec/extensions/authorization/proxy_spec.rb +60 -0
- data/spec/extensions/extensions_spec.rb +45 -0
- data/spec/fabricators/category_fabricator.rb +3 -0
- data/spec/fabricators/post_fabricator.rb +4 -0
- data/spec/fabricators/tag_fabricator.rb +3 -0
- data/spec/lolita_spec.rb +1 -0
- data/spec/orm/mongoid.rb +1 -0
- data/spec/rails_app/app/mongoid/category.rb +14 -1
- data/spec/rails_app/app/mongoid/post.rb +9 -1
- data/spec/rails_app/config/application.rb +0 -4
- data/spec/rails_app/config/boot.rb +1 -2
- data/spec/register_spec.rb +50 -0
- data/spec/search/simple_spec.rb +4 -4
- data/spec/simple_spec_helper.rb +2 -1
- data/spec/spec_helper.rb +22 -35
- data/vendor/assets/javascripts/tinymce_config.js +5 -3
- metadata +202 -180
- data/.document +0 -5
- data/GUIDELINES.rdoc +0 -22
- data/VERSION +0 -1
- data/app/helpers/lolita_helper.rb +0 -23
- data/app/views/components/lolita/configuration/column/_display.html.erb +0 -4
- data/app/views/components/lolita/configuration/column/_header.html.erb +0 -7
- data/app/views/components/lolita/configuration/column/_sort.html.erb +0 -7
- data/app/views/components/lolita/configuration/columns/_body.html.erb +0 -5
- data/app/views/components/lolita/configuration/columns/_display.html.erb +0 -2
- data/app/views/components/lolita/configuration/columns/_first.html.erb +0 -3
- data/app/views/components/lolita/configuration/columns/_first_column_header.html.erb +0 -3
- data/app/views/components/lolita/configuration/columns/_header.html.erb +0 -9
- data/app/views/components/lolita/configuration/columns/_last.html.erb +0 -4
- data/app/views/components/lolita/configuration/columns/_last_column_header.html.erb +0 -3
- data/app/views/components/lolita/configuration/columns/_row.html.erb +0 -7
- data/app/views/components/lolita/configuration/field/_display.html.erb +0 -13
- data/app/views/components/lolita/configuration/field/_label.html.erb +0 -1
- data/app/views/components/lolita/configuration/field/_object.html.erb +0 -1
- data/app/views/components/lolita/configuration/field/array/_display.html.erb +0 -5
- data/app/views/components/lolita/configuration/field/array/filter/_display.html.erb +0 -1
- data/app/views/components/lolita/configuration/field/array/select/_display.html.erb +0 -4
- data/app/views/components/lolita/configuration/field/big_decimal/_display.html.erb +0 -1
- data/app/views/components/lolita/configuration/field/boolean/_display.html.erb +0 -1
- data/app/views/components/lolita/configuration/field/boolean/filter/_display.html.erb +0 -2
- data/app/views/components/lolita/configuration/field/date/_display.html.erb +0 -1
- data/app/views/components/lolita/configuration/field/date_time/_display.html.erb +0 -1
- data/app/views/components/lolita/configuration/field/date_time/date/_display.html.erb +0 -1
- data/app/views/components/lolita/configuration/field/date_time/time/_display.html.erb +0 -1
- data/app/views/components/lolita/configuration/field/float/_display.html.erb +0 -1
- data/app/views/components/lolita/configuration/field/hidden/_display.html.erb +0 -1
- data/app/views/components/lolita/configuration/field/integer/_display.html.erb +0 -1
- data/app/views/components/lolita/configuration/field/string/_display.html.erb +0 -1
- data/app/views/components/lolita/configuration/field/string/disabled/_display.html.erb +0 -1
- data/app/views/components/lolita/configuration/field/string/password/_display.html.erb +0 -3
- data/app/views/components/lolita/configuration/field/string/text/_display.html.erb +0 -11
- data/app/views/components/lolita/configuration/field/time/_display.html.erb +0 -1
- data/app/views/components/lolita/configuration/field_set/_display.html.erb +0 -5
- data/app/views/components/lolita/configuration/list/_display.html.erb +0 -11
- data/app/views/components/lolita/configuration/list/_filter.html.erb +0 -8
- data/app/views/components/lolita/configuration/list/_new_resource.html.erb +0 -6
- data/app/views/components/lolita/configuration/list/_paginator.html.erb +0 -1
- data/app/views/components/lolita/configuration/list/_title.html.erb +0 -10
- data/app/views/components/lolita/configuration/nested_form/_display.html.erb +0 -15
- data/app/views/components/lolita/configuration/nested_form/_fields.html.erb +0 -13
- data/app/views/components/lolita/configuration/tab/_display.html.erb +0 -8
- data/app/views/components/lolita/configuration/tab/_error_msg.html.erb +0 -20
- data/app/views/components/lolita/configuration/tab/_fields.html.erb +0 -9
- data/app/views/components/lolita/configuration/tab/_form.html.erb +0 -8
- data/app/views/components/lolita/configuration/tab/content/_display.html.erb +0 -1
- data/app/views/components/lolita/configuration/tab/default/_display.html.erb +0 -3
- data/app/views/components/lolita/configuration/tabs/_display.html.erb +0 -11
- data/app/views/components/lolita/navigation/_display.html.erb +0 -3
- data/app/views/components/lolita/navigation/_tree.html.erb +0 -32
- data/app/views/components/lolita/shared/_flash.html.erb +0 -5
- data/app/views/components/lolita/shared/_header.html.erb +0 -9
- data/app/views/components/lolita/shared/_right_sidebar.html.erb +0 -9
- data/app/views/components/lolita/shared/_save_button.html.erb +0 -6
- data/app/views/layouts/lolita/application.html.erb +0 -37
- data/app/views/lolita/rest/form.html.erb +0 -1
- data/app/views/lolita/rest/index.html.erb +0 -1
- data/config/locales/default/lv.yml +0 -181
- data/db/seed.rb +0 -1
- data/features/create_page.feature +0 -20
- data/features/step_definitions/lolita_steps.rb +0 -7
- data/features/step_definitions/web_steps.rb +0 -219
- data/features/support/env.rb +0 -73
- data/features/support/paths.rb +0 -35
- data/lib/lolita/controllers/authorization_helpers.rb +0 -56
- data/lib/lolita/controllers/user_helpers.rb +0 -44
- data/lib/lolita/modules.rb +0 -6
- data/lib/lolita/rails.rb +0 -23
- data/lib/lolita/rails/all.rb +0 -11
- data/spec/support/factories/category.rb +0 -3
- data/spec/support/factories/post.rb +0 -4
- data/spec/support/factories/tag.rb +0 -3
@@ -1,44 +1,23 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../simple_spec_helper')
|
2
2
|
|
3
|
-
describe Lolita::Configuration::Base do
|
4
|
-
|
5
|
-
|
6
|
-
# end
|
3
|
+
describe Lolita::Configuration::Base do
|
4
|
+
let(:klass){Lolita::Configuration::Base}
|
5
|
+
let(:dbp){Object.new}
|
7
6
|
|
8
|
-
it "should
|
9
|
-
|
7
|
+
it "should include Lolita::Builder" do
|
8
|
+
klass.ancestors.should include(Lolita::Builder)
|
10
9
|
end
|
11
10
|
|
12
|
-
it "should
|
13
|
-
|
11
|
+
it "should respond to dbp" do
|
12
|
+
klass.new(dbp).should respond_to(:dbp)
|
14
13
|
end
|
15
14
|
|
16
|
-
it "should
|
17
|
-
|
18
|
-
Post.lolita.list.to_s.should match(/Lolita::LazyLoader/)
|
15
|
+
it "should respond to dbi" do
|
16
|
+
klass.new(dbp).should respond_to(:dbi)
|
19
17
|
end
|
20
18
|
|
21
|
-
it "should
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
Post.lolita.list.class.to_s.should == "Lolita::Configuration::List"
|
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)
|
26
22
|
end
|
27
|
-
|
28
|
-
it "should return tabs" do
|
29
|
-
define_config
|
30
|
-
Post.lolita.tabs.class.should == Lolita::Configuration::Tabs
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should allow add tabs" do
|
34
|
-
define_config do
|
35
|
-
tab(:content)
|
36
|
-
end
|
37
|
-
Post.lolita.tabs.size.should == 1
|
38
|
-
end
|
39
|
-
|
40
|
-
def define_config &block
|
41
|
-
Post.lolita=Lolita::Configuration::Base.new(Post,&block)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
23
|
+
end
|
@@ -3,11 +3,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
describe Lolita::Configuration::Column do
|
4
4
|
let(:dbi){Lolita::DBI::Base.create(Post)}
|
5
5
|
let(:column){Lolita::Configuration::Column.new(dbi,:col1)}
|
6
|
+
let(:column_class){Lolita::Configuration::Column}
|
6
7
|
|
7
8
|
|
8
9
|
it "should create new column with Hash attributes" do
|
9
10
|
column=Lolita::Configuration::Column.new(dbi,:name=>"col1",:title=>"Col1",:type=>String)
|
10
|
-
column.name.should ==
|
11
|
+
column.name.should == :col1
|
11
12
|
end
|
12
13
|
|
13
14
|
it "should create new column with Proc as block given" do
|
@@ -33,7 +34,7 @@ describe Lolita::Configuration::Column do
|
|
33
34
|
column=Lolita::Configuration::Column.new(dbi,:col1)
|
34
35
|
column.name.should == :col1
|
35
36
|
column=Lolita::Configuration::Column.new(dbi,"col2")
|
36
|
-
column.name.should ==
|
37
|
+
column.name.should == :col2
|
37
38
|
end
|
38
39
|
|
39
40
|
it "should raise error when no name is provided for column" do
|
@@ -85,5 +86,53 @@ describe Lolita::Configuration::Column do
|
|
85
86
|
column.formatter.with(1).should == 1
|
86
87
|
end
|
87
88
|
|
89
|
+
it "should set association for column if name matches any association name" do
|
90
|
+
new_column = column_class.new(dbi,:comments)
|
91
|
+
new_column.association.klass.should == Comment
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "sublist" do
|
95
|
+
|
96
|
+
it "should accept sublist" do
|
97
|
+
new_column = column_class.new(dbi,:comments) do
|
98
|
+
list do
|
99
|
+
column :body
|
100
|
+
end
|
101
|
+
end
|
102
|
+
new_column.list.should_not be_nil
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should accept list for reflection fields without any specifict arguments" do
|
106
|
+
expect{
|
107
|
+
column_class.new(dbi,:comments) do
|
108
|
+
list{}
|
109
|
+
end
|
110
|
+
}.not_to raise_error
|
111
|
+
|
112
|
+
expect{
|
113
|
+
column_class.new(dbi, :title) do
|
114
|
+
list{}
|
115
|
+
end
|
116
|
+
}.to raise_error(Lolita::UnknownDBPError)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should accept sublist in any depth" do
|
120
|
+
dbi = Lolita::DBI::Base.create(Category)
|
121
|
+
new_column = column_class.new(dbi,:posts) do
|
122
|
+
list do
|
123
|
+
column :title
|
124
|
+
column :comments do
|
125
|
+
list do
|
126
|
+
column :body
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
new_column.list.columns.by_name(:comments).list.should_not be_nil
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
88
137
|
end
|
89
138
|
|
@@ -2,53 +2,47 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
3
3
|
describe Lolita::Configuration::Columns do
|
4
4
|
|
5
|
-
|
6
|
-
@dbi=Lolita::DBI::Base.create(Post)
|
7
|
-
@list=Lolita::Configuration::List.new(@dbi)
|
8
|
-
end
|
5
|
+
let(:dbi){Lolita::DBI::Base.create(Post)}
|
9
6
|
|
10
7
|
it "should create columns" do
|
11
|
-
columns=Lolita::Configuration::Columns.new(
|
8
|
+
columns=Lolita::Configuration::Columns.new(dbi)
|
12
9
|
columns.class.should == Lolita::Configuration::Columns
|
13
10
|
end
|
14
11
|
|
15
12
|
it "should respond to array methods" do
|
16
|
-
columns=Lolita::Configuration::Columns.new(
|
13
|
+
columns=Lolita::Configuration::Columns.new(dbi)
|
17
14
|
columns.size.should == 0
|
18
15
|
end
|
19
16
|
|
20
17
|
it "should generate columns from dbi class" do
|
21
|
-
columns=Lolita::Configuration::Columns.new(
|
18
|
+
columns=Lolita::Configuration::Columns.new(dbi)
|
22
19
|
columns.generate!
|
23
|
-
columns.last.
|
20
|
+
columns.last.should_not be_nil
|
24
21
|
end
|
25
22
|
|
26
23
|
it "should make Lolita::Configuration::Column for each element " do
|
27
|
-
columns=Lolita::Configuration::Columns.new(
|
24
|
+
columns=Lolita::Configuration::Columns.new(dbi)
|
28
25
|
columns<<{:name=>"col1"}
|
29
|
-
columns<<Lolita::Configuration::Column.new(
|
26
|
+
columns<<Lolita::Configuration::Column.new(dbi,:name=>"col2")
|
30
27
|
columns.first.class.should == Lolita::Configuration::Column
|
31
28
|
end
|
32
29
|
|
33
30
|
it "should make Lolita::Configuration::Column from Symbol as name" do
|
34
|
-
columns=Lolita::Configuration::Columns.new(
|
31
|
+
columns=Lolita::Configuration::Columns.new(dbi)
|
35
32
|
columns<<:col1
|
36
33
|
columns.first.class.should == Lolita::Configuration::Column
|
37
|
-
columns.add(:col2).add(:col3)
|
38
|
-
columns.last.class.should == Lolita::Configuration::Column
|
39
|
-
columns.size.should == 3
|
40
34
|
end
|
41
35
|
|
42
36
|
it "should make ::Column object with given block" do
|
43
|
-
columns=Lolita::Configuration::Columns.new(
|
37
|
+
columns=Lolita::Configuration::Columns.new(dbi)
|
44
38
|
columns<<(Proc.new{
|
45
39
|
name "col1"
|
46
40
|
})
|
47
|
-
columns.first.name.should ==
|
48
|
-
columns.
|
49
|
-
name
|
41
|
+
columns.first.name.should == :col1
|
42
|
+
columns.column do
|
43
|
+
name :col2
|
50
44
|
end
|
51
|
-
columns.last.name.should ==
|
45
|
+
columns.last.name.should == :col2
|
52
46
|
end
|
53
47
|
end
|
54
48
|
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../simple_spec_helper')
|
2
|
+
|
3
|
+
describe Lolita::Configuration::Core do
|
4
|
+
let(:klass){Lolita::Configuration::Core}
|
5
|
+
let(:dbp_klass){Lolita::DBI::Base}
|
6
|
+
let(:dbp){Object.new}
|
7
|
+
let(:conf){klass.new(Object)}
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
dbp_klass.stub(:create).with(kind_of(Class)).and_return(dbp)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should create new instance without block" do
|
14
|
+
expect{
|
15
|
+
klass.new(Object)
|
16
|
+
}.not_to raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should create new instance with block" do
|
20
|
+
expect{
|
21
|
+
klass.new(Object){}
|
22
|
+
}.not_to raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should create dbp instance for received class" do
|
26
|
+
conf = klass.new(Object)
|
27
|
+
conf.dbi.should eq(dbp)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should call #generate! when no block is given" do
|
31
|
+
klass.any_instance.should_receive(:generate!).once
|
32
|
+
klass.new(Object)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should eval block on instance when block is given" do
|
36
|
+
proc = Proc.new{ "result" }
|
37
|
+
klass.any_instance.should_receive(:instance_eval).with(&proc).once
|
38
|
+
klass.new(Object,&proc)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should create new list with same DB proxy" do
|
42
|
+
Lolita::Configuration::List.should_receive(:new).with(dbp)
|
43
|
+
conf.list.class
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should create new list with block" do
|
47
|
+
block = Proc.new{}
|
48
|
+
Lolita::Configuration::List.should_receive(:new).with(dbp,&block)
|
49
|
+
conf.list(&block).class
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should assign new list to @list when instance class is kind of Lolita::Configuration::List" do
|
53
|
+
list = double("list")
|
54
|
+
list.stub(:is_a?).with(Lolita::Configuration::List).and_return(true)
|
55
|
+
conf.list = list
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should create tabs with same DB proxy" do
|
59
|
+
Lolita::Configuration::Tabs.should_receive(:new).with(dbp)
|
60
|
+
conf.tabs.class
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should create tabs with block" do
|
64
|
+
block = Proc.new{}
|
65
|
+
Lolita::Configuration::Tabs.should_receive(:new).with(dbp,&block)
|
66
|
+
conf.tabs(&block).class
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should create tab with any arguments and add to #tabs" do
|
70
|
+
Lolita::Configuration::Tabs.any_instance.should_receive(:<<).once.and_return(true)
|
71
|
+
Lolita::Configuration::Factory::Tab.should_receive(:add).with(dbp,1).and_return(Object.new)
|
72
|
+
conf.tab(1)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "shoud create tab with any arguments and block" do
|
76
|
+
block = Proc.new{}
|
77
|
+
Lolita::Configuration::Tabs.any_instance.should_receive(:<<).once
|
78
|
+
Lolita::Configuration::Factory::Tab.should_receive(:add).with(dbp,1,&block)
|
79
|
+
conf.tab(1,&block)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should call generator methods when #generate! is called" do
|
83
|
+
klass.class_variable_get(:@@generators).each do |gen_name|
|
84
|
+
klass.any_instance.should_receive(gen_name).once
|
85
|
+
end
|
86
|
+
conf
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
@@ -7,6 +7,7 @@ describe Lolita::Configuration::Field do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
let(:field_class){Lolita::Configuration::Field::Base}
|
10
|
+
let(:factory_class){Lolita::Configuration::Factory::Field}
|
10
11
|
|
11
12
|
it "should create new field" do
|
12
13
|
Lolita::Configuration::Field::Base.new(@dbi,:title,:string)
|
@@ -85,11 +86,11 @@ describe Lolita::Configuration::Field do
|
|
85
86
|
field.association.macro.should == :many
|
86
87
|
end
|
87
88
|
|
88
|
-
it "should
|
89
|
-
field =
|
90
|
-
field2 =
|
91
|
-
field3 =
|
92
|
-
field4 =
|
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"})
|
93
94
|
record = @dbi.klass.new
|
94
95
|
field.match_state_of?(record).should be_true
|
95
96
|
field2.match_state_of?(record).should_not be_true
|
@@ -102,5 +103,16 @@ describe Lolita::Configuration::Field do
|
|
102
103
|
field4.match_state_of?(record2).should be_true
|
103
104
|
end
|
104
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
|
+
|
105
117
|
end
|
106
118
|
|
@@ -2,41 +2,32 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
3
3
|
describe Lolita::Configuration::Filter do
|
4
4
|
|
5
|
-
|
6
|
-
@dbi=Lolita::DBI::Base.new(Post)
|
7
|
-
end
|
5
|
+
let(:dbi){Lolita::DBI::Base.new(Post)}
|
8
6
|
|
9
7
|
it "should create new filter with block" do
|
10
|
-
Lolita::Configuration::Filter.new(
|
8
|
+
Lolita::Configuration::Filter.new(dbi) do
|
11
9
|
end
|
12
10
|
end
|
13
11
|
|
14
12
|
it "should create new filter without block" do
|
15
|
-
Lolita::Configuration::Filter.new(
|
13
|
+
Lolita::Configuration::Filter.new(dbi)
|
16
14
|
end
|
17
15
|
|
18
16
|
it "should give fields as arguments" do
|
19
|
-
list=Lolita::Configuration::List.new(
|
17
|
+
list=Lolita::Configuration::List.new(dbi)
|
20
18
|
list.filter :name, :is_public
|
21
19
|
list.filter.fields.size.should == 2
|
22
20
|
end
|
23
|
-
|
24
|
-
it "should add default search field if none is given" do
|
25
|
-
filter=Lolita::Configuration::Filter.new(@dbi)
|
26
|
-
filter.fields.size.should == 1
|
27
|
-
filter=Lolita::Configuration::Filter.new(@dbi){}
|
28
|
-
filter.fields.size.should == 1
|
29
|
-
end
|
30
21
|
|
31
22
|
it "should add some fields" do
|
32
|
-
filter=Lolita::Configuration::Filter.new(
|
23
|
+
filter=Lolita::Configuration::Filter.new(dbi) do
|
33
24
|
fields :name, :is_public, :not_public
|
34
25
|
end
|
35
26
|
filter.fields.size.should == 3
|
36
27
|
end
|
37
28
|
|
38
29
|
it "should add some field with block" do
|
39
|
-
filter=Lolita::Configuration::Filter.new(
|
30
|
+
filter=Lolita::Configuration::Filter.new(dbi) do
|
40
31
|
field :name do
|
41
32
|
type :integer
|
42
33
|
end
|
@@ -45,7 +36,7 @@ describe Lolita::Configuration::Filter do
|
|
45
36
|
end
|
46
37
|
|
47
38
|
it "should add some fields with block" do
|
48
|
-
filter=Lolita::Configuration::Filter.new(
|
39
|
+
filter=Lolita::Configuration::Filter.new(dbi) do
|
49
40
|
fields :name, :is_public do
|
50
41
|
type :integer
|
51
42
|
end
|
@@ -57,67 +48,91 @@ describe Lolita::Configuration::Filter do
|
|
57
48
|
filter.fields[2].type.should == "time"
|
58
49
|
end
|
59
50
|
|
60
|
-
it "should generate correct field_name" do
|
61
|
-
filter=Lolita::Configuration::Filter.new(@dbi)
|
62
|
-
filter.fields :name, :not_public
|
63
|
-
filter.field_name(filter.fields.first).should == "f_name"
|
64
|
-
filter.field_name(filter.fields.last).should == "f_not_public"
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should return right options_for_select" do
|
68
|
-
Category.delete_all
|
69
|
-
3.times{ Factory.create(:category)}
|
70
|
-
filter=Lolita::Configuration::Filter.new(@dbi) do
|
71
|
-
field :category
|
72
|
-
field :some_type, :array, :options_for_select => %w(a b c)
|
73
|
-
end
|
74
|
-
options = filter.options_for_select(filter.fields.first)
|
75
|
-
options.size.should == 3
|
76
|
-
options.first.first.should be_an(String)
|
77
|
-
options.first.last.should be_an(BSON::ObjectId)
|
78
|
-
options = filter.options_for_select(filter.fields.last)
|
79
|
-
options.size.should == 3
|
80
|
-
options.should == %w(a b c)
|
81
|
-
end
|
82
|
-
|
83
51
|
it "should filter results for boolean" do
|
84
|
-
|
85
|
-
|
86
|
-
|
52
|
+
Fabricate(:post, :is_public => true)
|
53
|
+
Fabricate(:post, :is_public => true)
|
54
|
+
Fabricate(:post, :is_public => false)
|
87
55
|
|
88
|
-
filter=Lolita::Configuration::Filter.new(
|
56
|
+
filter=Lolita::Configuration::Filter.new(dbi) do
|
89
57
|
field :is_public
|
90
58
|
end
|
91
59
|
|
92
|
-
|
93
|
-
|
60
|
+
dbi.filter(:is_public => 1).size.should == 2
|
61
|
+
dbi.filter(:is_public => 0).size.should == 1
|
94
62
|
end
|
95
63
|
|
96
64
|
it "should filter results for belongs_to" do
|
97
|
-
c1 =
|
98
|
-
c2 =
|
99
|
-
p1=
|
100
|
-
p2=
|
101
|
-
p3=
|
65
|
+
c1 = Fabricate(:category, :name => "Linux")
|
66
|
+
c2 = Fabricate(:category, :name => "Android")
|
67
|
+
p1=Fabricate(:post, :category => c1)
|
68
|
+
p2=Fabricate(:post, :category => c1)
|
69
|
+
p3=Fabricate(:post, :category => c2)
|
102
70
|
|
103
|
-
filter=Lolita::Configuration::Filter.new(
|
71
|
+
filter=Lolita::Configuration::Filter.new(dbi) do
|
104
72
|
field :tags
|
105
73
|
end
|
106
|
-
|
107
|
-
|
74
|
+
dbi.filter(:category_id => c1.id).size.should == 2
|
75
|
+
dbi.filter(:category_id => c2.id).size.should == 1
|
108
76
|
end
|
109
77
|
|
110
78
|
it "should filter results for has_and_belongs_to_many" do
|
111
|
-
tag1 =
|
112
|
-
tag2 =
|
113
|
-
p1=
|
114
|
-
p2=
|
115
|
-
p3=
|
79
|
+
tag1 = Fabricate(:tag, :name => "Linux")
|
80
|
+
tag2 = Fabricate(:tag, :name => "Android")
|
81
|
+
p1=Fabricate(:post, :tags => [tag1,tag2])
|
82
|
+
p2=Fabricate(:post, :tags => [tag1,tag2])
|
83
|
+
p3=Fabricate(:post, :tags => [tag1])
|
116
84
|
|
117
|
-
filter=Lolita::Configuration::Filter.new(
|
85
|
+
filter=Lolita::Configuration::Filter.new(dbi) do
|
118
86
|
field :tags
|
119
87
|
end
|
120
|
-
|
121
|
-
|
88
|
+
dbi.filter(:tag_ids => tag1.id).size.should == 3
|
89
|
+
dbi.filter(:tag_ids => tag2.id).size.should == 2
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "Filtering list" do
|
93
|
+
let(:list){ Lolita::Configuration::List}
|
94
|
+
|
95
|
+
it "should filter with default filters" do
|
96
|
+
tags = %w(Android Linux Windows).map{|name| Fabricate(:tag, :name => name )}
|
97
|
+
3.times {|i| Fabricate(:post,:tags => [tags[i]])}
|
98
|
+
|
99
|
+
list_conf = list.new(dbi) do
|
100
|
+
filter do
|
101
|
+
field :tags
|
102
|
+
end
|
103
|
+
end
|
104
|
+
list_conf.paginate(1).should have(3).items
|
105
|
+
request = Object.new
|
106
|
+
request.class_eval do
|
107
|
+
def params
|
108
|
+
{:filter => {:tag_ids => Tag.where(:name => 'Android').first.id}}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
list_conf.paginate(1,request).should have(1).items
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should filter with custom search" do
|
115
|
+
tags = %w(Android Linux Windows).map{|name| Fabricate(:tag, :name => name )}
|
116
|
+
3.times {|i| Fabricate(:post,:tags => [tags[i]])}
|
117
|
+
Post.class_eval do
|
118
|
+
def self.custom_filter query,request
|
119
|
+
where(:tag_ids.in => Tag.where(:name.in => ['Android','Linux']).map(&:id))
|
120
|
+
end
|
121
|
+
end
|
122
|
+
list_conf = list.new(dbi) do
|
123
|
+
filter do
|
124
|
+
field :tags
|
125
|
+
search :custom_filter
|
126
|
+
end
|
127
|
+
end
|
128
|
+
list_conf.paginate(1).should have(3).items
|
129
|
+
request = Object.new
|
130
|
+
request.class_eval do
|
131
|
+
def params
|
132
|
+
{:filter => {:tag_ids => Tag.where(:name => 'Android').first.id}}
|
133
|
+
end
|
134
|
+
end
|
135
|
+
list_conf.paginate(1,request).should have(2).items
|
136
|
+
end
|
122
137
|
end
|
123
138
|
end
|