godmin 0.12.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +6 -0
  4. data/CHANGELOG.md +11 -0
  5. data/Gemfile +5 -0
  6. data/README.md +5 -11
  7. data/app/views/godmin/application/welcome.html.erb +4 -52
  8. data/app/views/godmin/resource/_filters.html.erb +1 -1
  9. data/app/views/godmin/resource/_table.html.erb +2 -2
  10. data/app/views/layouts/godmin/_layout.html.erb +2 -2
  11. data/app/views/layouts/godmin/application.html.erb +2 -2
  12. data/godmin.gemspec +4 -1
  13. data/lib/generators/godmin/install/install_generator.rb +0 -10
  14. data/lib/godmin.rb +3 -6
  15. data/lib/godmin/application_controller.rb +8 -4
  16. data/lib/godmin/authorization.rb +1 -1
  17. data/lib/godmin/authorization/policy_finder.rb +4 -3
  18. data/lib/godmin/engine_wrapper.rb +49 -0
  19. data/lib/godmin/helpers/tables.rb +6 -6
  20. data/lib/godmin/resolver.rb +32 -36
  21. data/lib/godmin/version.rb +1 -1
  22. data/test/dummy/admin/Rakefile +24 -0
  23. data/test/dummy/admin/admin.gemspec +15 -0
  24. data/test/dummy/admin/app/assets/javascripts/admin/application.js +14 -0
  25. data/test/dummy/admin/app/assets/stylesheets/admin/application.css +16 -0
  26. data/test/dummy/admin/app/controllers/admin/application_controller.rb +5 -0
  27. data/test/dummy/admin/app/controllers/admin/articles_controller.rb +7 -0
  28. data/test/dummy/admin/app/helpers/admin/application_helper.rb +4 -0
  29. data/test/dummy/admin/app/services/admin/article_service.rb +11 -0
  30. data/test/dummy/{app/assets/images → admin/app/views/admin/articles}/.keep +0 -0
  31. data/test/dummy/{app/mailers → admin/app/views/admin/articles/columns}/.keep +0 -0
  32. data/test/dummy/admin/app/views/admin/articles/filters/.keep +0 -0
  33. data/test/dummy/admin/app/views/admin/resource/.keep +0 -0
  34. data/test/dummy/admin/app/views/admin/resource/columns/.keep +0 -0
  35. data/test/dummy/admin/app/views/admin/resource/filters/.keep +0 -0
  36. data/test/dummy/admin/app/views/admin/shared/_navigation.html.erb +1 -0
  37. data/test/dummy/admin/bin/rails +12 -0
  38. data/test/dummy/admin/config/routes.rb +4 -0
  39. data/test/dummy/admin/lib/admin.rb +4 -0
  40. data/test/dummy/admin/lib/admin/engine.rb +5 -0
  41. data/test/dummy/admin/lib/admin/version.rb +3 -0
  42. data/test/dummy/app/assets/javascripts/application.js +1 -0
  43. data/test/dummy/app/assets/stylesheets/application.css +2 -1
  44. data/test/dummy/app/controllers/application_controller.rb +2 -0
  45. data/test/dummy/app/controllers/articles_controller.rb +3 -0
  46. data/test/dummy/app/models/article.rb +2 -0
  47. data/test/dummy/app/services/article_service.rb +9 -0
  48. data/test/dummy/app/views/articles/.keep +0 -0
  49. data/test/dummy/app/views/articles/columns/.keep +0 -0
  50. data/test/dummy/app/views/articles/filters/.keep +0 -0
  51. data/test/dummy/app/views/resource/.keep +0 -0
  52. data/test/dummy/app/views/resource/columns/.keep +0 -0
  53. data/test/dummy/app/views/resource/filters/.keep +0 -0
  54. data/test/dummy/app/views/shared/_navigation.html.erb +1 -0
  55. data/test/dummy/config/database.yml +0 -6
  56. data/test/dummy/config/environments/test.rb +4 -0
  57. data/test/dummy/config/routes.rb +3 -2
  58. data/test/dummy/db/migrate/20150717121532_create_articles.rb +11 -0
  59. data/test/dummy/db/schema.rb +9 -1
  60. data/test/fakes/article.rb +4 -0
  61. data/test/fakes/article_service.rb +68 -0
  62. data/test/integration/column_ordering_test.rb +23 -0
  63. data/test/integration/column_overriding_test.rb +59 -0
  64. data/test/integration/filter_overriding_test.rb +51 -0
  65. data/test/integration/partial_overriding_test.rb +51 -0
  66. data/test/integration/template_overriding_test.rb +51 -0
  67. data/test/integration/welcome_test.rb +8 -0
  68. data/test/lib/godmin/engine_wrapper_test.rb +55 -0
  69. data/test/lib/godmin/policy_finder_test.rb +30 -34
  70. data/test/lib/godmin/resolver_test.rb +26 -36
  71. data/test/lib/godmin/resources/resource_service/batch_actions_test.rb +1 -1
  72. data/test/lib/godmin/resources/resource_service/filters_test.rb +1 -1
  73. data/test/lib/godmin/resources/resource_service/pagination_test.rb +1 -1
  74. data/test/lib/godmin/resources/resource_service/scopes_test.rb +7 -7
  75. data/test/lib/godmin/resources/resource_service_test.rb +2 -2
  76. data/test/test_helper.rb +23 -66
  77. metadata +127 -20
  78. data/test/dummy/README.rdoc +0 -28
  79. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  80. data/test/dummy/config/environments/production.rb +0 -80
  81. data/test/dummy/config/locales/en.yml +0 -23
  82. data/test/godmin_test.rb +0 -7
  83. 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,8 @@
1
+ require "test_helper"
2
+
3
+ class WelcomeTest < ActionDispatch::IntegrationTest
4
+ def test_welcome
5
+ visit "/"
6
+ assert page.has_content? "Welcome"
7
+ end
8
+ 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
- namespaced_as "namespace" do
25
- policy = PolicyFinder.find(ArticlePolicyTest)
26
- assert_equal Namespace::ArticlePolicyTestPolicy, policy
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
- namespaced_as "namespace" do
32
- policy = PolicyFinder.find(Object)
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
- namespaced_as "namespace" do
39
- policy = PolicyFinder.find(:article_policy_test)
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
- namespaced_as "namespace" do
46
- policy = PolicyFinder.find(OverriddenPolicyTest)
47
- assert_equal Namespace::ObjectPolicy, policy
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
- namespaced_as "namespace" do
53
- policy = PolicyFinder.find(OverriddenPolicyTest.new)
54
- assert_equal Namespace::ObjectPolicy, policy
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
- def test_engine_resolver_template_paths
6
- namespaced_as "namespace" do
7
- assert_equal [
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
- def test_engine_resolver_template_paths_when_namespace_is_in_prefix
19
- namespaced_as "namespace" do
20
- assert_equal [
21
- "namespace/controller_name/prefix",
22
- "namespace/controller_name",
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 test_engine_resolver_template_paths_when_prefix_contains_godmin
32
- namespaced_as "namespace" do
33
- assert_equal [], EngineResolver.new("controller_name").template_paths("godmin/namespace/prefix", false)
34
- end
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 test_godmin_resolver_template_paths
38
- namespaced_as "namespace" do
39
- assert_equal [
40
- "godmin/controller_name/prefix",
41
- "godmin/controller_name",
42
- "godmin/prefix",
43
- "godmin/resource/prefix",
44
- "godmin/resource",
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
@@ -4,7 +4,7 @@ module Godmin
4
4
  module ResourceService
5
5
  class BatchActionsTest < ActiveSupport::TestCase
6
6
  def setup
7
- @article_service = ArticleService.new
7
+ @article_service = Fakes::ArticleService.new
8
8
  end
9
9
 
10
10
  def test_batch_action
@@ -4,7 +4,7 @@ module Godmin
4
4
  module ResourceService
5
5
  class FiltersTest < ActiveSupport::TestCase
6
6
  def setup
7
- @article_service = ArticleService.new
7
+ @article_service = Fakes::ArticleService.new
8
8
  end
9
9
 
10
10
  def test_calls_one_filter
@@ -4,7 +4,7 @@ module Godmin
4
4
  module ResourceService
5
5
  class PaginationTest < ActiveSupport::TestCase
6
6
  def setup
7
- @article_service = ArticleService.new
7
+ @article_service = Fakes::ArticleService.new
8
8
 
9
9
  resources_class = Class.new do
10
10
  def limit(_limit_param)
@@ -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
- @foo_thing = NoScopesService.new
16
- assert_equal :resources, @foo_thing.apply_scope("", :resources)
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