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.
- checksums.yaml +5 -5
- data/.gitignore +8 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +22 -0
- data/Appraisals +21 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +169 -0
- data/MIT-LICENSE +1 -1
- data/NOTES +87 -0
- data/README.md +1 -1
- data/Rakefile +1 -19
- data/app/controllers/.keep +0 -0
- data/app/views/.keep +0 -0
- data/bin/rails +12 -0
- data/gemfiles/rails_4.2.0.gemfile +13 -0
- data/gemfiles/rails_4.2.4.gemfile +13 -0
- data/gemfiles/rails_5.1.gemfile +17 -0
- data/gemfiles/rails_5.2.gemfile +17 -0
- data/lib/rows/version.rb +1 -1
- data/rows_controller.gemspec +25 -0
- data/script/rails +8 -0
- data/test/.watchr +61 -0
- data/test/controllers/order/items_controller_test.rb +64 -0
- data/test/controllers/orders_test.rb +83 -0
- data/test/controllers/rows_controller_test.rb +52 -0
- data/test/controllers/rows_ext_controller_test.rb +25 -0
- data/test/dummy3/Rakefile +6 -0
- data/test/dummy3/app/controllers/application_controller.rb +3 -0
- data/test/dummy3/app/controllers/order/items_controller.rb +8 -0
- data/test/dummy3/app/controllers/orders_controller.rb +8 -0
- data/test/dummy3/app/models/order.rb +14 -0
- data/test/dummy3/app/models/order/item.rb +4 -0
- data/test/dummy3/app/views/layouts/application.html.erb +12 -0
- data/test/dummy3/app/views/order/items/_form.html.erb +8 -0
- data/test/dummy3/app/views/orders/_form.html.erb +8 -0
- data/test/dummy3/config.ru +4 -0
- data/test/dummy3/config/application.rb +58 -0
- data/test/dummy3/config/boot.rb +10 -0
- data/test/dummy3/config/database.yml +25 -0
- data/test/dummy3/config/environment.rb +5 -0
- data/test/dummy3/config/environments/development.rb +37 -0
- data/test/dummy3/config/environments/production.rb +67 -0
- data/test/dummy3/config/environments/test.rb +37 -0
- data/test/dummy3/config/initializers/secret_token.rb +7 -0
- data/test/dummy3/config/initializers/session_store.rb +8 -0
- data/test/dummy3/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy3/config/routes.rb +9 -0
- data/test/dummy3/db/migrate/001_create_orders.rb +9 -0
- data/test/dummy3/db/migrate/002_create_order_items.rb +9 -0
- data/test/dummy3/db/schema.rb +28 -0
- data/test/dummy3/script/rails +6 -0
- data/test/dummy4/Rakefile +6 -0
- data/test/dummy4/app/controllers/application_controller.rb +3 -0
- data/test/dummy4/app/controllers/order/items_controller.rb +8 -0
- data/test/dummy4/app/controllers/orders_controller.rb +8 -0
- data/test/dummy4/app/models/order.rb +13 -0
- data/test/dummy4/app/models/order/item.rb +2 -0
- data/test/dummy4/app/views/layouts/application.html.erb +12 -0
- data/test/dummy4/app/views/order/items/_form.html.erb +8 -0
- data/test/dummy4/app/views/orders/_form.html.erb +8 -0
- data/test/dummy4/bin/bundle +3 -0
- data/test/dummy4/bin/rails +4 -0
- data/test/dummy4/bin/rake +4 -0
- data/test/dummy4/bin/setup +29 -0
- data/test/dummy4/config.ru +4 -0
- data/test/dummy4/config/application.rb +25 -0
- data/test/dummy4/config/boot.rb +5 -0
- data/test/dummy4/config/database.yml +25 -0
- data/test/dummy4/config/environment.rb +5 -0
- data/test/dummy4/config/environments/development.rb +41 -0
- data/test/dummy4/config/environments/production.rb +79 -0
- data/test/dummy4/config/environments/test.rb +42 -0
- data/test/dummy4/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy4/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy4/config/initializers/session_store.rb +3 -0
- data/test/dummy4/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy4/config/routes.rb +9 -0
- data/test/dummy4/config/secrets.yml +22 -0
- data/test/dummy4/db/migrate/001_create_orders.rb +9 -0
- data/test/dummy4/db/migrate/002_create_order_items.rb +9 -0
- data/test/dummy4/db/schema.rb +28 -0
- data/test/dummy4/log/.keep +0 -0
- data/test/dummy5/Rakefile +6 -0
- data/test/dummy5/app/controllers/application_controller.rb +3 -0
- data/test/dummy5/app/controllers/order/items_controller.rb +8 -0
- data/test/dummy5/app/controllers/orders_controller.rb +8 -0
- data/test/dummy5/app/models/application_record.rb +3 -0
- data/test/dummy5/app/models/order.rb +12 -0
- data/test/dummy5/app/models/order/item.rb +2 -0
- data/test/dummy5/app/views/layouts/application.html.erb +12 -0
- data/test/dummy5/app/views/order/items/_form.html.erb +8 -0
- data/test/dummy5/app/views/orders/_form.html.erb +8 -0
- data/test/dummy5/bin/rails +9 -0
- data/test/dummy5/config.ru +5 -0
- data/test/dummy5/config/application.rb +19 -0
- data/test/dummy5/config/boot.rb +6 -0
- data/test/dummy5/config/database.yml +25 -0
- data/test/dummy5/config/environment.rb +5 -0
- data/test/dummy5/config/environments/test.rb +42 -0
- data/test/dummy5/config/routes.rb +9 -0
- data/test/dummy5/config/secrets.yml +32 -0
- data/test/dummy5/config/spring.rb +6 -0
- data/test/dummy5/db/migrate/001_create_orders.rb +9 -0
- data/test/dummy5/db/migrate/002_create_order_items.rb +9 -0
- data/test/dummy5/db/schema.rb +27 -0
- data/test/dummy5/log/.keep +0 -0
- data/test/fixtures/order/items.yml +5 -0
- data/test/fixtures/orders.yml +5 -0
- data/test/test_helper.rb +31 -0
- metadata +231 -12
- data/app/controllers/rows_controller.rb.bak +0 -88
- 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
@@ -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
|