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.
- 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
data/lib/godmin/version.rb
CHANGED
@@ -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
|
+
*/
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -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'
|
@@ -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
|
-
*=
|
11
|
+
*= require godmin
|
12
12
|
*= require_tree .
|
13
|
+
*= require_self
|
13
14
|
*/
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= navbar_item Article %>
|
@@ -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
|
data/test/dummy/config/routes.rb
CHANGED
data/test/dummy/db/schema.rb
CHANGED
@@ -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:
|
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,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
|