godmin 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +1 -1
  3. data/CHANGELOG.md +4 -0
  4. data/Gemfile +0 -1
  5. data/README.md +27 -3
  6. data/app/views/godmin/resource/_breadcrumb.html.erb +12 -24
  7. data/app/views/godmin/resource/_breadcrumb_actions.html.erb +41 -0
  8. data/app/views/godmin/resource/_button_actions.html.erb +1 -1
  9. data/app/views/godmin/resource/columns/_actions.html.erb +3 -3
  10. data/app/views/godmin/resource/show.html.erb +1 -1
  11. data/config/locales/en.yml +2 -0
  12. data/config/locales/pt-BR.yml +2 -0
  13. data/config/locales/sv.yml +2 -0
  14. data/gemfiles/rails_4.gemfile +1 -2
  15. data/gemfiles/rails_5.gemfile +0 -1
  16. data/godmin.gemspec +8 -9
  17. data/lib/godmin/helpers/batch_actions.rb +1 -1
  18. data/lib/godmin/helpers/forms.rb +5 -1
  19. data/lib/godmin/resources/resource_controller.rb +24 -5
  20. data/lib/godmin/resources/resource_service.rb +7 -2
  21. data/lib/godmin/resources/resource_service/associations.rb +23 -0
  22. data/lib/godmin/version.rb +1 -1
  23. data/test/dummy/app/controllers/comments_controller.rb +3 -0
  24. data/test/dummy/app/models/article.rb +1 -0
  25. data/test/dummy/app/models/comment.rb +7 -0
  26. data/test/dummy/app/services/article_service.rb +2 -0
  27. data/test/dummy/app/services/comment_service.rb +7 -0
  28. data/test/dummy/bin/rails +1 -1
  29. data/test/dummy/config/application.rb +2 -14
  30. data/test/dummy/config/locales/en.yml +9 -0
  31. data/test/dummy/config/routes.rb +3 -1
  32. data/test/dummy/db/migrate/20160713134238_create_comment.rb +9 -0
  33. data/test/dummy/db/schema.rb +7 -0
  34. data/test/integration/authentication_test.rb +7 -1
  35. data/test/integration/nested_resources_test.rb +47 -0
  36. data/test/test_helper.rb +1 -7
  37. metadata +32 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec0d4e9f977de0473f9c482b30fe336208e58adb
4
- data.tar.gz: f266d7bfba24bdc6947934bf1df1a970dbfe433b
3
+ metadata.gz: 0a7bcd5f755d209ec853fc0ce1464aa52041367b
4
+ data.tar.gz: 63b8a83f08ef476be9e328d361776a327f4077e5
5
5
  SHA512:
6
- metadata.gz: 3fe30fb7f586871bea01de9696db6a9f40c5b6ce516388844f0de96a04c8f51a05444b7c178ea0176ff38bac6c9d260614be81a952f31b144f67b46496f6550a
7
- data.tar.gz: 9581339c532af064381e0a56bae194919d9cfe8b52ba65e642ee309e3e7413c291eede9c2dcc0465050d967b99416bc79cc0243e2391ff0ac0fa256be746683e
6
+ metadata.gz: f9dd7fec83fba49b6dddb6378c77a82c94c6d0ecd5e5b1ada53e9456207cbd5156380c446226deeeb14435dce61cb4bdfa6f65a8666c7dcd0d965ed332aac998
7
+ data.tar.gz: 4ab047ea311a45c24857b6ca5a71f6741705917892c58ca76016a37653501d752626400703a74ec8ae1c36d8e9415ed181eb74132e90a123cee324e59acf90b0
data/Appraisals CHANGED
@@ -1,5 +1,5 @@
1
1
  appraise "rails-4" do
2
- gem "rails", "~> 4.0"
2
+ gem "rails", "4.2.0"
3
3
  end
4
4
 
5
5
  appraise "rails-5" do
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ### 1.5.0 - 2017-02-17
4
+ Features
5
+ - Support for nested resources (https://github.com/varvet/godmin/pull/189)
6
+
3
7
  ### 1.4.0 - 2017-02-15
4
8
  Features
5
9
  - Support group queries in scopes and filters (https://github.com/varvet/godmin/pull/208)
data/Gemfile CHANGED
@@ -13,4 +13,3 @@ gemspec
13
13
  # The dummy app loads whatever is specified in this gemfile, therefore
14
14
  # we add the admin engine used by the dummy app here
15
15
  gem "admin", path: "test/dummy/admin", group: [:test, :development]
16
- gem "codeclimate-test-reporter", group: :test, require: nil
data/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  [![Gem Version](http://img.shields.io/gem/v/godmin.svg)](https://rubygems.org/gems/godmin)
4
4
  [![Build Status](https://img.shields.io/travis/varvet/godmin/master.svg)](https://travis-ci.org/varvet/godmin)
5
5
  [![Code Climate](https://img.shields.io/codeclimate/github/varvet/godmin.svg)](https://codeclimate.com/github/varvet/godmin)
6
- [![Test Coverage](https://codeclimate.com/github/varvet/godmin/badges/coverage.svg)](https://codeclimate.com/github/varvet/godmin/coverage)
7
6
 
8
7
  Godmin is an admin framework for Rails 4+. Use it to build dedicated admin sections for your apps, or stand alone admin apps such as internal tools. It has support for common features such as scoping, filtering and performing batch actions on your models. Check out the [demo app](http://godmin-sandbox.herokuapp.com) and its [source code](https://github.com/varvet/godmin-sandbox) to get a feel for how it works.
9
8
 
@@ -25,6 +24,7 @@ Godmin differs from tools like [ActiveAdmin](http://activeadmin.info/) and [Rail
25
24
  - [Redirecting](#redirecting)
26
25
  - [Pagination](#pagination)
27
26
  - [Exporting](#exporting)
27
+ - [Nested resources](#nested-resources)
28
28
  - [Views](#views)
29
29
  - [Forms](#forms)
30
30
  - [Navigation](#navigation)
@@ -511,7 +511,7 @@ If you wish to change the number of resources per page, you can override the `pe
511
511
 
512
512
  ```ruby
513
513
  class ArticlesService
514
- include Godmin::Resources::Service
514
+ include Godmin::Resources::ResourceService
515
515
 
516
516
  def per_page
517
517
  50
@@ -525,12 +525,36 @@ The `attrs_for_export` method in the service object makes it possible to mark at
525
525
 
526
526
  ```ruby
527
527
  class ArticlesService
528
- include Godmin::Resources::Service
528
+ include Godmin::Resources::ResourceService
529
529
 
530
530
  attrs_for_export :id, :title, :created_at, :updated_at
531
531
  end
532
532
  ```
533
533
 
534
+ ### Nested resources
535
+
536
+ Nested resources can be implemented by nesting your routes:
537
+
538
+ ```ruby
539
+ resources :blogs do
540
+ resources :blog_posts
541
+ end
542
+ ```
543
+
544
+ This will set up scoping of the nested resource as well as correct links in the breadcrumb.
545
+
546
+ If you want to add a link to the nested resource from the parent's show and edit pages, you can add the following to the service object:
547
+
548
+ ```ruby
549
+ class BlogService
550
+ include Godmin::Resources::ResourceService
551
+
552
+ has_many :blog_posts
553
+ end
554
+ ```
555
+
556
+ Otherwise, simply add links as you see fit using partial overrides.
557
+
534
558
  ## Views
535
559
 
536
560
  It's easy to override view templates and partials in Godmin, both globally and per resource. All you have to do is place a file with an identical name in your `app/views` directory. For instance, to override the `godmin/resource/index.html.erb` template for all resources, place a file under `app/views/resource/index.html.erb`. If you only wish to override it for articles, place it instead under `app/views/articles/index.html.erb`.
@@ -1,12 +1,22 @@
1
1
  <div id="breadcrumb">
2
2
  <ol class="breadcrumb">
3
+ <% if @resource_parents %>
4
+ <% @resource_parents.each do |parent| %>
5
+ <li>
6
+ <%= link_to parent.class.model_name.human(count: 2), parent.class %>
7
+ </li>
8
+ <li>
9
+ <%= link_to parent.to_s, parent %>
10
+ </li>
11
+ <% end %>
12
+ <% end %>
3
13
  <% if action_name == "index" %>
4
14
  <li class="active">
5
15
  <%= @resource_class.model_name.human(count: 2) %>
6
16
  </li>
7
17
  <% else %>
8
18
  <li>
9
- <%= link_to @resource_class.model_name.human(count: 2), @resource_class %>
19
+ <%= link_to @resource_class.model_name.human(count: 2), [*@resource_parents, @resource_class] %>
10
20
  </li>
11
21
  <li class="active">
12
22
  <% if @resource.new_record? %>
@@ -16,29 +26,7 @@
16
26
  <% end %>
17
27
  </li>
18
28
  <% if @resource.persisted? %>
19
- <li class="dropdown pull-right">
20
- <a href="#" data-toggle="dropdown" role="button">
21
- <%= translate_scoped("actions.label") %> <span class="caret"></span>
22
- </a>
23
- <ul class="dropdown-menu">
24
- <% if policy(@resource).show? && action_name != "show" %>
25
- <li>
26
- <%= link_to translate_scoped("actions.show"), @resource %>
27
- </li>
28
- <% end %>
29
- <% if policy(@resource).edit? && action_name != "edit" %>
30
- <li>
31
- <%= link_to translate_scoped("actions.edit"), [:edit, @resource] %>
32
- </li>
33
- <% end %>
34
- <% if policy(@resource).destroy? %>
35
- <li>
36
- <%= link_to translate_scoped("actions.destroy"), @resource, method: :delete,
37
- data: { confirm: translate_scoped("actions.confirm_message") } %>
38
- </li>
39
- <% end %>
40
- </ul>
41
- </li>
29
+ <%= render partial: "breadcrumb_actions" %>
42
30
  <% end %>
43
31
  <% end %>
44
32
  </ol>
@@ -0,0 +1,41 @@
1
+ <li class="dropdown pull-right">
2
+ <a href="#" data-toggle="dropdown">
3
+ <%= translate_scoped("actions.label") %> <span class="caret"></span>
4
+ </a>
5
+ <ul class="dropdown-menu">
6
+ <% if policy(@resource).show? && action_name != "show" %>
7
+ <li>
8
+ <%= link_to translate_scoped("actions.show"), [*@resource_parents, @resource] %>
9
+ </li>
10
+ <% end %>
11
+ <% if policy(@resource).edit? && action_name != "edit" %>
12
+ <li>
13
+ <%= link_to translate_scoped("actions.edit"), [:edit, *@resource_parents, @resource] %>
14
+ </li>
15
+ <% end %>
16
+ <% if policy(@resource).destroy? %>
17
+ <li>
18
+ <%= link_to translate_scoped("actions.destroy"), [*@resource_parents, @resource], method: :delete,
19
+ data: { confirm: translate_scoped("actions.confirm_message") } %>
20
+ </li>
21
+ <% end %>
22
+ </ul>
23
+ </li>
24
+
25
+ <% if @resource_service.has_many_map.present? %>
26
+ <li class="dropdown pull-right">
27
+ <a href="#" data-toggle="dropdown">
28
+ <%= translate_scoped("associations.label") %> <span class="caret"></span>
29
+ </a>
30
+ <ul class="dropdown-menu">
31
+ <% @resource_service.has_many_map.each do |name, options| %>
32
+ <% if policy(options[:class_name].constantize).index? %>
33
+ <li>
34
+ <%= link_to(options[:class_name].constantize.model_name.human(count: 2),
35
+ send("#{@resource_class.name.underscore}_#{name}_path", @resource)) %>
36
+ </li>
37
+ <% end %>
38
+ <% end %>
39
+ </ul>
40
+ </li>
41
+ <% end %>
@@ -1,3 +1,3 @@
1
1
  <% if policy(@resource_service.build_resource({})).new? %>
2
- <%= link_to t("helpers.submit.create", model: @resource_class.model_name.human), [:new, @resource_class.model_name.singular_route_key], class: "btn btn-default" %>
2
+ <%= link_to t("helpers.submit.create", model: @resource_class.model_name.human), [:new, *@resource_parents, @resource_class.model_name.singular_route_key], class: "btn btn-default" %>
3
3
  <% end %>
@@ -2,7 +2,7 @@
2
2
  <% if policy(resource).show? %>
3
3
  <%= link_to(
4
4
  translate_scoped("actions.show"),
5
- resource,
5
+ [*@resource_parents, resource],
6
6
  class: "btn btn-default",
7
7
  title: translate_scoped("actions.show_title", resource: resource)
8
8
  ) %>
@@ -10,7 +10,7 @@
10
10
  <% if policy(resource).edit? %>
11
11
  <%= link_to(
12
12
  translate_scoped("actions.edit"),
13
- [:edit, resource],
13
+ [:edit, *@resource_parents, resource],
14
14
  class: "btn btn-default",
15
15
  title: translate_scoped("actions.edit_title", resource: resource)
16
16
  ) %>
@@ -18,7 +18,7 @@
18
18
  <% if policy(resource).destroy? %>
19
19
  <%= link_to(
20
20
  translate_scoped("actions.destroy"),
21
- resource,
21
+ [*@resource_parents, resource],
22
22
  method: :delete,
23
23
  class: "btn btn-default",
24
24
  title: translate_scoped("actions.destroy_title", resource: resource),
@@ -1,6 +1,6 @@
1
1
  <%= render partial: "breadcrumb" %>
2
2
 
3
- <table class="table table-striped">
3
+ <table class="table">
4
4
  <% @resource_service.attrs_for_show.each do |attr| %>
5
5
  <tr>
6
6
  <th><%= @resource_class.human_attribute_name(attr) %></th>
@@ -25,6 +25,8 @@ en:
25
25
  confirm_message: Are you sure?
26
26
  export: Export
27
27
  export_as: As
28
+ associations:
29
+ label: Nested resources
28
30
  sessions:
29
31
  sign_in: Sign in
30
32
  sign_out: Sign out
@@ -25,6 +25,8 @@ pt-BR:
25
25
  confirm_message: Você tem certeza?
26
26
  export: Exportar
27
27
  export_as: Como
28
+ associations:
29
+ label: Nested resources
28
30
  sessions:
29
31
  sign_in: Entrar
30
32
  sign_out: Sair
@@ -25,6 +25,8 @@ sv:
25
25
  confirm_message: Är du säker?
26
26
  export: Exportera
27
27
  export_as: Som
28
+ associations:
29
+ label: Nästlade resurser
28
30
  sessions:
29
31
  sign_in: Logga in
30
32
  sign_out: Logga ut
@@ -3,7 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "admin", :path => "../test/dummy/admin", :group => [:test, :development]
6
- gem "codeclimate-test-reporter", :group => :test, :require => nil
7
- gem "rails", "~> 4.0"
6
+ gem "rails", "4.2.0"
8
7
 
9
8
  gemspec :path => "../"
@@ -3,7 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "admin", :path => "../test/dummy/admin", :group => [:test, :development]
6
- gem "codeclimate-test-reporter", :group => :test, :require => nil
7
6
  gem "rails", "~> 5.0"
8
7
 
9
8
  gemspec :path => "../"
@@ -26,16 +26,15 @@ Gem::Specification.new do |gem|
26
26
  gem.add_dependency "csv_builder", "~> 2.1"
27
27
  gem.add_dependency "jquery-rails", [">= 3.0", "< 5.0"]
28
28
  gem.add_dependency "momentjs-rails", "~> 2.8"
29
- gem.add_dependency "rails", [">= 4.0", "< 6.0"]
29
+ gem.add_dependency "rails", [">= 4.2.0", "< 6.0"]
30
30
  gem.add_dependency "sass-rails", [">= 4.0", "< 6.0"]
31
31
  gem.add_dependency "selectize-rails", "~> 0.12"
32
32
 
33
- gem.add_development_dependency "appraisal", "~> 2.1"
34
- gem.add_development_dependency "capybara", "~> 2.4"
35
- gem.add_development_dependency "m", "~> 1.3"
36
- gem.add_development_dependency "minitest-reporters", "~> 1.0"
37
- gem.add_development_dependency "minitest", "~> 5.5"
38
- gem.add_development_dependency "poltergeist", "~> 1.7"
39
- gem.add_development_dependency "pry", "~> 0.10"
40
- gem.add_development_dependency "sqlite3", "~> 1.3"
33
+ gem.add_development_dependency "appraisal", "~> 0"
34
+ gem.add_development_dependency "capybara", "~> 0"
35
+ gem.add_development_dependency "minitest-reporters", "~> 0"
36
+ gem.add_development_dependency "minitest", "~> 0"
37
+ gem.add_development_dependency "poltergeist", "~> 0"
38
+ gem.add_development_dependency "pry", "~> 0"
39
+ gem.add_development_dependency "sqlite3", "~> 0"
41
40
  end
@@ -6,7 +6,7 @@ module Godmin
6
6
 
7
7
  link_to(
8
8
  translate_scoped("batch_actions.labels.#{name}", default: name.to_s.titleize),
9
- @resource_class,
9
+ [*@resource_parents, @resource_class],
10
10
  method: :patch,
11
11
  class: "btn btn-default hidden",
12
12
  data: {
@@ -2,7 +2,11 @@ module Godmin
2
2
  module Helpers
3
3
  module Forms
4
4
  def form_for(record, options = {}, &block)
5
- super(record, { builder: FormBuilders::FormBuilder, inline_errors: false }.merge(options), &block)
5
+ super(record, {
6
+ url: [*@resource_parents, record],
7
+ builder: FormBuilders::FormBuilder,
8
+ inline_errors: false
9
+ }.merge(options), &block)
6
10
  end
7
11
  end
8
12
  end
@@ -17,6 +17,7 @@ module Godmin
17
17
 
18
18
  before_action :set_resource_service
19
19
  before_action :set_resource_class
20
+ before_action :set_resource_parents
20
21
  before_action :set_resources, only: :index
21
22
  before_action :set_resource, only: [:show, :new, :edit, :create, :update, :destroy]
22
23
  end
@@ -83,6 +84,10 @@ module Godmin
83
84
  @resource_class = resource_class
84
85
  end
85
86
 
87
+ def set_resource_parents
88
+ @resource_parents = resource_parents
89
+ end
90
+
86
91
  def set_resources
87
92
  @resources = resources
88
93
  authorize(@resources) if authorization_enabled?
@@ -98,17 +103,31 @@ module Godmin
98
103
  end
99
104
 
100
105
  def resource_service
106
+ resource_service = resource_service_class.new
107
+
101
108
  if authentication_enabled?
102
- resource_service_class.new(admin_user: admin_user)
103
- else
104
- resource_service_class.new
109
+ resource_service.options[:admin_user] = admin_user
110
+ end
111
+
112
+ if resource_parents.present?
113
+ resource_service.options[:resource_parent] = resource_parents.last
105
114
  end
115
+
116
+ resource_service
106
117
  end
107
118
 
108
119
  def resource_class
109
120
  @resource_service.resource_class
110
121
  end
111
122
 
123
+ def resource_parents
124
+ params.to_unsafe_h.each_with_object([]) do |(name, value), parents|
125
+ if name =~ /(.+)_id$/
126
+ parents << $1.classify.constantize.find(value)
127
+ end
128
+ end
129
+ end
130
+
112
131
  def resources
113
132
  @resource_service.resources(params)
114
133
  end
@@ -151,11 +170,11 @@ module Godmin
151
170
  end
152
171
 
153
172
  def redirect_after_save
154
- @resource
173
+ [*@resource_parents, @resource]
155
174
  end
156
175
 
157
176
  def redirect_after_destroy
158
- resource_class.model_name.route_key.to_sym
177
+ [*@resource_parents, resource_class.model_name.route_key.to_sym]
159
178
  end
160
179
 
161
180
  def redirect_flash_message
@@ -1,3 +1,4 @@
1
+ require "godmin/resources/resource_service/associations"
1
2
  require "godmin/resources/resource_service/batch_actions"
2
3
  require "godmin/resources/resource_service/filters"
3
4
  require "godmin/resources/resource_service/ordering"
@@ -9,6 +10,7 @@ module Godmin
9
10
  module ResourceService
10
11
  extend ActiveSupport::Concern
11
12
 
13
+ include Associations
12
14
  include BatchActions
13
15
  include Filters
14
16
  include Ordering
@@ -21,7 +23,6 @@ module Godmin
21
23
  @options = options
22
24
  end
23
25
 
24
- # TODO: should this raise its own error?
25
26
  def resource_class
26
27
  @options[:resource_class] || resource_class_name.constantize
27
28
  end
@@ -31,7 +32,11 @@ module Godmin
31
32
  end
32
33
 
33
34
  def resources_relation
34
- resource_class.all
35
+ if options[:resource_parent].present?
36
+ resource_class.where(options[:resource_parent].class.name.underscore => options[:resource_parent])
37
+ else
38
+ resource_class.all
39
+ end
35
40
  end
36
41
 
37
42
  def resources(params)
@@ -0,0 +1,23 @@
1
+ module Godmin
2
+ module Resources
3
+ module ResourceService
4
+ module Associations
5
+ extend ActiveSupport::Concern
6
+
7
+ delegate :has_many_map, to: "self.class"
8
+
9
+ module ClassMethods
10
+ def has_many_map
11
+ @has_many_map ||= {}
12
+ end
13
+
14
+ def has_many(attr, options = {})
15
+ has_many_map[attr] = {
16
+ class_name: attr.to_s.singularize.classify
17
+ }.merge(options)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Godmin
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -0,0 +1,3 @@
1
+ class CommentsController < ApplicationController
2
+ include Godmin::Resources::ResourceController
3
+ end
@@ -1,5 +1,6 @@
1
1
  class Article < ActiveRecord::Base
2
2
  belongs_to :admin_user
3
+ has_many :comments
3
4
 
4
5
  def non_orderable_column
5
6
  "Not orderable"
@@ -0,0 +1,7 @@
1
+ class Comment < ActiveRecord::Base
2
+ belongs_to :article
3
+
4
+ def to_s
5
+ title
6
+ end
7
+ end
@@ -5,6 +5,8 @@ class ArticleService
5
5
  attrs_for_show :id, :title, :body, :admin_user, :published
6
6
  attrs_for_form :title, :body, :admin_user, :published
7
7
 
8
+ has_many :comments
9
+
8
10
  def order_by_admin_user(resources, direction)
9
11
  resources.joins(:admin_users).order("admin_users.email #{direction}")
10
12
  end
@@ -0,0 +1,7 @@
1
+ class CommentService
2
+ include Godmin::Resources::ResourceService
3
+
4
+ attrs_for_index :id, :title
5
+ attrs_for_show :id, :title, :body
6
+ attrs_for_form :title, :body
7
+ end
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
3
  require_relative '../config/boot'
4
4
  require 'rails/commands'
@@ -1,23 +1,11 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ require File.expand_path("../boot", __FILE__)
2
2
 
3
- require 'rails/all'
3
+ require "rails/all"
4
4
 
5
5
  Bundler.require(*Rails.groups)
6
6
  require "godmin"
7
7
 
8
8
  module Dummy
9
9
  class Application < Rails::Application
10
- # Settings in config/environments/* take precedence over those specified here.
11
- # Application configuration should go into files in config/initializers
12
- # -- all .rb files in that directory are automatically loaded.
13
-
14
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
- # config.time_zone = 'Central Time (US & Canada)'
17
-
18
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
- # config.i18n.default_locale = :de
21
10
  end
22
11
  end
23
-
@@ -0,0 +1,9 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ article:
5
+ one: Article
6
+ other: Articles
7
+ comment:
8
+ one: Comment
9
+ other: Comments
@@ -1,5 +1,7 @@
1
1
  Rails.application.routes.draw do
2
- resources :articles
2
+ resources :articles do
3
+ resources :comments
4
+ end
3
5
  resources :authenticated_articles
4
6
  resources :authorized_articles
5
7
  resource :session, only: [:new, :create, :destroy]
@@ -0,0 +1,9 @@
1
+ class CreateComment < ActiveRecord::Migration
2
+ def change
3
+ create_table :comments do |t|
4
+ t.references :article, index: true, foreign_key: true
5
+ t.string :title
6
+ t.text :body
7
+ end
8
+ end
9
+ end
@@ -35,4 +35,11 @@ ActiveRecord::Schema.define(version: 20170207081043) do
35
35
  t.datetime "updated_at", null: false
36
36
  end
37
37
 
38
+ create_table "comments", force: :cascade do |t|
39
+ t.integer "article_id"
40
+ t.string "title"
41
+ t.text "body"
42
+ t.index ["article_id"], name: "index_comments_on_article_id"
43
+ end
44
+
38
45
  end
@@ -17,7 +17,13 @@ class AuthenticationTest < ActionDispatch::IntegrationTest
17
17
 
18
18
  def test_sign_in_with_non_default_user
19
19
  AnotherAdminUser.create!(email: "another_admin@example.com", password: "password")
20
- post another_admin_session_path, another_admin_user: { email: "another_admin@example.com", password: "password" }
20
+
21
+ case Rails::VERSION::MAJOR
22
+ when 4
23
+ post another_admin_session_path, another_admin_user: { email: "another_admin@example.com", password: "password" }
24
+ when 5
25
+ post another_admin_session_path, params: { another_admin_user: { email: "another_admin@example.com", password: "password" } }
26
+ end
21
27
 
22
28
  assert_redirected_to root_path
23
29
  end
@@ -0,0 +1,47 @@
1
+ require "test_helper"
2
+
3
+ class NestedResourcesTest < ActionDispatch::IntegrationTest
4
+ def test_list_nested_resources
5
+ article = Article.create! title: "foo", comments: [
6
+ Comment.new(title: "bar")
7
+ ]
8
+
9
+ visit articles_path
10
+ within "[data-resource-id='#{article.id}']" do
11
+ click_link "Show"
12
+ end
13
+ click_link "Comments"
14
+
15
+ assert_equal article_comments_path(article), current_path
16
+ assert page.has_content? "bar"
17
+ end
18
+
19
+ def test_list_nested_resources_scoping
20
+ article = Article.create! title: "foo", comments: [
21
+ Comment.new(title: "bar")
22
+ ]
23
+ Comment.create! title: "baz"
24
+
25
+ visit article_comments_path(article)
26
+
27
+ assert page.has_content? "bar"
28
+ assert page.has_no_content? "baz"
29
+ end
30
+
31
+ def test_create_nested_resource
32
+ article = Article.create! title: "foo"
33
+
34
+ visit new_article_comment_path(article)
35
+
36
+ fill_in "Title", with: "bar"
37
+ click_button "Create Comment"
38
+
39
+ assert_equal article_comment_path(article, Comment.last), current_path
40
+
41
+ within "#breadcrumb" do
42
+ click_link "Comments"
43
+ end
44
+
45
+ assert page.has_content? "bar"
46
+ end
47
+ end
@@ -1,11 +1,6 @@
1
- # TODO: This does not work anymore. We need to update this according to:
2
- # https://docs.codeclimate.com/docs/ruby
3
- #
4
- # require "codeclimate-test-reporter"
5
- # CodeClimate::TestReporter.start
6
-
7
1
  # Configure Rails Environment
8
2
  ENV["RAILS_ENV"] = "test"
3
+ ENV["DISABLE_DATABASE_ENVIRONMENT_CHECK"] = "1"
9
4
 
10
5
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
11
6
  require "rails/test_help"
@@ -14,7 +9,6 @@ require "capybara/poltergeist"
14
9
  require "minitest/reporters"
15
10
  require "pry"
16
11
 
17
- # TODO: what to call these?
18
12
  require File.expand_path("../fakes/article.rb", __FILE__)
19
13
  require File.expand_path("../fakes/article_service.rb", __FILE__)
20
14
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: godmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Ljungblad
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-02-15 00:00:00.000000000 Z
13
+ date: 2017-02-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bcrypt
@@ -128,7 +128,7 @@ dependencies:
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: '4.0'
131
+ version: 4.2.0
132
132
  - - "<"
133
133
  - !ruby/object:Gem::Version
134
134
  version: '6.0'
@@ -138,7 +138,7 @@ dependencies:
138
138
  requirements:
139
139
  - - ">="
140
140
  - !ruby/object:Gem::Version
141
- version: '4.0'
141
+ version: 4.2.0
142
142
  - - "<"
143
143
  - !ruby/object:Gem::Version
144
144
  version: '6.0'
@@ -182,112 +182,98 @@ dependencies:
182
182
  requirements:
183
183
  - - "~>"
184
184
  - !ruby/object:Gem::Version
185
- version: '2.1'
185
+ version: '0'
186
186
  type: :development
187
187
  prerelease: false
188
188
  version_requirements: !ruby/object:Gem::Requirement
189
189
  requirements:
190
190
  - - "~>"
191
191
  - !ruby/object:Gem::Version
192
- version: '2.1'
192
+ version: '0'
193
193
  - !ruby/object:Gem::Dependency
194
194
  name: capybara
195
195
  requirement: !ruby/object:Gem::Requirement
196
196
  requirements:
197
197
  - - "~>"
198
198
  - !ruby/object:Gem::Version
199
- version: '2.4'
200
- type: :development
201
- prerelease: false
202
- version_requirements: !ruby/object:Gem::Requirement
203
- requirements:
204
- - - "~>"
205
- - !ruby/object:Gem::Version
206
- version: '2.4'
207
- - !ruby/object:Gem::Dependency
208
- name: m
209
- requirement: !ruby/object:Gem::Requirement
210
- requirements:
211
- - - "~>"
212
- - !ruby/object:Gem::Version
213
- version: '1.3'
199
+ version: '0'
214
200
  type: :development
215
201
  prerelease: false
216
202
  version_requirements: !ruby/object:Gem::Requirement
217
203
  requirements:
218
204
  - - "~>"
219
205
  - !ruby/object:Gem::Version
220
- version: '1.3'
206
+ version: '0'
221
207
  - !ruby/object:Gem::Dependency
222
208
  name: minitest-reporters
223
209
  requirement: !ruby/object:Gem::Requirement
224
210
  requirements:
225
211
  - - "~>"
226
212
  - !ruby/object:Gem::Version
227
- version: '1.0'
213
+ version: '0'
228
214
  type: :development
229
215
  prerelease: false
230
216
  version_requirements: !ruby/object:Gem::Requirement
231
217
  requirements:
232
218
  - - "~>"
233
219
  - !ruby/object:Gem::Version
234
- version: '1.0'
220
+ version: '0'
235
221
  - !ruby/object:Gem::Dependency
236
222
  name: minitest
237
223
  requirement: !ruby/object:Gem::Requirement
238
224
  requirements:
239
225
  - - "~>"
240
226
  - !ruby/object:Gem::Version
241
- version: '5.5'
227
+ version: '0'
242
228
  type: :development
243
229
  prerelease: false
244
230
  version_requirements: !ruby/object:Gem::Requirement
245
231
  requirements:
246
232
  - - "~>"
247
233
  - !ruby/object:Gem::Version
248
- version: '5.5'
234
+ version: '0'
249
235
  - !ruby/object:Gem::Dependency
250
236
  name: poltergeist
251
237
  requirement: !ruby/object:Gem::Requirement
252
238
  requirements:
253
239
  - - "~>"
254
240
  - !ruby/object:Gem::Version
255
- version: '1.7'
241
+ version: '0'
256
242
  type: :development
257
243
  prerelease: false
258
244
  version_requirements: !ruby/object:Gem::Requirement
259
245
  requirements:
260
246
  - - "~>"
261
247
  - !ruby/object:Gem::Version
262
- version: '1.7'
248
+ version: '0'
263
249
  - !ruby/object:Gem::Dependency
264
250
  name: pry
265
251
  requirement: !ruby/object:Gem::Requirement
266
252
  requirements:
267
253
  - - "~>"
268
254
  - !ruby/object:Gem::Version
269
- version: '0.10'
255
+ version: '0'
270
256
  type: :development
271
257
  prerelease: false
272
258
  version_requirements: !ruby/object:Gem::Requirement
273
259
  requirements:
274
260
  - - "~>"
275
261
  - !ruby/object:Gem::Version
276
- version: '0.10'
262
+ version: '0'
277
263
  - !ruby/object:Gem::Dependency
278
264
  name: sqlite3
279
265
  requirement: !ruby/object:Gem::Requirement
280
266
  requirements:
281
267
  - - "~>"
282
268
  - !ruby/object:Gem::Version
283
- version: '1.3'
269
+ version: '0'
284
270
  type: :development
285
271
  prerelease: false
286
272
  version_requirements: !ruby/object:Gem::Requirement
287
273
  requirements:
288
274
  - - "~>"
289
275
  - !ruby/object:Gem::Version
290
- version: '1.3'
276
+ version: '0'
291
277
  description: Godmin is an admin framework for Rails 4+. Use it to build dedicated
292
278
  admin sections for your apps, or stand alone admin apps such as internal tools.
293
279
  email:
@@ -318,6 +304,7 @@ files:
318
304
  - app/views/godmin/resource/_actions.html.erb
319
305
  - app/views/godmin/resource/_batch_actions.html.erb
320
306
  - app/views/godmin/resource/_breadcrumb.html.erb
307
+ - app/views/godmin/resource/_breadcrumb_actions.html.erb
321
308
  - app/views/godmin/resource/_button_actions.html.erb
322
309
  - app/views/godmin/resource/_errors.html.erb
323
310
  - app/views/godmin/resource/_export_actions.html.erb
@@ -380,6 +367,7 @@ files:
380
367
  - lib/godmin/resources/resource_controller.rb
381
368
  - lib/godmin/resources/resource_controller/batch_actions.rb
382
369
  - lib/godmin/resources/resource_service.rb
370
+ - lib/godmin/resources/resource_service/associations.rb
383
371
  - lib/godmin/resources/resource_service/batch_actions.rb
384
372
  - lib/godmin/resources/resource_service/filters.rb
385
373
  - lib/godmin/resources/resource_service/ordering.rb
@@ -415,13 +403,16 @@ files:
415
403
  - test/dummy/app/controllers/articles_controller.rb
416
404
  - test/dummy/app/controllers/authenticated_articles_controller.rb
417
405
  - test/dummy/app/controllers/authorized_articles_controller.rb
406
+ - test/dummy/app/controllers/comments_controller.rb
418
407
  - test/dummy/app/controllers/sessions_controller.rb
419
408
  - test/dummy/app/models/.keep
420
409
  - test/dummy/app/models/admin_user.rb
421
410
  - test/dummy/app/models/another_admin_user.rb
422
411
  - test/dummy/app/models/article.rb
412
+ - test/dummy/app/models/comment.rb
423
413
  - test/dummy/app/policies/article_policy.rb
424
414
  - test/dummy/app/services/article_service.rb
415
+ - test/dummy/app/services/comment_service.rb
425
416
  - test/dummy/app/views/articles/.keep
426
417
  - test/dummy/app/views/articles/columns/.keep
427
418
  - test/dummy/app/views/articles/filters/.keep
@@ -446,9 +437,11 @@ files:
446
437
  - test/dummy/config/initializers/secret_token.rb
447
438
  - test/dummy/config/initializers/session_store.rb
448
439
  - test/dummy/config/initializers/wrap_parameters.rb
440
+ - test/dummy/config/locales/en.yml
449
441
  - test/dummy/config/routes.rb
450
442
  - test/dummy/db/migrate/20150717121532_create_articles.rb
451
443
  - test/dummy/db/migrate/20150907133753_create_admin_users.rb
444
+ - test/dummy/db/migrate/20160713134238_create_comment.rb
452
445
  - test/dummy/db/migrate/20170207081043_create_another_admin_user.rb
453
446
  - test/dummy/db/schema.rb
454
447
  - test/dummy/lib/assets/.keep
@@ -465,6 +458,7 @@ files:
465
458
  - test/integration/column_ordering_test.rb
466
459
  - test/integration/crud_test.rb
467
460
  - test/integration/filters_test.rb
461
+ - test/integration/nested_resources_test.rb
468
462
  - test/integration/scopes_test.rb
469
463
  - test/integration/view_overriding/column_overriding_test.rb
470
464
  - test/integration/view_overriding/filter_overriding_test.rb
@@ -536,13 +530,16 @@ test_files:
536
530
  - test/dummy/app/controllers/articles_controller.rb
537
531
  - test/dummy/app/controllers/authenticated_articles_controller.rb
538
532
  - test/dummy/app/controllers/authorized_articles_controller.rb
533
+ - test/dummy/app/controllers/comments_controller.rb
539
534
  - test/dummy/app/controllers/sessions_controller.rb
540
535
  - test/dummy/app/models/.keep
541
536
  - test/dummy/app/models/admin_user.rb
542
537
  - test/dummy/app/models/another_admin_user.rb
543
538
  - test/dummy/app/models/article.rb
539
+ - test/dummy/app/models/comment.rb
544
540
  - test/dummy/app/policies/article_policy.rb
545
541
  - test/dummy/app/services/article_service.rb
542
+ - test/dummy/app/services/comment_service.rb
546
543
  - test/dummy/app/views/articles/.keep
547
544
  - test/dummy/app/views/articles/columns/.keep
548
545
  - test/dummy/app/views/articles/filters/.keep
@@ -567,9 +564,11 @@ test_files:
567
564
  - test/dummy/config/initializers/secret_token.rb
568
565
  - test/dummy/config/initializers/session_store.rb
569
566
  - test/dummy/config/initializers/wrap_parameters.rb
567
+ - test/dummy/config/locales/en.yml
570
568
  - test/dummy/config/routes.rb
571
569
  - test/dummy/db/migrate/20150717121532_create_articles.rb
572
570
  - test/dummy/db/migrate/20150907133753_create_admin_users.rb
571
+ - test/dummy/db/migrate/20160713134238_create_comment.rb
573
572
  - test/dummy/db/migrate/20170207081043_create_another_admin_user.rb
574
573
  - test/dummy/db/schema.rb
575
574
  - test/dummy/lib/assets/.keep
@@ -586,6 +585,7 @@ test_files:
586
585
  - test/integration/column_ordering_test.rb
587
586
  - test/integration/crud_test.rb
588
587
  - test/integration/filters_test.rb
588
+ - test/integration/nested_resources_test.rb
589
589
  - test/integration/scopes_test.rb
590
590
  - test/integration/view_overriding/column_overriding_test.rb
591
591
  - test/integration/view_overriding/filter_overriding_test.rb