godmin 1.0.0 → 1.1.0

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 (35) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/.travis.yml +1 -0
  4. data/CHANGELOG.md +12 -0
  5. data/README.md +58 -8
  6. data/Rakefile +45 -16
  7. data/app/views/godmin/resource/show.html.erb +1 -1
  8. data/app/views/layouts/godmin/_layout.html.erb +1 -0
  9. data/app/views/layouts/godmin/application.html.erb +7 -1
  10. data/config/locales/en.yml +1 -1
  11. data/config/locales/pt-BR.yml +44 -0
  12. data/config/locales/sv.yml +1 -1
  13. data/godmin.gemspec +2 -1
  14. data/lib/generators/godmin/authentication/authentication_generator.rb +1 -1
  15. data/lib/godmin/application_controller.rb +1 -1
  16. data/lib/godmin/generators/named_base.rb +8 -0
  17. data/lib/godmin/resolver.rb +44 -18
  18. data/lib/godmin/resources/resource_controller.rb +17 -30
  19. data/lib/godmin/resources/resource_controller/batch_actions.rb +49 -0
  20. data/lib/godmin/version.rb +1 -1
  21. data/template.rb +180 -18
  22. data/test/dummy/admin/app/assets/javascripts/admin/application.js +1 -0
  23. data/test/dummy/app/assets/javascripts/application.js +1 -0
  24. data/test/dummy/app/controllers/application_controller.rb +2 -2
  25. data/test/dummy/app/controllers/articles_controller.rb +10 -0
  26. data/test/dummy/app/services/article_service.rb +31 -0
  27. data/test/dummy/app/services/secret_article_service.rb +0 -7
  28. data/test/dummy/db/migrate/20150717121532_create_articles.rb +1 -1
  29. data/test/dummy/db/schema.rb +3 -3
  30. data/test/integration/batch_actions_test.rb +51 -0
  31. data/test/integration/filters_test.rb +21 -0
  32. data/test/integration/scopes_test.rb +23 -0
  33. data/test/lib/godmin/resolver_test.rb +22 -8
  34. data/test/test_helper.rb +19 -3
  35. metadata +25 -3
@@ -1,3 +1,13 @@
1
1
  class ArticlesController < ApplicationController
2
2
  include Godmin::Resources::ResourceController
3
+
4
+ private
5
+
6
+ def redirect_after_batch_action_publish
7
+ articles_path(scope: :published)
8
+ end
9
+
10
+ def redirect_after_batch_action_unpublish
11
+ articles_path(scope: :unpublished)
12
+ end
3
13
  end
@@ -5,5 +5,36 @@ class ArticleService
5
5
  attrs_for_show :id, :title, :body, :published
6
6
  attrs_for_form :title, :body, :published
7
7
 
8
+ scope :unpublished
9
+ scope :published
10
+
11
+ def scope_unpublished(articles)
12
+ articles.where(published: false)
13
+ end
14
+
15
+ def scope_published(articles)
16
+ articles.where(published: true)
17
+ end
18
+
8
19
  filter :title
20
+
21
+ def filter_title(articles, value)
22
+ articles.where(title: value)
23
+ end
24
+
25
+ batch_action :destroy
26
+ batch_action :publish
27
+ batch_action :unpublish
28
+
29
+ def batch_action_destroy(articles)
30
+ articles.destroy_all
31
+ end
32
+
33
+ def batch_action_publish(articles)
34
+ articles.update_all(published: true)
35
+ end
36
+
37
+ def batch_action_unpublish(articles)
38
+ articles.update_all(published: false)
39
+ end
9
40
  end
@@ -1,9 +1,2 @@
1
1
  class SecretArticleService < 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
2
  end
@@ -3,7 +3,7 @@ class CreateArticles < ActiveRecord::Migration
3
3
  create_table :articles do |t|
4
4
  t.string :title
5
5
  t.text :body
6
- t.boolean :published
6
+ t.boolean :published, default: false
7
7
 
8
8
  t.timestamps null: false
9
9
  end
@@ -23,9 +23,9 @@ ActiveRecord::Schema.define(version: 20150907133753) do
23
23
  create_table "articles", force: :cascade do |t|
24
24
  t.string "title"
25
25
  t.text "body"
26
- t.boolean "published"
27
- t.datetime "created_at", null: false
28
- t.datetime "updated_at", null: false
26
+ t.boolean "published", default: false
27
+ t.datetime "created_at", null: false
28
+ t.datetime "updated_at", null: false
29
29
  end
30
30
 
31
31
  end
@@ -0,0 +1,51 @@
1
+ require "test_helper"
2
+
3
+ class BatchActionsTest < ActionDispatch::IntegrationTest
4
+ def test_batch_action
5
+ Capybara.current_driver = Capybara.javascript_driver
6
+
7
+ Article.create! title: "foo"
8
+ Article.create! title: "bar"
9
+
10
+ visit articles_path
11
+
12
+ all("[data-behavior~=batch-actions-checkbox]").each(&:click)
13
+ within "#actions" do
14
+ click_link "Destroy"
15
+ end
16
+
17
+ assert_equal 200, page.status_code
18
+ assert page.has_no_content? "foo"
19
+ assert page.has_no_content? "bar"
20
+
21
+ Capybara.use_default_driver
22
+ end
23
+
24
+ def test_batch_action_redirect
25
+ Capybara.current_driver = Capybara.javascript_driver
26
+
27
+ Article.create! title: "foo"
28
+
29
+ visit articles_path
30
+
31
+ all("[data-behavior~=batch-actions-checkbox]").each(&:click)
32
+ within "#actions" do
33
+ click_link "Publish"
34
+ end
35
+
36
+ assert_equal articles_path(scope: :published), current_path_with_params
37
+ assert_equal 200, page.status_code
38
+
39
+ Capybara.use_default_driver
40
+ end
41
+
42
+ private
43
+
44
+ def current_path_with_params
45
+ "#{current_uri.path}?#{current_uri.query}"
46
+ end
47
+
48
+ def current_uri
49
+ URI.parse(page.current_url)
50
+ end
51
+ end
@@ -0,0 +1,21 @@
1
+ require "test_helper"
2
+
3
+ class FiltersTest < ActionDispatch::IntegrationTest
4
+ def test_filter
5
+ Article.create! title: "foo"
6
+ Article.create! title: "bar"
7
+
8
+ visit articles_path
9
+
10
+ fill_in "Title", with: "foo"
11
+ click_button "Filter"
12
+ assert_equal 200, page.status_code
13
+ assert page.has_content? "foo"
14
+ assert page.has_no_content? "bar"
15
+
16
+ click_link "Clear filter"
17
+ assert_equal 200, page.status_code
18
+ assert page.has_content? "foo"
19
+ assert page.has_content? "bar"
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ require "test_helper"
2
+
3
+ class ScopesTest < ActionDispatch::IntegrationTest
4
+ def test_scopes
5
+ Article.create! title: "foo"
6
+ Article.create! title: "bar"
7
+ Article.create! title: "baz", published: true
8
+
9
+ visit articles_path
10
+
11
+ assert page.has_content? "foo"
12
+ assert page.has_content? "bar"
13
+ assert page.has_no_content? "baz"
14
+
15
+ within "#scopes" do
16
+ click_link "Published"
17
+ end
18
+
19
+ assert page.has_no_content? "foo"
20
+ assert page.has_no_content? "bar"
21
+ assert page.has_content? "baz"
22
+ end
23
+ end
@@ -17,23 +17,37 @@ module Godmin
17
17
  @engine_wrapper_2 = EngineWrapper.new(Admin::Controller)
18
18
  end
19
19
 
20
+ def test_engine_resolver_when_not_namespaced
21
+ resolver = EngineResolver.new("articles", @engine_wrapper_1)
22
+
23
+ assert_equal [
24
+ "resource"
25
+ ], resolver.template_paths("articles")
26
+ end
27
+
28
+ def test_engine_resolver_when_namespaced
29
+ resolver = EngineResolver.new("godmin/resolver_test/admin/articles", @engine_wrapper_2)
30
+
31
+ assert_equal [
32
+ "godmin/resolver_test/admin/resource"
33
+ ], resolver.template_paths("godmin/resolver_test/admin/articles")
34
+ end
35
+
20
36
  def test_godmin_resolver_when_not_namespaced
21
- resolver = Resolver.new("articles", @engine_wrapper_1)
37
+ resolver = GodminResolver.new("articles", @engine_wrapper_1)
22
38
 
23
39
  assert_equal [
24
- File.join(@engine_wrapper_1.root, "app/views/resource"),
25
- File.join(Godmin::Engine.root, "app/views/godmin/articles"),
26
- File.join(Godmin::Engine.root, "app/views/godmin/resource")
40
+ "articles",
41
+ "resource"
27
42
  ], resolver.template_paths("articles")
28
43
  end
29
44
 
30
45
  def test_godmin_resolver_when_namespaced
31
- resolver = Resolver.new("godmin/resolver_test/admin/articles", @engine_wrapper_2)
46
+ resolver = GodminResolver.new("godmin/resolver_test/admin/articles", @engine_wrapper_2)
32
47
 
33
48
  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/articles"),
36
- File.join(Godmin::Engine.root, "app/views/godmin/resource")
49
+ "articles",
50
+ "resource"
37
51
  ], resolver.template_paths("godmin/resolver_test/admin/articles")
38
52
  end
39
53
  end
data/test/test_helper.rb CHANGED
@@ -4,15 +4,16 @@ CodeClimate::TestReporter.start
4
4
  # Configure Rails Environment
5
5
  ENV["RAILS_ENV"] = "test"
6
6
 
7
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
7
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
8
8
  require "rails/test_help"
9
9
  require "capybara/rails"
10
+ require "capybara/poltergeist"
10
11
  require "minitest/reporters"
11
12
  require "pry"
12
13
 
13
14
  # TODO: what to call these?
14
- require File.expand_path("../fakes/article.rb", __FILE__)
15
- require File.expand_path("../fakes/article_service.rb", __FILE__)
15
+ require File.expand_path("../fakes/article.rb", __FILE__)
16
+ require File.expand_path("../fakes/article_service.rb", __FILE__)
16
17
 
17
18
  Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(
18
19
  color: true
@@ -28,6 +29,21 @@ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
28
29
  ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
29
30
  end
30
31
 
32
+ class ActiveRecord::Base
33
+ mattr_accessor :shared_connection
34
+ @@shared_connection = nil
35
+
36
+ def self.connection
37
+ @@shared_connection || retrieve_connection
38
+ end
39
+ end
40
+
41
+ # Forces all threads to share the same connection. This works on
42
+ # Capybara because it starts the web server in a thread.
43
+ ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
44
+
45
+ Capybara.javascript_driver = :poltergeist
46
+
31
47
  class ActionDispatch::IntegrationTest
32
48
  include Capybara::DSL
33
49
 
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.0.0
4
+ version: 1.1.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: 2015-11-13 00:00:00.000000000 Z
13
+ date: 2015-12-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bcrypt
@@ -186,6 +186,20 @@ dependencies:
186
186
  - - ">="
187
187
  - !ruby/object:Gem::Version
188
188
  version: '0'
189
+ - !ruby/object:Gem::Dependency
190
+ name: minitest-reporters
191
+ requirement: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ type: :development
197
+ prerelease: false
198
+ version_requirements: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
189
203
  - !ruby/object:Gem::Dependency
190
204
  name: minitest
191
205
  requirement: !ruby/object:Gem::Requirement
@@ -201,7 +215,7 @@ dependencies:
201
215
  - !ruby/object:Gem::Version
202
216
  version: '0'
203
217
  - !ruby/object:Gem::Dependency
204
- name: minitest-reporters
218
+ name: poltergeist
205
219
  requirement: !ruby/object:Gem::Requirement
206
220
  requirements:
207
221
  - - ">="
@@ -294,6 +308,7 @@ files:
294
308
  - app/views/layouts/godmin/application.html.erb
295
309
  - app/views/layouts/godmin/login.html.erb
296
310
  - config/locales/en.yml
311
+ - config/locales/pt-BR.yml
297
312
  - config/locales/sv.yml
298
313
  - config/routes.rb
299
314
  - godmin.gemspec
@@ -327,6 +342,7 @@ files:
327
342
  - lib/godmin/paginator.rb
328
343
  - lib/godmin/resolver.rb
329
344
  - lib/godmin/resources/resource_controller.rb
345
+ - lib/godmin/resources/resource_controller/batch_actions.rb
330
346
  - lib/godmin/resources/resource_service.rb
331
347
  - lib/godmin/resources/resource_service/batch_actions.rb
332
348
  - lib/godmin/resources/resource_service/filters.rb
@@ -410,10 +426,13 @@ files:
410
426
  - test/dummy/public/favicon.ico
411
427
  - test/fakes/article.rb
412
428
  - test/fakes/article_service.rb
429
+ - test/integration/batch_actions_test.rb
413
430
  - test/integration/column_ordering_test.rb
414
431
  - test/integration/column_overriding_test.rb
415
432
  - test/integration/filter_overriding_test.rb
433
+ - test/integration/filters_test.rb
416
434
  - test/integration/partial_overriding_test.rb
435
+ - test/integration/scopes_test.rb
417
436
  - test/integration/sign_in_test.rb
418
437
  - test/integration/template_overriding_test.rb
419
438
  - test/integration/welcome_test.rb
@@ -529,10 +548,13 @@ test_files:
529
548
  - test/dummy/public/favicon.ico
530
549
  - test/fakes/article.rb
531
550
  - test/fakes/article_service.rb
551
+ - test/integration/batch_actions_test.rb
532
552
  - test/integration/column_ordering_test.rb
533
553
  - test/integration/column_overriding_test.rb
534
554
  - test/integration/filter_overriding_test.rb
555
+ - test/integration/filters_test.rb
535
556
  - test/integration/partial_overriding_test.rb
557
+ - test/integration/scopes_test.rb
536
558
  - test/integration/sign_in_test.rb
537
559
  - test/integration/template_overriding_test.rb
538
560
  - test/integration/welcome_test.rb