rows_controller 2.1.0 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +8 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +22 -0
  6. data/Appraisals +21 -0
  7. data/Gemfile +14 -0
  8. data/Gemfile.lock +169 -0
  9. data/MIT-LICENSE +1 -1
  10. data/NOTES +87 -0
  11. data/README.md +1 -1
  12. data/Rakefile +1 -19
  13. data/app/controllers/.keep +0 -0
  14. data/app/views/.keep +0 -0
  15. data/bin/rails +12 -0
  16. data/gemfiles/rails_4.2.0.gemfile +13 -0
  17. data/gemfiles/rails_4.2.4.gemfile +13 -0
  18. data/gemfiles/rails_5.1.gemfile +17 -0
  19. data/gemfiles/rails_5.2.gemfile +17 -0
  20. data/lib/rows/version.rb +1 -1
  21. data/rows_controller.gemspec +25 -0
  22. data/script/rails +8 -0
  23. data/test/.watchr +61 -0
  24. data/test/controllers/order/items_controller_test.rb +64 -0
  25. data/test/controllers/orders_test.rb +83 -0
  26. data/test/controllers/rows_controller_test.rb +52 -0
  27. data/test/controllers/rows_ext_controller_test.rb +25 -0
  28. data/test/dummy3/Rakefile +6 -0
  29. data/test/dummy3/app/controllers/application_controller.rb +3 -0
  30. data/test/dummy3/app/controllers/order/items_controller.rb +8 -0
  31. data/test/dummy3/app/controllers/orders_controller.rb +8 -0
  32. data/test/dummy3/app/models/order.rb +14 -0
  33. data/test/dummy3/app/models/order/item.rb +4 -0
  34. data/test/dummy3/app/views/layouts/application.html.erb +12 -0
  35. data/test/dummy3/app/views/order/items/_form.html.erb +8 -0
  36. data/test/dummy3/app/views/orders/_form.html.erb +8 -0
  37. data/test/dummy3/config.ru +4 -0
  38. data/test/dummy3/config/application.rb +58 -0
  39. data/test/dummy3/config/boot.rb +10 -0
  40. data/test/dummy3/config/database.yml +25 -0
  41. data/test/dummy3/config/environment.rb +5 -0
  42. data/test/dummy3/config/environments/development.rb +37 -0
  43. data/test/dummy3/config/environments/production.rb +67 -0
  44. data/test/dummy3/config/environments/test.rb +37 -0
  45. data/test/dummy3/config/initializers/secret_token.rb +7 -0
  46. data/test/dummy3/config/initializers/session_store.rb +8 -0
  47. data/test/dummy3/config/initializers/wrap_parameters.rb +14 -0
  48. data/test/dummy3/config/routes.rb +9 -0
  49. data/test/dummy3/db/migrate/001_create_orders.rb +9 -0
  50. data/test/dummy3/db/migrate/002_create_order_items.rb +9 -0
  51. data/test/dummy3/db/schema.rb +28 -0
  52. data/test/dummy3/script/rails +6 -0
  53. data/test/dummy4/Rakefile +6 -0
  54. data/test/dummy4/app/controllers/application_controller.rb +3 -0
  55. data/test/dummy4/app/controllers/order/items_controller.rb +8 -0
  56. data/test/dummy4/app/controllers/orders_controller.rb +8 -0
  57. data/test/dummy4/app/models/order.rb +13 -0
  58. data/test/dummy4/app/models/order/item.rb +2 -0
  59. data/test/dummy4/app/views/layouts/application.html.erb +12 -0
  60. data/test/dummy4/app/views/order/items/_form.html.erb +8 -0
  61. data/test/dummy4/app/views/orders/_form.html.erb +8 -0
  62. data/test/dummy4/bin/bundle +3 -0
  63. data/test/dummy4/bin/rails +4 -0
  64. data/test/dummy4/bin/rake +4 -0
  65. data/test/dummy4/bin/setup +29 -0
  66. data/test/dummy4/config.ru +4 -0
  67. data/test/dummy4/config/application.rb +25 -0
  68. data/test/dummy4/config/boot.rb +5 -0
  69. data/test/dummy4/config/database.yml +25 -0
  70. data/test/dummy4/config/environment.rb +5 -0
  71. data/test/dummy4/config/environments/development.rb +41 -0
  72. data/test/dummy4/config/environments/production.rb +79 -0
  73. data/test/dummy4/config/environments/test.rb +42 -0
  74. data/test/dummy4/config/initializers/cookies_serializer.rb +3 -0
  75. data/test/dummy4/config/initializers/filter_parameter_logging.rb +4 -0
  76. data/test/dummy4/config/initializers/session_store.rb +3 -0
  77. data/test/dummy4/config/initializers/wrap_parameters.rb +14 -0
  78. data/test/dummy4/config/routes.rb +9 -0
  79. data/test/dummy4/config/secrets.yml +22 -0
  80. data/test/dummy4/db/migrate/001_create_orders.rb +9 -0
  81. data/test/dummy4/db/migrate/002_create_order_items.rb +9 -0
  82. data/test/dummy4/db/schema.rb +28 -0
  83. data/test/dummy4/log/.keep +0 -0
  84. data/test/dummy5/Rakefile +6 -0
  85. data/test/dummy5/app/controllers/application_controller.rb +3 -0
  86. data/test/dummy5/app/controllers/order/items_controller.rb +8 -0
  87. data/test/dummy5/app/controllers/orders_controller.rb +8 -0
  88. data/test/dummy5/app/models/application_record.rb +3 -0
  89. data/test/dummy5/app/models/order.rb +12 -0
  90. data/test/dummy5/app/models/order/item.rb +2 -0
  91. data/test/dummy5/app/views/layouts/application.html.erb +12 -0
  92. data/test/dummy5/app/views/order/items/_form.html.erb +8 -0
  93. data/test/dummy5/app/views/orders/_form.html.erb +8 -0
  94. data/test/dummy5/bin/rails +9 -0
  95. data/test/dummy5/config.ru +5 -0
  96. data/test/dummy5/config/application.rb +19 -0
  97. data/test/dummy5/config/boot.rb +6 -0
  98. data/test/dummy5/config/database.yml +25 -0
  99. data/test/dummy5/config/environment.rb +5 -0
  100. data/test/dummy5/config/environments/test.rb +42 -0
  101. data/test/dummy5/config/routes.rb +9 -0
  102. data/test/dummy5/config/secrets.yml +32 -0
  103. data/test/dummy5/config/spring.rb +6 -0
  104. data/test/dummy5/db/migrate/001_create_orders.rb +9 -0
  105. data/test/dummy5/db/migrate/002_create_order_items.rb +9 -0
  106. data/test/dummy5/db/schema.rb +27 -0
  107. data/test/dummy5/log/.keep +0 -0
  108. data/test/fixtures/order/items.yml +5 -0
  109. data/test/fixtures/orders.yml +5 -0
  110. data/test/test_helper.rb +31 -0
  111. metadata +231 -12
  112. data/app/controllers/rows_controller.rb.bak +0 -88
  113. data/lib/rows/resources.rb.bak +0 -80
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.2.0"
6
+
7
+ group :test do
8
+ gem "rails-controller-testing"
9
+ gem "observr"
10
+ gem "simplecov", require: false
11
+ gem "minitest"
12
+ gem "capybara"
13
+ gem "sqlite3"
14
+ gem "slim"
15
+ end
16
+
17
+ gemspec path: "../"
data/lib/rows/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rows
2
- VERSION = '2.1.0'
2
+ VERSION = '2.1.2'
3
3
  end
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "rows/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'rows_controller'
7
+ s.version = Rows::VERSION
8
+ s.summary = 'RowsController DRYs your controllers.'
9
+ s.description = 'YourController < RowsController ( < ApplicationController).'
10
+ s.authors = ['Dittmar Krall']
11
+ s.email = ['dittmar.krall@matique.de']
12
+ s.homepage = 'http://matique.de'
13
+
14
+ s.license = 'MIT'
15
+ s.platform = Gem::Platform::RUBY
16
+
17
+ s.files = `git ls-files -z`.split("\x0")
18
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
+ s.require_paths = ['lib']
20
+
21
+ s.add_development_dependency 'bundler', '~> 1'
22
+ s.add_development_dependency 'rake', '~> 12'
23
+ s.add_development_dependency 'appraisal', '~> 2'
24
+ # s.add_development_dependency 'combustion', '~> 0'
25
+ end
data/script/rails ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/rows/engine', __FILE__)
6
+
7
+ require 'rails/all'
8
+ require 'rails/engine/commands'
data/test/.watchr ADDED
@@ -0,0 +1,61 @@
1
+ HH = '#' * 22 unless defined?(HH)
2
+ H = '#' * 5 unless defined?(H)
3
+
4
+ def usage
5
+ puts <<-EOS
6
+ Ctrl-\\ or ctrl-4 Running all tests
7
+ Ctrl-C Exit
8
+ EOS
9
+ end
10
+
11
+ def run(cmd)
12
+ puts "#{HH} #{Time.now} #{HH}"
13
+ puts "#{H} #{cmd}"
14
+ system "/usr/bin/time --format '#{HH} Elapsed time %E' #{cmd}"
15
+ end
16
+
17
+ def run_it(type, file)
18
+ case type
19
+ # when 'test'; run %Q{ruby -I"lib:test" -rubygems #{file}}
20
+ when 'test'; run %Q{rails test #{file}}
21
+ when 'spec'; run %Q{rspec -X #{file}}
22
+ else; puts "#{H} unknown type: #{type}, file: #{file}"
23
+ end
24
+ end
25
+
26
+ def run_all_tests
27
+ puts "\n#{HH} Running all tests #{HH}\n"
28
+ # system "spring stop"
29
+ %w{test spec}.each { |dir| run "rails #{dir}" if File.exists?(dir) }
30
+ end
31
+
32
+ def run_matching_files(base)
33
+ base = base.split('_').first
34
+ %w{test spec}.each { |type|
35
+ files = Dir["#{type}/**/*.rb"].select { |file| file =~ /#{base}_.*\.rb/ }
36
+ run_it type, files.join(' ') unless files.empty?
37
+ }
38
+ end
39
+
40
+ %w{test spec}.each { |type|
41
+ watch("#{type}/#{type}_helper\.rb") { run_all_tests }
42
+ watch("#{type}/.*/*_#{type}\.rb") { |match| run_it type, match[0] }
43
+ watch("#{type}/data/(.*)\.rb") { |match|
44
+ m1 = match[1]
45
+ run_matching_files("#{type}/#{m1}/#{m1}_#{type}.rb")
46
+ }
47
+ }
48
+ %w{rb erb haml slim}.each { |type|
49
+ watch("app/.*/(.*)\.#{type}") { |match|
50
+ run_matching_files(match[1])
51
+ }
52
+ }
53
+ Dir['**/*.rb'].find_all{ |x| !(x =~ /_test\.rb$/) }.each { |name|
54
+ watch(name) { run_all_tests }
55
+ }
56
+
57
+ # Ctrl-\ or ctrl-4
58
+ Signal.trap('QUIT') { run_all_tests }
59
+ # Ctrl-C
60
+ Signal.trap('INT') { abort("Interrupted\n") }
61
+ usage
@@ -0,0 +1,64 @@
1
+ # mostly generated by Rails
2
+
3
+ require 'test_helper'
4
+
5
+ class Order::ItemsControllerTest < ActionController::TestCase
6
+ fixtures :all
7
+
8
+ def setup
9
+ @order_item = order_items(:one)
10
+ end
11
+
12
+ test 'checking model_...' do
13
+ get :index
14
+ assert_equal Order::Item, @controller.send(:model_class)
15
+ assert_equal 'Order::Item', @controller.send(:model_name)
16
+ assert_equal 'order_item', @controller.send(:model_symbol)
17
+ assert_equal 'order_items', @controller.send(:model_symbol_plural)
18
+ end
19
+
20
+ test "should get index" do
21
+ get :index
22
+ assert_response :success
23
+ assert_not_nil assigns(:order_items)
24
+ end
25
+
26
+ test "should get new" do
27
+ get :new
28
+ assert_response :success
29
+ end
30
+
31
+ test "should create order_item" do
32
+ assert_difference('Order::Item.count') do
33
+ post :create, params: { order_item: { price: @order_item.price } }
34
+ end
35
+
36
+ ## assert_redirected_to order_item_path(assigns(:order_item))
37
+ assert_redirected_to edit_order_item_path(assigns(:order_item))
38
+ end
39
+
40
+ test "should show order_item" do
41
+ get :show, params: { id: @order_item }
42
+ assert_response :success
43
+ end
44
+
45
+ test "should get edit" do
46
+ get :edit, params: { id: @order_item }
47
+ assert_response :success
48
+ end
49
+
50
+ test "should update order_item" do
51
+ put :update, params: { id: @order_item,
52
+ order_item: { price: @order_item.price } }
53
+ ## assert_redirected_to order_item_path(assigns(:order_item))
54
+ assert_redirected_to edit_order_item_path(assigns(:order_item))
55
+ end
56
+
57
+ test "should destroy order_item" do
58
+ assert_difference('Order::Item.count', -1) do
59
+ delete :destroy, params: { id: @order_item }
60
+ end
61
+
62
+ assert_redirected_to order_items_path
63
+ end
64
+ end
@@ -0,0 +1,83 @@
1
+ require 'test_helper'
2
+
3
+ class OrdersControllerTest < ActionController::TestCase
4
+ #class OrdersControllerTest < ActionDispatch::IntegrationTest
5
+ #class OrdersControllerTest < ActiveSupport::TestCase
6
+ fixtures :all
7
+
8
+ def setup
9
+ @order = orders(:one)
10
+ end
11
+
12
+ %i{ index new }.each do |action|
13
+ test "renders the '#{action}' template" do
14
+ get action
15
+ assert_response :success
16
+ assert_template "rows/#{action}"
17
+ assert_match(/Order/, response.body)
18
+ end
19
+ end
20
+
21
+ %i{ edit show }.each do |action|
22
+ test "renders the '#{action}' template" do
23
+ get action, params: { id: @order.id }
24
+ assert_response :success
25
+ assert_template "rows/#{action}"
26
+ assert_match(/Order/, response.body)
27
+ end
28
+ end
29
+
30
+ test 'checking resource' do
31
+ get :show, params: { id: @order.id }
32
+ assert_equal @order, @controller.send(:resource)
33
+ assert_equal @order, assigns(:order)
34
+ assert_equal @order, assigns(:row)
35
+ end
36
+
37
+ test 'checking resources' do
38
+ get :index
39
+ assert_kind_of Array, @controller.send(:resources).to_a
40
+ assert_kind_of Array, assigns(:orders).to_a
41
+ assert_kind_of Array, assigns(:rows).to_a
42
+ assert_equal Order.all, assigns(:orders)
43
+ end
44
+
45
+ test 'checking model_class' do
46
+ get :show, params: { id: @order.id }
47
+ assert_equal Order, @controller.send(:model_class)
48
+ assert_equal 'Order', @controller.send(:model_name)
49
+ assert_equal 'order', @controller.send(:model_symbol)
50
+ assert_equal 'orders', @controller.send(:model_symbol_plural)
51
+ end
52
+
53
+ test "should create order #2" do
54
+ assert_difference('Order.count') do
55
+ post :create, params: { commit: 'OK', order: { name: @order.name } }
56
+ end
57
+ end
58
+
59
+ test 'should update' do
60
+ put :update, params: { id: @order.id, order: {name: 'name'} }
61
+ assert response
62
+ assert_redirected_to(action: :edit)
63
+ end
64
+
65
+ test 'should update #2' do
66
+ put :update, params: {id: @order.id, commit: 'OK', order: {name: 'name'}}
67
+ assert response
68
+ assert_redirected_to(action: :index)
69
+ end
70
+
71
+ test 'should not update' do
72
+ put :update, params: { id: @order.id, order: {name: 'error'} }
73
+ assert_response :success
74
+ assert_template 'rows/edit'
75
+ end
76
+
77
+ test 'should not create' do
78
+ post :create, params: { id: @order.id, order: {name: 'error'} }
79
+ assert_response :success
80
+ assert_template 'rows/new'
81
+ end
82
+
83
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+
3
+ class RowsControllerTest < ActionController::TestCase
4
+ test 'respond resource' do
5
+ test_response %i{ resource resources set_resource set_resources }
6
+ end
7
+
8
+ test 'respond model' do
9
+ test_response %i{ model_class }
10
+ end
11
+
12
+ test 'respond resource format' do
13
+ test_response %i{ resource_format }
14
+ end
15
+
16
+
17
+ test 'respond action' do
18
+ test_response %i{ index new create show edit update destroy }
19
+ end
20
+
21
+ test 'coverage resource_format' do
22
+ assert_equal 'abc', @controller.send(:resource_format, 'abc')
23
+ end
24
+
25
+ test 'available public methods' do
26
+ list = %i{create destroy edit index new show update}
27
+ assert_equal list.sort, @controller.public_methods(false).sort
28
+ end
29
+
30
+ test 'exposed resource private methods' do
31
+ list = %i{resource resource_format resources set_resource set_resources}
32
+ assert_equal list.sort, filter(@controller.public_methods, 'resource')
33
+ end
34
+
35
+ test 'exposed model_ private methods' do
36
+ list = %i{model_class model_name model_symbol model_symbol_plural}
37
+ got = filter(@controller.public_methods, 'model_')
38
+ assert_equal list.sort, (list & got).sort
39
+ end
40
+
41
+ private
42
+ def filter(x, criteria)
43
+ x.map(&:to_s).sort.find_all { |y| y =~ /#{criteria}/ }.map(&:to_sym).sort
44
+ end
45
+
46
+ def test_response(list)
47
+ list.each { |x|
48
+ assert @controller.respond_to?(x), "controller don't respond to #{x}"
49
+ }
50
+ end
51
+
52
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ class OrdersControllerTest < ActionController::TestCase
4
+ #class OrdersControllerTest < ActionDispatch::IntegrationTest
5
+ #class OrdersControllerTest < ActiveSupport::TestCase
6
+
7
+ test 'respond to :copy' do
8
+ assert @controller.respond_to?(:copy)
9
+ order = Order.create :name => 'name'
10
+ # n = Order.all.length
11
+ Order.all.length
12
+
13
+ put :copy, params: { id: order.id }
14
+ assert_response :success
15
+ assert_template 'rows/new'
16
+ assert_match(/New Order/, response.body)
17
+ end
18
+
19
+ test 'coverage: multi deletion' do
20
+ delete :multi_deletion
21
+ assert response
22
+ assert_redirected_to orders_url
23
+ end
24
+
25
+ end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Dummy::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,8 @@
1
+ class Order::ItemsController < RowsController
2
+
3
+ private
4
+ def resource_whitelist
5
+ %i{ price }
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ class OrdersController < RowsExtController
2
+
3
+ private
4
+ def resource_whitelist
5
+ %i{ name }
6
+ end
7
+
8
+ end
@@ -0,0 +1,14 @@
1
+ class Order < ActiveRecord::Base
2
+ attr_accessible :name
3
+
4
+ before_save :err
5
+
6
+ protected
7
+ def err
8
+ return true unless name == 'error'
9
+
10
+ self.errors.add :base, 'panic'
11
+ return false
12
+ end
13
+
14
+ end
@@ -0,0 +1,4 @@
1
+ class Order::Item < ActiveRecord::Base
2
+ attr_accessible :price
3
+
4
+ end
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+ </head>
7
+ <body>
8
+
9
+ <%= yield %>
10
+
11
+ </body>
12
+ </html>
@@ -0,0 +1,8 @@
1
+ <%
2
+ # This is a typical form
3
+ # Requires f
4
+ %>
5
+ <div class="field">
6
+ <%= f.label :price %><br />
7
+ <%= f.text_field :price %>
8
+ </div>
@@ -0,0 +1,8 @@
1
+ <%
2
+ # This is a typical form
3
+ # Requires f
4
+ %>
5
+ <div class="field">
6
+ <%= f.label :name %><br />
7
+ <%= f.text_field :name %>
8
+ </div>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application