godmin 0.12.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +5 -0
- data/README.md +5 -11
- data/app/views/godmin/application/welcome.html.erb +4 -52
- data/app/views/godmin/resource/_filters.html.erb +1 -1
- data/app/views/godmin/resource/_table.html.erb +2 -2
- data/app/views/layouts/godmin/_layout.html.erb +2 -2
- data/app/views/layouts/godmin/application.html.erb +2 -2
- data/godmin.gemspec +4 -1
- data/lib/generators/godmin/install/install_generator.rb +0 -10
- data/lib/godmin.rb +3 -6
- data/lib/godmin/application_controller.rb +8 -4
- data/lib/godmin/authorization.rb +1 -1
- data/lib/godmin/authorization/policy_finder.rb +4 -3
- data/lib/godmin/engine_wrapper.rb +49 -0
- data/lib/godmin/helpers/tables.rb +6 -6
- data/lib/godmin/resolver.rb +32 -36
- data/lib/godmin/version.rb +1 -1
- data/test/dummy/admin/Rakefile +24 -0
- data/test/dummy/admin/admin.gemspec +15 -0
- data/test/dummy/admin/app/assets/javascripts/admin/application.js +14 -0
- data/test/dummy/admin/app/assets/stylesheets/admin/application.css +16 -0
- data/test/dummy/admin/app/controllers/admin/application_controller.rb +5 -0
- data/test/dummy/admin/app/controllers/admin/articles_controller.rb +7 -0
- data/test/dummy/admin/app/helpers/admin/application_helper.rb +4 -0
- data/test/dummy/admin/app/services/admin/article_service.rb +11 -0
- data/test/dummy/{app/assets/images → admin/app/views/admin/articles}/.keep +0 -0
- data/test/dummy/{app/mailers → admin/app/views/admin/articles/columns}/.keep +0 -0
- data/test/dummy/admin/app/views/admin/articles/filters/.keep +0 -0
- data/test/dummy/admin/app/views/admin/resource/.keep +0 -0
- data/test/dummy/admin/app/views/admin/resource/columns/.keep +0 -0
- data/test/dummy/admin/app/views/admin/resource/filters/.keep +0 -0
- data/test/dummy/admin/app/views/admin/shared/_navigation.html.erb +1 -0
- data/test/dummy/admin/bin/rails +12 -0
- data/test/dummy/admin/config/routes.rb +4 -0
- data/test/dummy/admin/lib/admin.rb +4 -0
- data/test/dummy/admin/lib/admin/engine.rb +5 -0
- data/test/dummy/admin/lib/admin/version.rb +3 -0
- data/test/dummy/app/assets/javascripts/application.js +1 -0
- data/test/dummy/app/assets/stylesheets/application.css +2 -1
- data/test/dummy/app/controllers/application_controller.rb +2 -0
- data/test/dummy/app/controllers/articles_controller.rb +3 -0
- data/test/dummy/app/models/article.rb +2 -0
- data/test/dummy/app/services/article_service.rb +9 -0
- data/test/dummy/app/views/articles/.keep +0 -0
- data/test/dummy/app/views/articles/columns/.keep +0 -0
- data/test/dummy/app/views/articles/filters/.keep +0 -0
- data/test/dummy/app/views/resource/.keep +0 -0
- data/test/dummy/app/views/resource/columns/.keep +0 -0
- data/test/dummy/app/views/resource/filters/.keep +0 -0
- data/test/dummy/app/views/shared/_navigation.html.erb +1 -0
- data/test/dummy/config/database.yml +0 -6
- data/test/dummy/config/environments/test.rb +4 -0
- data/test/dummy/config/routes.rb +3 -2
- data/test/dummy/db/migrate/20150717121532_create_articles.rb +11 -0
- data/test/dummy/db/schema.rb +9 -1
- data/test/fakes/article.rb +4 -0
- data/test/fakes/article_service.rb +68 -0
- data/test/integration/column_ordering_test.rb +23 -0
- data/test/integration/column_overriding_test.rb +59 -0
- data/test/integration/filter_overriding_test.rb +51 -0
- data/test/integration/partial_overriding_test.rb +51 -0
- data/test/integration/template_overriding_test.rb +51 -0
- data/test/integration/welcome_test.rb +8 -0
- data/test/lib/godmin/engine_wrapper_test.rb +55 -0
- data/test/lib/godmin/policy_finder_test.rb +30 -34
- data/test/lib/godmin/resolver_test.rb +26 -36
- data/test/lib/godmin/resources/resource_service/batch_actions_test.rb +1 -1
- data/test/lib/godmin/resources/resource_service/filters_test.rb +1 -1
- data/test/lib/godmin/resources/resource_service/pagination_test.rb +1 -1
- data/test/lib/godmin/resources/resource_service/scopes_test.rb +7 -7
- data/test/lib/godmin/resources/resource_service_test.rb +2 -2
- data/test/test_helper.rb +23 -66
- metadata +127 -20
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config/environments/production.rb +0 -80
- data/test/dummy/config/locales/en.yml +0 -23
- data/test/godmin_test.rb +0 -7
- data/test/integration/navigation_test.rb +0 -10
@@ -0,0 +1,51 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ColumnOverridingTest < ActionDispatch::IntegrationTest
|
4
|
+
def test_default_filter
|
5
|
+
visit articles_path
|
6
|
+
assert find("#filters").has_content? "Title"
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_override_filter
|
10
|
+
add_template "app/views/articles/filters/_title.html.erb", "foo"
|
11
|
+
visit articles_path
|
12
|
+
assert find("#filters").has_content? "foo"
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_override_resource_filter
|
16
|
+
add_template "app/views/resource/filters/_title.html.erb", "foo"
|
17
|
+
visit articles_path
|
18
|
+
assert find("#filters").has_content? "foo"
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_override_filter_and_resource_filter
|
22
|
+
add_template "app/views/articles/filters/_title.html.erb", "foo"
|
23
|
+
add_template "app/views/resource/filters/_title.html.erb", "bar"
|
24
|
+
visit articles_path
|
25
|
+
assert find("#filters").has_content? "foo"
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_default_filter_in_engine
|
29
|
+
visit admin.articles_path
|
30
|
+
assert find("#filters").has_content? "Title"
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_override_filter_in_engine
|
34
|
+
add_template "admin/app/views/admin/articles/filters/_title.html.erb", "foo"
|
35
|
+
visit admin.articles_path
|
36
|
+
assert find("#filters").has_content? "foo"
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_override_resource_filter_in_engine
|
40
|
+
add_template "admin/app/views/admin/resource/filters/_title.html.erb", "foo"
|
41
|
+
visit admin.articles_path
|
42
|
+
assert find("#filters").has_content? "foo"
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_override_filter_and_resource_filter_in_engine
|
46
|
+
add_template "admin/app/views/admin/articles/filters/_title.html.erb", "foo"
|
47
|
+
add_template "admin/app/views/admin/resource/filters/_title.html.erb", "bar"
|
48
|
+
visit admin.articles_path
|
49
|
+
assert find("#filters").has_content? "foo"
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class PartialOverridingTest < ActionDispatch::IntegrationTest
|
4
|
+
def test_default_partial
|
5
|
+
visit new_article_path
|
6
|
+
assert page.has_content? "Title"
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_override_partial
|
10
|
+
add_template "app/views/articles/_form.html.erb", "foo"
|
11
|
+
visit new_article_path
|
12
|
+
assert page.has_content? "foo"
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_override_resource_partial
|
16
|
+
add_template "app/views/resource/_form.html.erb", "foo"
|
17
|
+
visit new_article_path
|
18
|
+
assert page.has_content? "foo"
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_override_partial_and_resource_partial
|
22
|
+
add_template "app/views/articles/_form.html.erb", "foo"
|
23
|
+
add_template "app/views/resource/_form.html.erb", "bar"
|
24
|
+
visit new_article_path
|
25
|
+
assert page.has_content? "foo"
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_default_partial_in_engine
|
29
|
+
visit admin.new_article_path
|
30
|
+
assert page.has_content? "Title"
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_override_partial_in_engine
|
34
|
+
add_template "admin/app/views/admin/articles/_form.html.erb", "foo"
|
35
|
+
visit admin.new_article_path
|
36
|
+
assert page.has_content? "foo"
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_override_resource_partial_in_engine
|
40
|
+
add_template "admin/app/views/admin/resource/_form.html.erb", "foo"
|
41
|
+
visit admin.new_article_path
|
42
|
+
assert page.has_content? "foo"
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_override_partial_and_resource_partial_in_engine
|
46
|
+
add_template "admin/app/views/admin/articles/_form.html.erb", "foo"
|
47
|
+
add_template "admin/app/views/admin/resource/_form.html.erb", "bar"
|
48
|
+
visit admin.new_article_path
|
49
|
+
assert page.has_content? "foo"
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TemplateOverridingTest < ActionDispatch::IntegrationTest
|
4
|
+
def test_default_template
|
5
|
+
visit articles_path
|
6
|
+
assert page.has_content? "Create Article"
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_override_template
|
10
|
+
add_template "app/views/articles/index.html.erb", "foo"
|
11
|
+
visit articles_path
|
12
|
+
assert page.has_content? "foo"
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_override_resource_template
|
16
|
+
add_template "app/views/resource/index.html.erb", "foo"
|
17
|
+
visit articles_path
|
18
|
+
assert page.has_content? "foo"
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_override_template_and_resource_template
|
22
|
+
add_template "app/views/articles/index.html.erb", "foo"
|
23
|
+
add_template "app/views/resource/index.html.erb", "bar"
|
24
|
+
visit articles_path
|
25
|
+
assert page.has_content? "foo"
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_default_template_in_engine
|
29
|
+
visit admin.articles_path
|
30
|
+
assert page.has_content? "Create Article"
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_override_template_in_engine
|
34
|
+
add_template "admin/app/views/admin/articles/index.html.erb", "foo"
|
35
|
+
visit admin.articles_path
|
36
|
+
assert page.has_content? "foo"
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_override_resource_template_in_engine
|
40
|
+
add_template "admin/app/views/admin/resource/index.html.erb", "foo"
|
41
|
+
visit admin.articles_path
|
42
|
+
assert page.has_content? "foo"
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_override_template_and_resource_template_in_engine
|
46
|
+
add_template "admin/app/views/admin/articles/index.html.erb", "foo"
|
47
|
+
add_template "admin/app/views/admin/resource/index.html.erb", "bar"
|
48
|
+
visit admin.articles_path
|
49
|
+
assert page.has_content? "foo"
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Godmin
|
4
|
+
class EngineWrapperTest < ActiveSupport::TestCase
|
5
|
+
module Admin
|
6
|
+
class Engine < Rails::Engine
|
7
|
+
isolate_namespace Admin
|
8
|
+
end
|
9
|
+
|
10
|
+
class Controller < ActionController::Base; end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Controller < ActionController::Base; end
|
14
|
+
|
15
|
+
def test_default_namespace
|
16
|
+
engine_wrapper = EngineWrapper.new(Controller)
|
17
|
+
assert_equal nil, engine_wrapper.namespace
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_default_namespaced?
|
21
|
+
engine_wrapper = EngineWrapper.new(Controller)
|
22
|
+
assert_equal false, engine_wrapper.namespaced?
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_default_namespaced_path
|
26
|
+
engine_wrapper = EngineWrapper.new(Controller)
|
27
|
+
assert_equal [], engine_wrapper.namespaced_path
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_default_root
|
31
|
+
engine_wrapper = EngineWrapper.new(Controller)
|
32
|
+
assert_equal Rails.application.root, engine_wrapper.root
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_engine_namespace
|
36
|
+
engine_wrapper = EngineWrapper.new(Admin::Controller)
|
37
|
+
assert_equal Admin, engine_wrapper.namespace
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_engine_namespaced?
|
41
|
+
engine_wrapper = EngineWrapper.new(Admin::Controller)
|
42
|
+
assert_equal true, engine_wrapper.namespaced?
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_engine_namespaced_path
|
46
|
+
engine_wrapper = EngineWrapper.new(Admin::Controller)
|
47
|
+
assert_equal ["godmin", "engine_wrapper_test", "admin"], engine_wrapper.namespaced_path
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_engine_root
|
51
|
+
engine_wrapper = EngineWrapper.new(Admin::Controller)
|
52
|
+
assert_equal Admin::Engine.root, engine_wrapper.root
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,58 +1,54 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
|
-
module Namespace
|
4
|
-
class ArticlePolicyTestPolicy; end
|
5
|
-
class ObjectPolicy; end
|
6
|
-
end
|
7
|
-
|
8
|
-
class ArticlePolicyTest; extend ActiveModel::Naming; end
|
9
|
-
class OverriddenPolicyTest
|
10
|
-
extend ActiveModel::Naming
|
11
|
-
def self.policy_class
|
12
|
-
Namespace::ObjectPolicy
|
13
|
-
end
|
14
|
-
|
15
|
-
def policy_class
|
16
|
-
Namespace::ObjectPolicy
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
3
|
module Godmin
|
21
4
|
module Authorization
|
22
5
|
class PolicyFinderTest < ActiveSupport::TestCase
|
6
|
+
class Article; end
|
7
|
+
class ArticlePolicy; end
|
8
|
+
|
23
9
|
def test_find_by_model
|
24
|
-
|
25
|
-
|
26
|
-
|
10
|
+
klass = Class.new do
|
11
|
+
extend ActiveModel::Naming
|
12
|
+
|
13
|
+
def self.name
|
14
|
+
"Article"
|
15
|
+
end
|
27
16
|
end
|
17
|
+
|
18
|
+
policy = PolicyFinder.find(klass, Godmin::Authorization::PolicyFinderTest)
|
19
|
+
assert_equal ArticlePolicy, policy
|
28
20
|
end
|
29
21
|
|
30
22
|
def test_find_by_class
|
31
|
-
|
32
|
-
|
33
|
-
assert_equal Namespace::ObjectPolicy, policy
|
34
|
-
end
|
23
|
+
policy = PolicyFinder.find(Article)
|
24
|
+
assert_equal ArticlePolicy, policy
|
35
25
|
end
|
36
26
|
|
37
27
|
def test_find_by_symbol
|
38
|
-
|
39
|
-
|
40
|
-
assert_equal Namespace::ArticlePolicyTestPolicy, policy
|
41
|
-
end
|
28
|
+
policy = PolicyFinder.find(:article, Godmin::Authorization::PolicyFinderTest)
|
29
|
+
assert_equal ArticlePolicy, policy
|
42
30
|
end
|
43
31
|
|
44
32
|
def test_override_policy_class_on_class
|
45
|
-
|
46
|
-
|
47
|
-
|
33
|
+
klass = Class.new do
|
34
|
+
def self.policy_class
|
35
|
+
ArticlePolicy
|
36
|
+
end
|
48
37
|
end
|
38
|
+
|
39
|
+
policy = PolicyFinder.find(klass)
|
40
|
+
assert_equal ArticlePolicy, policy
|
49
41
|
end
|
50
42
|
|
51
43
|
def test_override_policy_class_on_instance
|
52
|
-
|
53
|
-
|
54
|
-
|
44
|
+
klass = Class.new do
|
45
|
+
def policy_class
|
46
|
+
ArticlePolicy
|
47
|
+
end
|
55
48
|
end
|
49
|
+
|
50
|
+
policy = PolicyFinder.find(klass.new)
|
51
|
+
assert_equal ArticlePolicy, policy
|
56
52
|
end
|
57
53
|
end
|
58
54
|
end
|
@@ -2,49 +2,39 @@ require "test_helper"
|
|
2
2
|
|
3
3
|
module Godmin
|
4
4
|
class ResolverTest < ActiveSupport::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
"namespace/controller_name/prefix",
|
9
|
-
"namespace/controller_name",
|
10
|
-
"namespace/prefix",
|
11
|
-
"namespace/resource/prefix",
|
12
|
-
"namespace/resource",
|
13
|
-
"namespace"
|
14
|
-
], EngineResolver.new("controller_name").template_paths("prefix", false)
|
5
|
+
module Admin
|
6
|
+
class Engine < Rails::Engine
|
7
|
+
isolate_namespace Admin
|
15
8
|
end
|
9
|
+
|
10
|
+
class Controller < ActionController::Base; end
|
16
11
|
end
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
"namespace/prefix",
|
24
|
-
"namespace/resource/prefix",
|
25
|
-
"namespace/resource",
|
26
|
-
"namespace"
|
27
|
-
], EngineResolver.new("controller_name").template_paths("namespace/prefix", false)
|
28
|
-
end
|
13
|
+
class Controller < ActionController::Base; end
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@engine_wrapper_1 = EngineWrapper.new(Controller)
|
17
|
+
@engine_wrapper_2 = EngineWrapper.new(Admin::Controller)
|
29
18
|
end
|
30
19
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
20
|
+
def test_godmin_resolver_when_not_namespaced
|
21
|
+
resolver = Resolver.new("articles", @engine_wrapper_1)
|
22
|
+
|
23
|
+
assert_equal [
|
24
|
+
File.join(@engine_wrapper_1.root, "app/views/resource"),
|
25
|
+
File.join(Godmin::Engine.root, "app/views/godmin/resource"),
|
26
|
+
File.join(Godmin::Engine.root, "app/views/godmin/articles")
|
27
|
+
], resolver.template_paths("articles")
|
35
28
|
end
|
36
29
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
"godmin"
|
46
|
-
], GodminResolver.new("controller_name").template_paths("prefix", false)
|
47
|
-
end
|
30
|
+
def test_godmin_resolver_when_namespaced
|
31
|
+
resolver = Resolver.new("godmin/resolver_test/admin/articles", @engine_wrapper_2)
|
32
|
+
|
33
|
+
assert_equal [
|
34
|
+
File.join(@engine_wrapper_2.root, "app/views/godmin/resolver_test/admin/resource"),
|
35
|
+
File.join(Godmin::Engine.root, "app/views/godmin/resource"),
|
36
|
+
File.join(Godmin::Engine.root, "app/views/godmin/articles")
|
37
|
+
], resolver.template_paths("godmin/resolver_test/admin/articles")
|
48
38
|
end
|
49
39
|
end
|
50
40
|
end
|
@@ -3,17 +3,17 @@ require "test_helper"
|
|
3
3
|
module Godmin
|
4
4
|
module ResourceService
|
5
5
|
class ScopesTest < ActiveSupport::TestCase
|
6
|
-
class NoScopesService
|
7
|
-
include Godmin::Resources::ResourceService
|
8
|
-
end
|
9
|
-
|
10
6
|
def setup
|
11
|
-
@article_service = ArticleService.new
|
7
|
+
@article_service = Fakes::ArticleService.new
|
12
8
|
end
|
13
9
|
|
14
10
|
def test_returns_resources_when_no_scopes_are_defined
|
15
|
-
|
16
|
-
|
11
|
+
service_class = Class.new do
|
12
|
+
include Godmin::Resources::ResourceService
|
13
|
+
end
|
14
|
+
|
15
|
+
service = service_class.new
|
16
|
+
assert_equal :resources, service.apply_scope("", :resources)
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_calls_default_scope
|
@@ -3,11 +3,11 @@ require "test_helper"
|
|
3
3
|
module Godmin
|
4
4
|
class ResourceServiceTest < ActiveSupport::TestCase
|
5
5
|
def setup
|
6
|
-
@article_service = ArticleService.new
|
6
|
+
@article_service = Fakes::ArticleService.new
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_resource_class
|
10
|
-
assert_equal Article, @article_service.resource_class
|
10
|
+
assert_equal Fakes::Article, @article_service.resource_class
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_attrs_for_index
|