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,4 +1,4 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../simple_spec_helper')
|
2
2
|
|
3
3
|
class SearchEngine
|
4
4
|
def run(*args)
|
@@ -6,75 +6,369 @@ class SearchEngine
|
|
6
6
|
end
|
7
7
|
|
8
8
|
describe Lolita::Configuration::List do
|
9
|
+
let(:klass){Lolita::Configuration::List}
|
10
|
+
let(:dbp_klass){Lolita::DBI::Base}
|
11
|
+
let(:dbp){Object.new}
|
12
|
+
let(:list){klass.new(dbp)}
|
9
13
|
|
10
|
-
|
11
|
-
|
14
|
+
it "should create new with dbp" do
|
15
|
+
expect{
|
16
|
+
klass.new(dbp)
|
17
|
+
}.not_to raise_error
|
12
18
|
end
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
19
|
+
|
20
|
+
it "should raise error when no dbp is given" do
|
21
|
+
expect{
|
22
|
+
klass.new nil
|
23
|
+
}.to raise_error(Lolita::UnknownDBPError)
|
17
24
|
end
|
18
25
|
|
19
|
-
|
20
|
-
|
26
|
+
describe "lolita accessors" do
|
27
|
+
it "should have lolita acessor for pagination_method" do
|
28
|
+
list.should respond_to(:pagination_method)
|
29
|
+
list.should respond_to(:pagination_method=)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have per_page acessor" do
|
33
|
+
list.should respond_to(:per_page)
|
34
|
+
list.should respond_to(:per_page=)
|
35
|
+
end
|
21
36
|
|
37
|
+
it "should have actions accessor" do
|
38
|
+
list.should respond_to(:actions)
|
39
|
+
list.should respond_to(:actions=)
|
22
40
|
end
|
23
41
|
end
|
24
42
|
|
25
|
-
it "should
|
26
|
-
|
43
|
+
it "should accept block and eval it" do
|
44
|
+
block = Proc.new{}
|
45
|
+
klass.any_instance.should_receive(:instance_eval).with(&block)
|
46
|
+
klass.new(dbp,&block)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should accept options and assign them as attributes" do
|
50
|
+
klass.any_instance.should_receive(:test_title=).with("test_title")
|
51
|
+
klass.new(dbp,:test_title => "test_title")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should set default attributes values" do
|
55
|
+
list.actions.should_not be_empty
|
56
|
+
list.per_page.should eq(10)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should populate actions with two default ones" do
|
60
|
+
list.actions.should have(2).items
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should initialize attribute and eval block after default attributes is initialized" do
|
64
|
+
actions_before = nil
|
65
|
+
per_page_before = nil
|
66
|
+
klass.new(dbp) do
|
67
|
+
actions_before = actions.dup
|
68
|
+
per_page_before = per_page
|
69
|
+
end
|
70
|
+
per_page_before.should eq(10)
|
71
|
+
actions_before.should be_empty
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should allow to add action with name, options and block" do
|
75
|
+
action = stub(:name => :name)
|
76
|
+
Lolita::Configuration::Action.stub(:new).and_return(action)
|
77
|
+
block = Proc.new{}
|
78
|
+
list.action :do_stuff, {:key => :value}, &block
|
79
|
+
list.actions.should include(action)
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#list" do
|
83
|
+
let(:nested_dbp){double("nested_dbp")}
|
84
|
+
before(:each) do
|
85
|
+
dbp_klass.stub(:create).and_return(nested_dbp)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should return @list when no args and/or block received" do
|
89
|
+
dummy_list = stub
|
90
|
+
list.instance_variable_set(:@list, dummy_list)
|
91
|
+
list.list.should eq(dummy_list)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should check for association and raise error when none is found" do
|
95
|
+
dbp.stub(:associations).and_return({})
|
96
|
+
expect{
|
97
|
+
list.list :dummy_name
|
98
|
+
}.to raise_error(Lolita::UnknownDBPError)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should create new dbp object for found assocition class" do
|
102
|
+
dummy_association = double("dummy_association")
|
103
|
+
dummy_association.stub(:klass).and_return(Object)
|
104
|
+
dummy_association.stub(:name).and_return("name")
|
105
|
+
dbp.stub(:associations).and_return({:dummy_association => dummy_association})
|
106
|
+
|
107
|
+
nested_list = double("nested_list")
|
108
|
+
Lolita::Configuration::NestedList.should_receive(:new).with(nested_dbp,list,{:association_name => "name"}).and_return(nested_list)
|
109
|
+
list.list :dummy_association
|
110
|
+
list.list.should eq(nested_list)
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "#search" do
|
116
|
+
let(:dummy_search){double("search")}
|
117
|
+
before(:each) do
|
118
|
+
dummy_search.stub(:update).and_return(true)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should add search when args and/or block is given" do
|
122
|
+
block = Proc.new{}
|
123
|
+
Lolita::Configuration::Search.should_receive(:new).with(dbp,:some_thing, &block).and_return(dummy_search)
|
124
|
+
list.search :some_thing, &block
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should return @search when nothing is received" do
|
128
|
+
Lolita::Configuration::Search.stub(:new).and_return(dummy_search)
|
129
|
+
list.search :some_args
|
130
|
+
list.search.should eq(dummy_search)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "#paginate" do
|
135
|
+
it "should call dbp#paginate with arguments and #pagination_method" do
|
136
|
+
request = double("request")
|
137
|
+
list.pagination_method = :my_dummy_method
|
138
|
+
dbp.should_receive(:paginate).with(1,list.per_page, :request => request, :pagination_method => :my_dummy_method).and_return([])
|
139
|
+
list.paginate(1, request)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should return pagination results" do
|
143
|
+
page = double("page")
|
144
|
+
dbp.should_receive(:paginate).and_return(page)
|
145
|
+
list.paginate(1)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should notify observers with method name, self and request" do
|
149
|
+
request = double("request")
|
150
|
+
dbp.stub(:paginate).and_return(nil)
|
151
|
+
list.should_receive(:changed)
|
152
|
+
list.should_receive(:notify_observers).with(:paginate,list,request)
|
153
|
+
list.paginate(1,request)
|
154
|
+
end
|
27
155
|
end
|
28
156
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
157
|
+
describe "#columns=" do
|
158
|
+
it "should raise error when something else then Enumerable or Lolita::Configuration::Columns is givne" do
|
159
|
+
expect{
|
160
|
+
list.columns = Object.new
|
161
|
+
}.to raise_error(ArgumentError,"Accepts only Enumerable or Lolita::Configuration::Columns.")
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should assign received values to @columns directly when they are kind of Lolita::Configuration::Columns" do
|
165
|
+
columns = double("columns")
|
166
|
+
columns.should_receive(:parent=).with(list)
|
167
|
+
columns.stub(:is_a?).with(Lolita::Configuration::Columns).and_return(true)
|
168
|
+
list.columns = columns
|
169
|
+
list.columns.should eq(columns)
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should iterate through all possible columns and create column with each value" do
|
173
|
+
list.should_receive(:column).exactly(3).times.and_return(stub())
|
174
|
+
list.columns= [1,2,3]
|
175
|
+
end
|
34
176
|
end
|
35
177
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
title "Column two"
|
45
|
-
end
|
178
|
+
describe "#columns" do
|
179
|
+
it "should create columns with and/or args, block" do
|
180
|
+
block = Proc.new{}
|
181
|
+
columns = double("columns")
|
182
|
+
columns.should_receive(:parent=).with(list)
|
183
|
+
columns.stub(:is_a?).with(Lolita::Configuration::Columns).and_return(true)
|
184
|
+
Lolita::Configuration::Columns.should_receive(:new).with(dbp,1,2,3,&block).and_return(columns)
|
185
|
+
list.columns(1,2,3,&block)
|
46
186
|
end
|
47
|
-
|
187
|
+
|
188
|
+
it "should return columns when no arguments are given" do
|
189
|
+
columns = double("columns")
|
190
|
+
list.instance_variable_set(:@columns,columns)
|
191
|
+
list.columns.should eq(columns)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should create column with args and block" do
|
196
|
+
block = Proc.new{}
|
197
|
+
columns = stub("columns")
|
198
|
+
list.stub(:columns).and_return(columns)
|
199
|
+
columns.should_receive("column").with(1,2,3,&block)
|
200
|
+
list.column(1,2,3,&block)
|
48
201
|
end
|
49
202
|
|
50
|
-
it "should
|
51
|
-
|
52
|
-
|
53
|
-
|
203
|
+
it "should determine if there is filter defined for list by checking class" do
|
204
|
+
list.filter?.should_not be_true
|
205
|
+
filter = double("filter")
|
206
|
+
filter.stub(:is_a?).with(Lolita::Configuration::Filter).and_return(true)
|
207
|
+
list.instance_variable_set(:@filter,filter)
|
208
|
+
list.filter?.should be_true
|
54
209
|
end
|
55
210
|
|
56
|
-
|
57
|
-
|
58
|
-
|
211
|
+
describe "#filter" do
|
212
|
+
let(:filter){double("filter")}
|
213
|
+
it "should create filter with arguments and/or block" do
|
214
|
+
block = Proc.new{}
|
215
|
+
list.stub(:add_observer).and_return(true)
|
216
|
+
Lolita::Configuration::Filter.should_receive(:new).with(dbp,1,2,3,&block)
|
217
|
+
list.filter(1,2,3,&block)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should return @filter when no arguments is given" do
|
221
|
+
list.stub(:add_observer).and_return(true)
|
222
|
+
Lolita::Configuration::Filter.should_receive(:new).and_return(filter)
|
223
|
+
list.filter(1,2,3)
|
224
|
+
list.filter.should eq(filter)
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should add observer to filter" do
|
228
|
+
Lolita::Configuration::Filter.stub(:new).and_return(filter)
|
229
|
+
list.should_receive(:add_observer).with(filter)
|
230
|
+
list.filter 1,2
|
59
231
|
end
|
60
|
-
list.columns.size.should == 3
|
61
232
|
end
|
62
233
|
|
63
|
-
describe "
|
64
|
-
|
234
|
+
describe "#by_path" do
|
235
|
+
it "should return self when path is empty" do
|
236
|
+
list.by_path([]).should eq(list)
|
237
|
+
end
|
238
|
+
|
239
|
+
it "should return object list when path starts with l" do
|
240
|
+
nested_list = double("nested_list")
|
241
|
+
list.stub(:list).and_return(nested_list)
|
242
|
+
list.by_path(["l_some_list"]).should eq(nested_list)
|
243
|
+
end
|
65
244
|
|
66
|
-
it "should
|
67
|
-
|
68
|
-
|
245
|
+
it "should return column with [column_name] list when c_column_name in path" do
|
246
|
+
columns = double("columns")
|
247
|
+
column = double("column_with_name")
|
248
|
+
nested_list = double("nested_list")
|
249
|
+
columns.stub(:by_name).with("column_name").and_return(column)
|
250
|
+
column.stub(:list).and_return(nested_list)
|
251
|
+
list.stub(:columns).and_return(columns)
|
252
|
+
list.by_path(["c_column_name"]).should eq(nested_list)
|
69
253
|
end
|
70
254
|
|
71
|
-
it "should
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
255
|
+
it "should go through all path array until last object found" do
|
256
|
+
path = ["l_some_list","c_column_name","l_other_list"]
|
257
|
+
nested_list_1 = double("nested_list_1")
|
258
|
+
nested_list_2 = double("nested_list_2")
|
259
|
+
nested_list_3 = double("nested_list_3")
|
260
|
+
columns = double("columns")
|
261
|
+
column = double("column")
|
262
|
+
|
263
|
+
nested_list_1.stub(:columns).and_return(columns)
|
264
|
+
nested_list_2.stub(:list).and_return(nested_list_3)
|
265
|
+
columns.stub(:by_name).with("column_name").and_return(column)
|
266
|
+
column.stub("list").and_return(nested_list_2)
|
267
|
+
list.stub(:list).and_return(nested_list_1)
|
268
|
+
|
269
|
+
list.by_path(path).should eq(nested_list_3)
|
76
270
|
end
|
77
271
|
end
|
78
272
|
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
# before(:each) do
|
279
|
+
# @dbi=Lolita::DBI::Base.create(Post)
|
280
|
+
# end
|
281
|
+
|
282
|
+
# after(:each) do
|
283
|
+
# @recs||=[]
|
284
|
+
# @recs.each{|r| r.destroy}
|
285
|
+
# end
|
286
|
+
|
287
|
+
# let(:list_class){Lolita::Configuration::List}
|
288
|
+
|
289
|
+
# it "should create new list with block" do
|
290
|
+
# Lolita::Configuration::List.new(@dbi) do
|
291
|
+
|
292
|
+
# end
|
293
|
+
# end
|
294
|
+
|
295
|
+
# it "should create new list without block" do
|
296
|
+
# Lolita::Configuration::List.new(@dbi)
|
297
|
+
# end
|
298
|
+
|
299
|
+
# it "should generate columns if none is given" do
|
300
|
+
# list=Lolita::Configuration::List.new(@dbi)
|
301
|
+
# list.columns.should have(@dbi.fields.reject{|f| f.technical?}.size).items
|
302
|
+
# list=Lolita::Configuration::List.new(@dbi){}
|
303
|
+
# list.columns.should have(@dbi.fields.reject{|f| f.technical?}.size).items
|
304
|
+
# end
|
305
|
+
|
306
|
+
# it "should not generate columns if one or more is given" do
|
307
|
+
# list=list_class.new(@dbi,:columns=>[{:name=>"C1"}])
|
308
|
+
# list.columns.should have(1).item
|
309
|
+
# list=list_class.new(@dbi) do
|
310
|
+
# column :name=>"Col1"
|
311
|
+
# column :name=>"col3"
|
312
|
+
# column do
|
313
|
+
# name "col2"
|
314
|
+
# title "Column two"
|
315
|
+
# end
|
316
|
+
# end
|
317
|
+
# list.columns.should have(3).items
|
318
|
+
# end
|
319
|
+
|
320
|
+
# it "should get records for list page" do
|
321
|
+
# 1.upto(5) { Fabricate(:post)}
|
322
|
+
# list=list_class.new(@dbi,:per_page => 1)
|
323
|
+
# list.paginate(1,Object.new).to_a.size.should == 1
|
324
|
+
# end
|
325
|
+
|
326
|
+
# it "should define columns when Symbols are given as args" do
|
327
|
+
# list = list_class.new(@dbi) do
|
328
|
+
# columns :col1,:col2,:col3
|
329
|
+
# end
|
330
|
+
# list.columns.should have(3).items
|
331
|
+
# end
|
332
|
+
|
333
|
+
# describe "search" do
|
334
|
+
# let(:list){ list_class.new(@dbi,:per_page => 10) }
|
335
|
+
|
336
|
+
# it "should define default search by passing true" do
|
337
|
+
# list.search true
|
338
|
+
# list.search.class.to_s.should match(/Lolita::Configuration::Search/)
|
339
|
+
# end
|
340
|
+
|
341
|
+
# it "should define search with block" do
|
342
|
+
# list.search do
|
343
|
+
# with SearchEngine.new
|
344
|
+
# end
|
345
|
+
# list.search.class.to_s.should match(/Lolita::Configuration::Search/)
|
346
|
+
# end
|
347
|
+
# end
|
348
|
+
|
349
|
+
# describe "sublist" do
|
350
|
+
|
351
|
+
# it "should allow to define sublist with association name" do
|
352
|
+
# list_class.new(@dbi) do
|
353
|
+
# list(:comments){}
|
354
|
+
# end
|
355
|
+
# end
|
356
|
+
|
357
|
+
# it "should raise error when no DBI is given or found through association" do
|
358
|
+
# expect{
|
359
|
+
# list_class.new(@dbi) do
|
360
|
+
# list{}
|
361
|
+
# end
|
362
|
+
# }.to raise_error(Lolita::UnknownDBPError)
|
363
|
+
|
364
|
+
# expect{
|
365
|
+
# list_class.new(@dbi) do
|
366
|
+
# list(:title)
|
367
|
+
# end
|
368
|
+
# }.to raise_error(Lolita::UnknownDBPError)
|
369
|
+
# end
|
370
|
+
|
371
|
+
#end
|
372
|
+
|
79
373
|
end
|
80
374
|
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Lolita::Configuration::NestedList do
|
4
|
+
let(:dbi){ Lolita::DBI::Base.create(Post) }
|
5
|
+
let(:comment_dbi){ Lolita::DBI::Base.create(Comment) }
|
6
|
+
let(:list_class){ Lolita::Configuration::List }
|
7
|
+
let(:nested_list_class){ Lolita::Configuration::NestedList }
|
8
|
+
|
9
|
+
it "should create new nested list" do
|
10
|
+
expect do
|
11
|
+
Lolita::Configuration::NestedList.new(comment_dbi,list_class.new(dbi))
|
12
|
+
end.not_to raise_error
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should raise error when no list or nested list or column is given" do
|
16
|
+
expect do
|
17
|
+
Lolita::Configuration::NestedList.new(comment_dbi,nil)
|
18
|
+
end.to raise_error(Lolita::ParentNotAListError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should receive List, NestedList or Column as parent" do
|
22
|
+
list_object = Lolita::Configuration::List.new(dbi)
|
23
|
+
column_object = Lolita::Configuration::Column.new(dbi,:name => :title)
|
24
|
+
|
25
|
+
list = nested_list_class.new(dbi, list_object)
|
26
|
+
list.parent.should == list_object
|
27
|
+
list = nested_list_class.new(dbi, column_object)
|
28
|
+
list.parent.should == column_object
|
29
|
+
nested_list_object = Lolita::Configuration::NestedList.new(dbi,list_object)
|
30
|
+
list = nested_list_class.new(dbi, nested_list_object)
|
31
|
+
list.parent.should == nested_list_object
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should collect all parents " do
|
35
|
+
list = list_class.new(dbi)
|
36
|
+
nlist1 = nested_list_class.new(dbi,list)
|
37
|
+
nlist2 = nested_list_class.new(dbi,nlist1)
|
38
|
+
nlist3 = nested_list_class.new(dbi,nlist2)
|
39
|
+
nlist3.parents.should == [nlist2,nlist1,list]
|
40
|
+
nlist2.parents.should == [nlist1,list]
|
41
|
+
nlist1.parents.should == [list]
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return depth of list" do
|
45
|
+
list = list_class.new(dbi)
|
46
|
+
nlist1 = nested_list_class.new(dbi,list)
|
47
|
+
nlist2= nested_list_class.new(dbi,nlist1)
|
48
|
+
nlist1.depth.should == 1
|
49
|
+
nlist2.depth.should == 2
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have list association name" do
|
53
|
+
main_list = list_class.new(dbi) do
|
54
|
+
list(:comments){}
|
55
|
+
end
|
56
|
+
main_list.list.association_name.should == :comments
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should have association" do
|
60
|
+
main_list = list_class.new(dbi) do
|
61
|
+
list(:comments){}
|
62
|
+
end
|
63
|
+
main_list.list.association.name.should == dbi.associations[:comments].name
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return root" do
|
67
|
+
list = list_class.new(dbi)
|
68
|
+
nlist1 = nested_list_class.new(dbi,list)
|
69
|
+
nlist2 = nested_list_class.new(dbi,nlist1)
|
70
|
+
nlist2.root.should == list
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should create mapping for DBI class" do
|
74
|
+
list = list_class.new(dbi)
|
75
|
+
nlist = nested_list_class.new(comment_dbi,list, :association_name => "comments")
|
76
|
+
nlist.mapping.to.should == Comment
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should allow to define sublist in any depth" do
|
80
|
+
dbi = Lolita::DBI::Base.create(Category)
|
81
|
+
|
82
|
+
new_list = list_class.new(dbi) do
|
83
|
+
list(:posts) do
|
84
|
+
column :title
|
85
|
+
list(:comments) do
|
86
|
+
column :body
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
new_list.list.list.columns.should have(1).item
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should create options for nested lists" do
|
95
|
+
dbi = Lolita::DBI::Base.create(Category)
|
96
|
+
|
97
|
+
new_list = list_class.new(dbi) do
|
98
|
+
list(:posts) do
|
99
|
+
column :title
|
100
|
+
list(:comments) do
|
101
|
+
column :body
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
record = Fabricate(:category)
|
107
|
+
post = Fabricate(:post)
|
108
|
+
new_list.list.nested_options_for(record)[:nested].keys.should == ["category_id",:parent,:path]
|
109
|
+
new_list.list.list.nested_options_for(post)[:nested].keys.should == ["post_id",:parent,:path]
|
110
|
+
end
|
111
|
+
end
|