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
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../simple_spec_helper')
|
2
|
+
|
3
|
+
describe Lolita::Extensions::Authentication::Proxy do
|
4
|
+
let(:klass){ Lolita::Extensions::Authentication::Proxy }
|
5
|
+
let(:proxy){ klass.new(Object.new,{}) }
|
6
|
+
|
7
|
+
it "should create new proxy" do
|
8
|
+
expect do
|
9
|
+
klass.new(Object.new,{})
|
10
|
+
end.not_to raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have #current_user" do
|
14
|
+
proxy.respond_to?(:current_user).should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have #user_signed_in?" do
|
18
|
+
proxy.respond_to?(:user_signed_in?).should be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have #adapter" do
|
22
|
+
proxy.adapter.is_a?(Object)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have #authenticate_user!" do
|
26
|
+
proxy.respond_to?(:authenticate_user!).should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have #sign_out_path" do
|
30
|
+
proxy.respond_to?(:sign_out_path).should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have #sign_out_via" do
|
34
|
+
proxy.respond_to?(:sign_out_via).should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have #edit_path" do
|
38
|
+
proxy.respond_to?(:edit_path).should be_true
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'Connecting adapter' do
|
42
|
+
context 'default adapter' do
|
43
|
+
it "should create when Authentication is not specified" do
|
44
|
+
proxy.adapter.should be_a(Lolita::Extensions::Authentication::DefaultAdapter)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
context 'devise adapter' do
|
48
|
+
it "should create when Lolita.authentication is specified" do
|
49
|
+
Lolita.authentication = :test
|
50
|
+
proxy.adapter.should be_a(Lolita::Extensions::Authentication::DeviseAdapter)
|
51
|
+
Lolita.authentication = nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../simple_spec_helper')
|
2
|
+
|
3
|
+
class TestApplicationController
|
4
|
+
include Lolita::Extensions
|
5
|
+
|
6
|
+
def authorize! *args
|
7
|
+
"context_response"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class TestAbility
|
12
|
+
def initialize *args
|
13
|
+
end
|
14
|
+
|
15
|
+
def can? action,klass
|
16
|
+
action == :read && klass == String
|
17
|
+
end
|
18
|
+
|
19
|
+
def cannot? *args
|
20
|
+
!can?(*args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def authorize! *args
|
24
|
+
"ability_response"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module CanCan
|
29
|
+
end
|
30
|
+
|
31
|
+
describe Lolita::Extensions::Authorization::CanCanAdapter do
|
32
|
+
let(:klass){ Lolita::Extensions::Authorization::CanCanAdapter }
|
33
|
+
around(:each){|example|
|
34
|
+
Lolita.authorization = 'CanCan'
|
35
|
+
Lolita.ability_class = TestAbility
|
36
|
+
example.run
|
37
|
+
Lolita.authorization = nil
|
38
|
+
Lolita.ability_class = nil
|
39
|
+
}
|
40
|
+
let(:adapter){ klass.new(TestApplicationController.new,{}) }
|
41
|
+
|
42
|
+
it "should create new" do
|
43
|
+
expect do
|
44
|
+
klass.new(TestApplicationController.new,{})
|
45
|
+
end.not_to raise_error
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should raise error without authorization" do
|
49
|
+
expect do
|
50
|
+
Lolita.authorization = nil
|
51
|
+
klass.new(TestApplicationController.new,{})
|
52
|
+
end.to raise_error(Lolita::NoAuthorizationDefinedError)
|
53
|
+
end
|
54
|
+
|
55
|
+
context "current user" do
|
56
|
+
|
57
|
+
it "can do some action with current abilities" do
|
58
|
+
adapter.can?(:read,"HiddenText".class).should be_true
|
59
|
+
adapter.can?(:create,"HiddenText".class).should be_false
|
60
|
+
end
|
61
|
+
|
62
|
+
it "can ONLY ado ctions from abilities" do
|
63
|
+
adapter.cannot?(:read,"HiddenText".class).should be_false
|
64
|
+
adapter.cannot?(:create,"HiddenText".class).should be_true
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should have current ability" do
|
68
|
+
adapter.current_ability.should be_a(Lolita.ability_class)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should authorize resource" do
|
72
|
+
adapter2 = klass.new(nil)
|
73
|
+
expect do
|
74
|
+
adapter2.authorize!(:read,Object).should == "ability_response"
|
75
|
+
adapter.authorize!(:read,Object).should == "context_response"
|
76
|
+
end.not_to raise_error
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'Integration with proxy' do
|
81
|
+
let(:proxy){
|
82
|
+
mock_class = Object.new
|
83
|
+
mock_class.class_eval{include Lolita::Extensions}
|
84
|
+
Lolita::Extensions::Authorization::Proxy.new(mock_class,{})
|
85
|
+
}
|
86
|
+
it "should have the same method results for adapter and proxy" do
|
87
|
+
proxy.adapter = adapter
|
88
|
+
%w(can? cannot? authorize!).each do |name|
|
89
|
+
proxy.send(name,:read,String).should eql(adapter.send(name,:read,String))
|
90
|
+
end
|
91
|
+
proxy.adapter.current_ability == adapter.current_ability
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../simple_spec_helper')
|
2
|
+
|
3
|
+
describe Lolita::Extensions::Authorization::DefaultAdapter do
|
4
|
+
let(:klass){ Lolita::Extensions::Authorization::DefaultAdapter }
|
5
|
+
let(:adapter){ klass.new(Object.new,{}) }
|
6
|
+
|
7
|
+
it "should create new" do
|
8
|
+
expect do
|
9
|
+
klass.new(Object.new,{})
|
10
|
+
end.not_to raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
context "current user" do
|
14
|
+
|
15
|
+
it "can do all" do
|
16
|
+
adapter.can?(:read,Object.new).should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "cannot do nothing" do
|
20
|
+
adapter.cannot?([]).should be_false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not have current ability" do
|
24
|
+
adapter.current_ability.should be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be authorized for all" do
|
28
|
+
expect do
|
29
|
+
adapter.authorize!
|
30
|
+
end.not_to raise_error
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'Integration with proxy' do
|
35
|
+
let(:proxy){ Lolita::Extensions::Authorization::Proxy.new(Object.new,{}) }
|
36
|
+
it "should have the same method results for adapter and proxy" do
|
37
|
+
proxy.adapter = adapter
|
38
|
+
%w(can? cannot? current_ability authorize!).each do |name|
|
39
|
+
proxy.send(name).should eql(adapter.send(name))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../simple_spec_helper')
|
2
|
+
|
3
|
+
class TestAbility
|
4
|
+
def initialize(*args)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Lolita::Extensions::Authorization::Proxy do
|
9
|
+
let(:klass){ Lolita::Extensions::Authorization::Proxy }
|
10
|
+
let(:proxy){ klass.new(Object.new,{}) }
|
11
|
+
around(:each) do |example|
|
12
|
+
Lolita.ability_class = TestAbility
|
13
|
+
example.run
|
14
|
+
Lolita.ability_class = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create new proxy" do
|
18
|
+
expect do
|
19
|
+
klass.new(Object.new,{})
|
20
|
+
end.not_to raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have #can?" do
|
24
|
+
proxy.respond_to?(:can?).should be_true
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should have #cannot?" do
|
28
|
+
proxy.respond_to?(:cannot?).should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have #authorize!" do
|
32
|
+
proxy.respond_to?(:authorize!).should be_true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have #current_ability" do
|
36
|
+
proxy.respond_to?(:current_ability).should be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'Connecting adapter' do
|
40
|
+
context 'default adapter' do
|
41
|
+
it "should create when authorization is not specified or is 'Default'" do
|
42
|
+
proxy.adapter.should be_a(Lolita::Extensions::Authorization::DefaultAdapter)
|
43
|
+
Lolita.authorization = 'Default'
|
44
|
+
proxy.adapter.should be_a(Lolita::Extensions::Authorization::DefaultAdapter)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
context 'devise adapter' do
|
48
|
+
let(:proxy){
|
49
|
+
mock_class = Object.new
|
50
|
+
mock_class.class_eval{include Lolita::Extensions}
|
51
|
+
klass.new(mock_class,{})
|
52
|
+
}
|
53
|
+
it "should create when Lolita.authentication is specified" do
|
54
|
+
Lolita.authorization = 'CanCan'
|
55
|
+
proxy.adapter.should be_a(Lolita::Extensions::Authorization::CanCanAdapter)
|
56
|
+
Lolita.authorization = nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../simple_spec_helper')
|
2
|
+
|
3
|
+
class WithLolitaExtensions
|
4
|
+
include Lolita::Extensions
|
5
|
+
end
|
6
|
+
|
7
|
+
module Lolita::Extensions::Test
|
8
|
+
class Proxy
|
9
|
+
def initialize *args
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Lolita::Extensions do
|
15
|
+
let(:test_class){ WithLolitaExtensions.new }
|
16
|
+
let(:object){
|
17
|
+
klass = Object.new
|
18
|
+
klass.class_eval{include Lolita::Extensions}
|
19
|
+
klass
|
20
|
+
}
|
21
|
+
|
22
|
+
it "should load all extensions proxies" do
|
23
|
+
Lolita::Extensions.add(:test)
|
24
|
+
test_class.load_extensions_proxies(object)
|
25
|
+
test_class.test_proxy.should be_a(Lolita::Extensions::Test::Proxy)
|
26
|
+
end
|
27
|
+
|
28
|
+
context "default extensions" do
|
29
|
+
it "should have default extensions proxies" do
|
30
|
+
test_class.load_extensions_proxies(object)
|
31
|
+
Lolita::Extensions::EXTENSIONS.each do |name|
|
32
|
+
test_class.send(:"#{name}_proxy").should be_a("Lolita::Extensions::#{name.to_s.camelize}::Proxy".constantize)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "default configuration" do
|
38
|
+
|
39
|
+
it "should have authentication adapter" do
|
40
|
+
test_class.load_extensions_proxies(object)
|
41
|
+
test_class.authentication_proxy.respond_to?(:adapter).should be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
data/spec/lolita_spec.rb
CHANGED
data/spec/orm/mongoid.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
|
+
|
1
2
|
class Category
|
2
3
|
include Mongoid::Document
|
3
4
|
include Lolita::Configuration
|
4
5
|
field :name, type: String
|
5
|
-
has_many :
|
6
|
+
has_many :posts
|
7
|
+
|
8
|
+
lolita do
|
9
|
+
list do
|
10
|
+
list(:posts) do
|
11
|
+
column :comments do
|
12
|
+
list do
|
13
|
+
column :body
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
6
19
|
end
|
@@ -15,7 +15,15 @@ class Post
|
|
15
15
|
default_scope order_by([:title, :asc])
|
16
16
|
accepts_nested_attributes_for :comments, :reject_if => :all_blank
|
17
17
|
|
18
|
-
lolita
|
18
|
+
lolita do
|
19
|
+
list do
|
20
|
+
column :comments do
|
21
|
+
list do
|
22
|
+
column :body
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
19
27
|
|
20
28
|
def self.custom_search query,request=nil,dbi=nil
|
21
29
|
self.where(:expire_date.gt => Date.today)
|
@@ -7,10 +7,6 @@ require "sprockets/railtie"
|
|
7
7
|
|
8
8
|
Bundler.require(:default, LOLITA_ORM, Rails.env) if defined?(Bundler)
|
9
9
|
|
10
|
-
require 'lolita'
|
11
|
-
require "lolita/rails/all"
|
12
|
-
require 'kaminari'
|
13
|
-
|
14
10
|
module RailsApp
|
15
11
|
class Application < Rails::Application
|
16
12
|
# Add additional load paths for your own custom dirs
|
@@ -5,8 +5,7 @@ LOLITA_ORM=:mongoid unless defined?(LOLITA_ORM)
|
|
5
5
|
gemfile = File.expand_path('../../Gemfile', __FILE__)
|
6
6
|
begin
|
7
7
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
8
|
-
|
9
|
-
Bundler.setup(:default,Rails.env,LOLITA_ORM)
|
8
|
+
Bundler.setup(Rails.env)
|
10
9
|
rescue Bundler::GemNotFound => e
|
11
10
|
STDERR.puts e.message
|
12
11
|
STDERR.puts "Try running `bundle install`."
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/simple_spec_helper')
|
2
|
+
|
3
|
+
describe Lolita::Register do
|
4
|
+
let(:register){ Lolita::Register.new }
|
5
|
+
it "should create new" do
|
6
|
+
expect do
|
7
|
+
Lolita::Register.new
|
8
|
+
end.not_to raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should set new key" do
|
12
|
+
register.set(:test, 1).should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should get key" do
|
16
|
+
register.set(:test, 1)
|
17
|
+
register.get(:test).should == 1
|
18
|
+
register.get(:not_existing_key).should be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should get with options" do
|
22
|
+
register.set(:test, 1, :foo => :bar)
|
23
|
+
register.set(:test_without_options, 1)
|
24
|
+
register.get_with_options(:test).should have(2).items
|
25
|
+
register.get_with_options(:test_without_options).should have(1).item
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should set key with options" do
|
29
|
+
register.set(:test, 1, :foo => :bar).should be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
context "filter" do
|
33
|
+
it "should accept only key" do
|
34
|
+
register.set(:test, 1, :foo => :bar)
|
35
|
+
register.filter(:test).should == [[1, {:foo=>:bar}]]
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should accept key and options" do
|
39
|
+
register.set(:test, 1, :foo => :bar)
|
40
|
+
register.filter(:test, :foo => 0).should be_empty
|
41
|
+
register.filter(:test, :foo => :bar).should have(1).item
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should accept only options" do
|
45
|
+
register.set(:test, 1, :foo => :bar)
|
46
|
+
register.filter(:foo => 0).should be_empty
|
47
|
+
register.filter(:foo => :bar).should have(1).item
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/search/simple_spec.rb
CHANGED
@@ -18,20 +18,20 @@ describe Lolita::Search::Simple do
|
|
18
18
|
|
19
19
|
it "should run default search when no search method is provided" do
|
20
20
|
pending "think that map_reduce should be fixed"
|
21
|
-
|
21
|
+
Fabricate(:post,:title => "moonwalker")
|
22
22
|
search = Lolita::Search::Simple.new(dbi)
|
23
23
|
search.run("moon").size.should == 1
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should accept custom dbi for search" do
|
27
|
-
|
27
|
+
Fabricate(:category, :name => "special_text")
|
28
28
|
search.run("special_text").should be_empty
|
29
29
|
search.run("special_text",Object.new,Lolita::DBI::Base.create(Category)).should have(1).item
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should run custom search when search method is provided" do
|
33
33
|
search = Lolita::Search::Simple.new(dbi,:custom_search)
|
34
|
-
post =
|
34
|
+
post = Fabricate(:post,:expire_date => 2.days.since)
|
35
35
|
results = search.run("")
|
36
36
|
results.should have(1).item
|
37
37
|
results.first.should == post
|
@@ -39,7 +39,7 @@ describe Lolita::Search::Simple do
|
|
39
39
|
|
40
40
|
it "should use only given fields when they are presented" do
|
41
41
|
search = Lolita::Search::Simple.new(dbi,:fields => [:body])
|
42
|
-
|
42
|
+
Fabricate(:post,:title => "only_in_title")
|
43
43
|
search.run("only_in_title").should have(0).items
|
44
44
|
search2 = Lolita::Search::Simple.new(dbi,:fields => [:title])
|
45
45
|
search2.run("only_in_title").should have(1).item
|