godmin 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,3 +1,3 @@
1
1
  module Godmin
2
- VERSION = "0.12.0"
2
+ VERSION = "0.12.1"
3
3
  end
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Admin'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -0,0 +1,15 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "admin/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "admin"
9
+ s.version = Admin::VERSION
10
+ s.authors = ["admin"]
11
+ s.email = ["admin@example.com"]
12
+ s.summary = "admin"
13
+
14
+ s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
15
+ end
@@ -0,0 +1,14 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require godmin
14
+ //= require_tree .
@@ -0,0 +1,16 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require godmin
14
+ *= require_tree .
15
+ *= require_self
16
+ */
@@ -0,0 +1,5 @@
1
+ module Admin
2
+ class ApplicationController < ActionController::Base
3
+ include Godmin::ApplicationController
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require_dependency "admin/application_controller"
2
+
3
+ module Admin
4
+ class ArticlesController < ApplicationController
5
+ include Godmin::Resources::ResourceController
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ module Admin
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,11 @@
1
+ module Admin
2
+ class ArticleService
3
+ include Godmin::Resources::ResourceService
4
+
5
+ attrs_for_index :id, :title, :published
6
+ attrs_for_show :id, :title, :body, :published
7
+ attrs_for_form :title, :body, :published
8
+
9
+ filter :title
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ <%= navbar_item Article %>
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/admin/engine', __FILE__)
6
+
7
+ # Set up gems listed in the Gemfile.
8
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
9
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
10
+
11
+ require 'rails/all'
12
+ require 'rails/engine/commands'
@@ -0,0 +1,4 @@
1
+ Admin::Engine.routes.draw do
2
+ resources :articles
3
+ root to: "application#welcome"
4
+ end
@@ -0,0 +1,4 @@
1
+ require "admin/engine"
2
+
3
+ module Admin
4
+ end
@@ -0,0 +1,5 @@
1
+ module Admin
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Admin
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Admin
2
+ VERSION = "0.0.1"
3
+ end
@@ -10,4 +10,5 @@
10
10
  // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
+ //= require godmin
13
14
  //= require_tree .
@@ -8,6 +8,7 @@
8
8
  * You're free to add application-wide styles to this file and they'll appear at the top of the
9
9
  * compiled file, but it's generally better to create a new file per style scope.
10
10
  *
11
- *= require_self
11
+ *= require godmin
12
12
  *= require_tree .
13
+ *= require_self
13
14
  */
@@ -2,4 +2,6 @@ class ApplicationController < ActionController::Base
2
2
  # Prevent CSRF attacks by raising an exception.
3
3
  # For APIs, you may want to use :null_session instead.
4
4
  protect_from_forgery with: :exception
5
+
6
+ include Godmin::ApplicationController
5
7
  end
@@ -0,0 +1,3 @@
1
+ class ArticlesController < ApplicationController
2
+ include Godmin::Resources::ResourceController
3
+ end
@@ -0,0 +1,2 @@
1
+ class Article < ActiveRecord::Base
2
+ end
@@ -0,0 +1,9 @@
1
+ class ArticleService
2
+ include Godmin::Resources::ResourceService
3
+
4
+ attrs_for_index :id, :title, :published, :created_at
5
+ attrs_for_show :id, :title, :body, :published
6
+ attrs_for_form :title, :body, :published
7
+
8
+ filter :title
9
+ end
File without changes
File without changes
@@ -0,0 +1 @@
1
+ <%= navbar_item Article %>
@@ -17,9 +17,3 @@ test:
17
17
  database: db/test.sqlite3
18
18
  pool: 5
19
19
  timeout: 5000
20
-
21
- production:
22
- adapter: sqlite3
23
- database: db/production.sqlite3
24
- pool: 5
25
- timeout: 5000
@@ -36,4 +36,8 @@ Dummy::Application.configure do
36
36
 
37
37
  # Print deprecation notices to the stderr.
38
38
  config.active_support.deprecation = :stderr
39
+
40
+ # Disable caching of templates so that our template override
41
+ # tests work properly.
42
+ config.action_view.cache_template_loading = false
39
43
  end
@@ -1,4 +1,5 @@
1
1
  Rails.application.routes.draw do
2
-
3
- mount Godmin::Engine => "/godmin"
2
+ resources :articles
3
+ root to: "application#welcome"
4
+ mount Admin::Engine, at: "admin"
4
5
  end
@@ -0,0 +1,11 @@
1
+ class CreateArticles < ActiveRecord::Migration
2
+ def change
3
+ create_table :articles do |t|
4
+ t.string :title
5
+ t.text :body
6
+ t.boolean :published
7
+
8
+ t.timestamps null: false
9
+ end
10
+ end
11
+ end
@@ -11,6 +11,14 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 0) do
14
+ ActiveRecord::Schema.define(version: 20150717121532) do
15
+
16
+ create_table "articles", force: :cascade do |t|
17
+ t.string "title"
18
+ t.text "body"
19
+ t.boolean "published"
20
+ t.datetime "created_at", null: false
21
+ t.datetime "updated_at", null: false
22
+ end
15
23
 
16
24
  end
@@ -0,0 +1,4 @@
1
+ module Fakes
2
+ class Article
3
+ end
4
+ end
@@ -0,0 +1,68 @@
1
+ module Fakes
2
+ class ArticleService
3
+ include Godmin::Resources::ResourceService
4
+
5
+ attr_accessor :called_methods
6
+
7
+ attrs_for_index :id, :title, :country
8
+ attrs_for_show :title, :country
9
+ attrs_for_form :id, :title, :country, :body
10
+ attrs_for_export :id, :title
11
+
12
+ scope :unpublished, default: true
13
+ scope :published
14
+
15
+ filter :title
16
+ filter :country, as: :select, collection: %w(Sweden Canada)
17
+ filter :tags, as: :multiselect, collection: %w(Apple Banana)
18
+
19
+ batch_action :unpublish
20
+ batch_action :publish, confirm: true, only: :unpublished, except: :published
21
+
22
+ def initialize(*)
23
+ super
24
+ @called_methods = { scopes: {}, filters: {}, batch_actions: {} }
25
+ end
26
+
27
+ def resource_class
28
+ Fakes::Article
29
+ end
30
+
31
+ def resources_relation
32
+ [:foo, :bar, :baz]
33
+ end
34
+
35
+ def scope_unpublished(resources)
36
+ called_methods[:scopes][:unpublished] = resources
37
+ resources.slice(1, 3)
38
+ end
39
+
40
+ def scope_published(resources)
41
+ called_methods[:scopes][:published] = resources
42
+ resources.slice(0, 1)
43
+ end
44
+
45
+ def filter_title(resources, value)
46
+ called_methods[:filters][:title] = [resources, value]
47
+ resources
48
+ end
49
+
50
+ def filter_country(resources, value)
51
+ called_methods[:filters][:country] = [resources, value]
52
+ resources
53
+ end
54
+
55
+ def filter_tags(resources, value)
56
+ called_methods[:filters][:tags] = [resources, value]
57
+ resources
58
+ end
59
+
60
+ def batch_action_unpublish(resources)
61
+ called_methods[:batch_actions][:unpublish] = resources
62
+ end
63
+
64
+ def batch_action_publish(resources)
65
+ called_methods[:batch_actions][:publish] = resources
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,23 @@
1
+ require "test_helper"
2
+
3
+ class ColumnOrderingTest < ActionDispatch::IntegrationTest
4
+ def test_default_order_links
5
+ visit articles_path
6
+ link = find("#table th.column-created_at a")
7
+ assert_equal "/articles?order=created_at_desc", link[:href]
8
+ end
9
+
10
+ def test_order_flipped
11
+ visit articles_path
12
+ link_matcher = "#table th.column-created_at a"
13
+ find(link_matcher).click
14
+ link = find(link_matcher)
15
+ assert_equal "/articles?order=created_at_asc", link[:href]
16
+ end
17
+
18
+ def test_order_links_when_order_empty
19
+ visit articles_path(order: "")
20
+ link = find("#table th.column-created_at a")
21
+ assert_equal "/articles?order=created_at_desc", link[:href]
22
+ end
23
+ end
@@ -0,0 +1,59 @@
1
+ require "test_helper"
2
+
3
+ class ColumnOverridingTest < ActionDispatch::IntegrationTest
4
+ def test_default_column
5
+ Article.create! title: "foo"
6
+ visit articles_path
7
+ assert find("#table").has_content? "foo"
8
+ end
9
+
10
+ def test_override_column
11
+ Article.create! title: "foo"
12
+ add_template "app/views/articles/columns/_title.html.erb", "bar"
13
+ visit articles_path
14
+ assert find("#table").has_content? "bar"
15
+ end
16
+
17
+ def test_override_resource_column
18
+ Article.create! title: "foo"
19
+ add_template "app/views/resource/columns/_title.html.erb", "bar"
20
+ visit articles_path
21
+ assert find("#table").has_content? "bar"
22
+ end
23
+
24
+ def test_override_column_and_resource_column
25
+ Article.create! title: "foo"
26
+ add_template "app/views/articles/columns/_title.html.erb", "bar"
27
+ add_template "app/views/resource/columns/_title.html.erb", "baz"
28
+ visit articles_path
29
+ assert find("#table").has_content? "bar"
30
+ end
31
+
32
+ def test_default_column_in_engine
33
+ Article.create! title: "foo"
34
+ visit admin.articles_path
35
+ assert find("#table").has_content? "foo"
36
+ end
37
+
38
+ def test_override_column_in_engine
39
+ Article.create! title: "foo"
40
+ add_template "admin/app/views/admin/articles/columns/_title.html.erb", "bar"
41
+ visit admin.articles_path
42
+ assert find("#table").has_content? "bar"
43
+ end
44
+
45
+ def test_override_resource_column_in_engine
46
+ Article.create! title: "foo"
47
+ add_template "admin/app/views/admin/resource/columns/_title.html.erb", "bar"
48
+ visit admin.articles_path
49
+ assert find("#table").has_content? "bar"
50
+ end
51
+
52
+ def test_override_column_and_resource_column_in_engine
53
+ Article.create! title: "foo"
54
+ add_template "admin/app/views/admin/articles/columns/_title.html.erb", "bar"
55
+ add_template "admin/app/views/admin/resource/columns/_title.html.erb", "baz"
56
+ visit admin.articles_path
57
+ assert find("#table").has_content? "bar"
58
+ end
59
+ end