godmin 1.5.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.travis.yml +8 -5
  4. data/Appraisals +4 -4
  5. data/CHANGELOG.md +51 -2
  6. data/Gemfile +1 -1
  7. data/README.md +38 -5
  8. data/Rakefile +2 -2
  9. data/gemfiles/rails_5.gemfile +2 -2
  10. data/gemfiles/rails_6.gemfile +8 -0
  11. data/godmin.gemspec +18 -15
  12. data/lib/generators/godmin/resource/resource_generator.rb +7 -1
  13. data/lib/generators/godmin/resource/templates/resource_model.rb +4 -0
  14. data/lib/godmin/application_controller.rb +10 -11
  15. data/lib/godmin/authentication.rb +11 -11
  16. data/lib/godmin/authentication/sessions_controller.rb +1 -0
  17. data/lib/godmin/authorization.rb +6 -20
  18. data/lib/godmin/engine_wrapper.rb +10 -1
  19. data/lib/godmin/generators/base.rb +4 -4
  20. data/lib/godmin/generators/named_base.rb +4 -4
  21. data/lib/godmin/helpers/application.rb +3 -3
  22. data/lib/godmin/resolver.rb +20 -5
  23. data/lib/godmin/resources/resource_controller/batch_actions.rb +1 -1
  24. data/lib/godmin/resources/resource_service.rb +1 -5
  25. data/lib/godmin/version.rb +1 -1
  26. data/template.rb +3 -3
  27. data/test/dummy/admin/app/controllers/admin/authorized_articles_controller.rb +15 -0
  28. data/test/dummy/admin/app/models/admin/article.rb +4 -0
  29. data/test/dummy/admin/app/policies/admin/article_policy.rb +7 -0
  30. data/test/dummy/admin/config/routes.rb +1 -0
  31. data/test/dummy/app/assets/config/manifest.js +4 -0
  32. data/test/dummy/app/controllers/another_admin_sessions_controller.rb +0 -2
  33. data/test/dummy/db/migrate/20150717121532_create_articles.rb +1 -1
  34. data/test/dummy/db/migrate/20150907133753_create_admin_users.rb +1 -1
  35. data/test/dummy/db/migrate/20160713134238_create_comment.rb +1 -1
  36. data/test/dummy/db/schema.rb +17 -16
  37. data/test/fakes/article.rb +1 -1
  38. data/test/fakes/article_service.rb +3 -7
  39. data/test/generators/resource_generator_test.rb +77 -0
  40. data/test/integration/authentication_test.rb +3 -8
  41. data/test/integration/authorization_test.rb +5 -0
  42. data/test/{lib/godmin → unit}/engine_wrapper_test.rb +0 -0
  43. data/test/{lib/godmin → unit}/helpers/filters_test.rb +0 -0
  44. data/test/{lib/godmin → unit}/paginator_test.rb +0 -0
  45. data/test/{lib/godmin → unit}/resolver_test.rb +0 -0
  46. data/test/{lib/godmin → unit}/resources/resource_service/batch_actions_test.rb +0 -0
  47. data/test/{lib/godmin → unit}/resources/resource_service/filters_test.rb +0 -0
  48. data/test/{lib/godmin → unit}/resources/resource_service/ordering_test.rb +0 -0
  49. data/test/{lib/godmin → unit}/resources/resource_service/pagination_test.rb +0 -0
  50. data/test/{lib/godmin → unit}/resources/resource_service/scopes_test.rb +0 -0
  51. data/test/{lib/godmin → unit}/resources/resource_service_test.rb +0 -0
  52. metadata +139 -85
  53. data/gemfiles/rails_4.gemfile +0 -8
  54. data/lib/godmin/authorization/policy_finder.rb +0 -31
  55. data/lib/tasks/godmin_tasks.rake +0 -4
  56. data/test/lib/godmin/policy_finder_test.rb +0 -55
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "admin", :path => "../test/dummy/admin", :group => [:test, :development]
6
- gem "rails", "4.2.0"
7
-
8
- gemspec :path => "../"
@@ -1,31 +0,0 @@
1
- module Godmin
2
- module Authorization
3
- class PolicyFinder
4
- class << self
5
- def find(object, namespace = nil)
6
- return object.policy_class if object.respond_to?(:policy_class)
7
- return object.class.policy_class if object.class.respond_to?(:policy_class)
8
-
9
- klass =
10
- if object.respond_to?(:model_name)
11
- object.model_name
12
- elsif object.class.respond_to?(:model_name)
13
- object.class.model_name
14
- elsif object.is_a?(Class)
15
- object
16
- elsif object.is_a?(Symbol)
17
- object.to_s.classify
18
- else
19
- object.class
20
- end
21
-
22
- if namespace
23
- "#{namespace}::#{klass}Policy"
24
- else
25
- "#{klass}Policy"
26
- end.constantize
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :godmin do
3
- # # Task goes here
4
- # end
@@ -1,55 +0,0 @@
1
- require "test_helper"
2
-
3
- module Godmin
4
- module Authorization
5
- class PolicyFinderTest < ActiveSupport::TestCase
6
- class Article; end
7
- class ArticlePolicy; end
8
-
9
- def test_find_by_model
10
- klass = Class.new do
11
- extend ActiveModel::Naming
12
-
13
- def self.name
14
- "Article"
15
- end
16
- end
17
-
18
- policy = PolicyFinder.find(klass, Godmin::Authorization::PolicyFinderTest)
19
- assert_equal ArticlePolicy, policy
20
- end
21
-
22
- def test_find_by_class
23
- policy = PolicyFinder.find(Article)
24
- assert_equal ArticlePolicy, policy
25
- end
26
-
27
- def test_find_by_symbol
28
- policy = PolicyFinder.find(:article, Godmin::Authorization::PolicyFinderTest)
29
- assert_equal ArticlePolicy, policy
30
- end
31
-
32
- def test_override_policy_class_on_class
33
- klass = Class.new do
34
- def self.policy_class
35
- ArticlePolicy
36
- end
37
- end
38
-
39
- policy = PolicyFinder.find(klass)
40
- assert_equal ArticlePolicy, policy
41
- end
42
-
43
- def test_override_policy_class_on_instance
44
- klass = Class.new do
45
- def policy_class
46
- ArticlePolicy
47
- end
48
- end
49
-
50
- policy = PolicyFinder.find(klass.new)
51
- assert_equal ArticlePolicy, policy
52
- end
53
- end
54
- end
55
- end