rows_controller 1.1.9 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +19 -0
  3. data/.watchr +55 -0
  4. data/Appraisals +7 -0
  5. data/MIT-LICENSE +1 -1
  6. data/README.md +29 -16
  7. data/Rakefile +21 -12
  8. data/app/controllers/rows_controller.rb +47 -62
  9. data/lib/rows_controller/locales/de.yml +2 -2
  10. data/lib/rows_controller/model.rb +20 -0
  11. data/lib/rows_controller/resources.rb +78 -0
  12. data/lib/rows_controller/utils.rb +19 -0
  13. data/lib/rows_controller/version.rb +1 -1
  14. data/lib/rows_controller.rb +4 -2
  15. data/test/controllers/order/items_controller_test.rb +53 -0
  16. data/test/controllers/orders_controller_test.rb +53 -0
  17. data/test/controllers/orders_test.rb +93 -0
  18. data/test/controllers/rows_controller_test.rb +52 -0
  19. data/test/controllers/rows_ext_controller_test.rb +22 -0
  20. data/test/dummy/Rakefile +6 -0
  21. data/test/dummy/app/controllers/application_controller.rb +5 -0
  22. data/test/dummy/app/controllers/order/items_controller.rb +8 -0
  23. data/test/dummy/app/controllers/orders_controller.rb +8 -0
  24. data/test/dummy/app/models/order/item.rb +2 -0
  25. data/test/dummy/app/models/order.rb +11 -0
  26. data/test/dummy/app/views/layouts/application.html.erb +12 -0
  27. data/test/dummy/app/views/order/items/_form.html.erb +8 -0
  28. data/test/dummy/app/views/orders/_form.html.erb +8 -0
  29. data/test/dummy/bin/bundle +3 -0
  30. data/test/dummy/bin/rails +4 -0
  31. data/test/dummy/bin/rake +4 -0
  32. data/test/dummy/bin/setup +29 -0
  33. data/test/dummy/config/application.rb +26 -0
  34. data/test/dummy/config/boot.rb +5 -0
  35. data/test/dummy/config/database.yml +25 -0
  36. data/test/dummy/config/environment.rb +5 -0
  37. data/test/dummy/config/environments/development.rb +41 -0
  38. data/test/dummy/config/environments/production.rb +79 -0
  39. data/test/dummy/config/environments/test.rb +42 -0
  40. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  41. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  42. data/test/dummy/config/initializers/session_store.rb +3 -0
  43. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  44. data/test/dummy/config/routes.rb +9 -0
  45. data/test/dummy/config/secrets.yml +22 -0
  46. data/test/dummy/config.ru +4 -0
  47. data/test/dummy/db/development.sqlite3 +0 -0
  48. data/test/dummy/db/migrate/001_create_orders.rb +9 -0
  49. data/test/dummy/db/migrate/002_create_order_items.rb +9 -0
  50. data/test/dummy/db/schema.rb +28 -0
  51. data/test/dummy/db/test.sqlite3 +0 -0
  52. data/test/dummy/tmp/restart.txt +0 -0
  53. data/test/fixtures/order/items.yml +5 -0
  54. data/test/fixtures/orders.yml +5 -0
  55. data/test/test_helper.rb +27 -0
  56. metadata +95 -21
  57. data/app/controllers/rows_controller/helpers.rb +0 -114
  58. data/app/controllers/rows_ext_controller.rb.bak +0 -18
  59. data/lib/rows_controller/version.rb.bak +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93f715b348e2399eaa011180ec14a6243cd763df
4
- data.tar.gz: 98dbeaa2ff0af947ca08bd4e4a65ffdd0921055d
3
+ metadata.gz: afd501f680af68257cdd2a7f5df5874862667259
4
+ data.tar.gz: ec22cd6d7a4f72057d1712065c1310313d9bb1f9
5
5
  SHA512:
6
- metadata.gz: 960b5fe48bea5173276f620aaf5edf071b951ca2317e10681613d9f20859f0b48d4dfdce40f24fce362fdc1ad1f85c2928e9973b18c578143024fbdade3a67f7
7
- data.tar.gz: 69fb060f123c9bc6f12b34c4b82269aacd83d5e6e11165ab491afc902d8289aa83c0e641b94685535af5e8b808ec30cacce433de3a7b5ae2745cf6485ef3d061
6
+ metadata.gz: 757d0fb0008aa4f1115203f554e18a57fcb76ac0159871754766fc0d6f92bbd3c3415dcc1090cebe76d823dc3d26c2bda2002c114e2f01a02bf5c0974b7525b5
7
+ data.tar.gz: f310dc6c707b4a8d4aea2ecb005c9d02baa167f3dbc0d08748c1224f42b52bb976582c917ed1c5519d44361621dc453a4a9da4eba58585a0347a04222d1a1e71
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ # - 2.0.0 # OK for Rails 4.2.4
5
+ # - 2.2.0
6
+ - 2.2.3
7
+
8
+ gemfile:
9
+ - gemfiles/rails_4.2.4.gemfile
10
+
11
+ matrix:
12
+ include:
13
+ # fails due to test/dummy/config/environments/test.rb
14
+ # - rvm: 1.9.3 # or 2.0.0
15
+ # gemfile: gemfiles/rails-3.2.16.gemfile
16
+ exclude:
17
+
18
+ notifications:
19
+ email: false
data/.watchr ADDED
@@ -0,0 +1,55 @@
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 'spec'; run %Q{rspec -X #{file}}
21
+ else; puts "#{H} unknown type: #{type}, file: #{file}"
22
+ end
23
+ end
24
+
25
+ def run_all_tests
26
+ puts "\n#{HH} Running all tests #{HH}\n"
27
+ %w{test spec}.each { |dir| run "rake #{dir} RAILS_ENV=test" if File.exists?(dir) }
28
+ end
29
+
30
+ def run_matching_files(base)
31
+ base = base.split('_').first
32
+ %w{test spec}.each { |type|
33
+ files = Dir["#{type}/**/*.rb"].select { |file| file =~ /#{base}_.*\.rb/ }
34
+ run_it type, files.join(' ') unless files.empty?
35
+ }
36
+ end
37
+
38
+ %w{test spec}.each { |type|
39
+ watch("#{type}/#{type}_helper\.rb") { run_all_tests }
40
+ watch("#{type}/.*/*_#{type}\.rb") { |match| run_it type, match[0] }
41
+ }
42
+ #%w{rb erb haml slim}.each { |type|
43
+ # watch("app/.*/.*\.#{type}") { |m|
44
+ # run_matching_files("#{m[0].split('/').at(2).split('.').first}")
45
+ # }
46
+ #}
47
+ Dir['**/*.rb'].find_all{ |x| !(x =~ /_test\.rb$/) }.each { |name|
48
+ watch(name) { run_all_tests }
49
+ }
50
+
51
+ # Ctrl-\ or ctrl-4
52
+ Signal.trap('QUIT') { run_all_tests }
53
+ # Ctrl-C
54
+ Signal.trap('INT') { abort("Interrupted\n") }
55
+ usage
data/Appraisals ADDED
@@ -0,0 +1,7 @@
1
+ #appraise "rails-3.2" do
2
+ # gem "rails", "3.2.16"
3
+ #end
4
+
5
+ appraise "rails-4.2.4" do
6
+ gem "rails", "4.2.4"
7
+ end
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2009-2013 Dittmar Krall - http://matique.de
1
+ Copyright 2009-2015 Dittmar Krall http://matique.de
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  RowsController
2
2
  ==============
3
- [![Gem Version](https://badge.fury.io/rb/rows_controller.png)](http://badge.fury.io/rb/rows_controller)
3
+ [![Gem Version](https://badge.fury.io/rb/rows_controller.svg)](https://badge.fury.io/rb/rows_controller)
4
4
  [![Build Status](https://travis-ci.org/matique/rows_controller.png?branch=master)](https://travis-ci.org/matique/rows_controller)
5
5
 
6
6
  DRYs Rails controllers. Imagine replacing that @order by 'resource' in the
@@ -8,35 +8,48 @@ controllers/views and, imho, an area for DRYing appears.
8
8
  Instead of:
9
9
 
10
10
  class OrdersController < ApplicationController
11
- ...
11
+ .....
12
+ private
13
+ def order_params
14
+ params.require(:order).permit(:name)
15
+ end
16
+ end
12
17
 
13
18
  use:
14
19
 
15
20
  class OrdersController < RowsController # < ApplicationController
21
+ private
22
+ def resource_whitelist
23
+ %i{ name }
24
+ end
25
+ end
16
26
 
27
+ I.e. RowsController defines all the usual methods (index, show, edit,...).
17
28
 
18
- The OrdersController may end there as RowsController has all the usual
19
- methods (index, show, edit,...).
20
-
21
- The methods may be redefined in OrdersController overwritting the
29
+ The methods may be redefined in OrdersController overwriting the
22
30
  methods from RowsController.
23
31
 
24
32
  Low level methods like 'resources' may be redefined as well.
25
33
  An example:
26
34
 
27
35
  def resources
28
- @_resources ||= model_class.paginate(:page => params[:page])
36
+ @_resources ||= model_class.paginate(page: params[:page])
29
37
  end
30
38
 
31
39
  RowsController inherites from ApplicationController, i.e. all the helpers
32
40
  defined there will be available.
33
41
 
34
42
 
35
- Customization of views
36
- ----------------------
43
+ Customizing of views
44
+ --------------------
45
+
46
+ RowsController initializes some instance variables used in the views
47
+ (e.g. @order, @orders; legacy @row & @rows are still supported).
48
+ Furthermore, the helpers resource, resources, set_resource and
49
+ set_resources are available. You guess their usage.
37
50
 
38
51
  Providing e.g. an "#{Rails.root}/app/views/order/index.html.erb"
39
- overwrites the default Rows view as Rails will first look
52
+ overwrites the default RowsController view as Rails will first look
40
53
  into the directory "#{Rails.root}/app/views" before looking
41
54
  into the RowsController.
42
55
 
@@ -52,20 +65,21 @@ be changed by e.g.:
52
65
 
53
66
  class OrdersController < RowsController
54
67
  model_class Booking
68
+ ...
55
69
 
56
- The model class can be retrieved with model_class.
70
+ The model class can be retrieved with the helper model_class.
57
71
 
58
72
 
59
73
  Rails 4
60
74
  -------
61
75
 
62
76
  This gem is intended for Rails 4.
63
- For older Rails versions feel free to switch to "gem 'rows_controller', '= 0.4.4'".
77
+ Older Rails versions may use "gem 'rows_controller', '= 1.1.9'".
64
78
 
65
79
  Rails 4 introduced strong parameters.
66
80
  To support them a private method 'resource_whitelist' is required
67
81
  in the controllers.
68
- Alternatively you may define a private method 'resource_params'
82
+ Alternatively you may define the private method 'resource_params'
69
83
  in the controller to filter params.
70
84
 
71
85
 
@@ -81,7 +95,7 @@ The "id" of the cloned resource is set to nil.
81
95
  Usage of "copy" requires a defining in config/routes.rb. An example:
82
96
 
83
97
  resources :orders
84
- get 'copy', :on => :member
98
+ get 'copy', on: :member
85
99
  end
86
100
 
87
101
  ### columns
@@ -111,5 +125,4 @@ Look for:
111
125
  - inherited_resources
112
126
  - decent_exposure
113
127
 
114
-
115
- Copyright (c) 2009-2014 [Dittmar Krall], released under the MIT license
128
+ Copyright (c) 2009-2015 [Dittmar Krall], released under the MIT license.
data/Rakefile CHANGED
@@ -1,17 +1,26 @@
1
- require File.expand_path('../test/dummy/config/application', __FILE__)
1
+ require "rubygems"
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
10
+ load 'rails/tasks/engine.rake'
11
+
12
+ load 'rails/tasks/statistics.rake'
2
13
 
3
- Rails.application.load_tasks
4
14
  Bundler::GemHelper.install_tasks
5
15
 
6
- desc "Clean automatically generated files"
7
- task :clean do
8
- FileUtils.rm_rf "pkg"
9
- end
16
+ require 'rake/testtask'
10
17
 
11
- desc "Check syntax"
12
- task :syntax do
13
- Dir["**/*.rb"].each do |file|
14
- print "#{file}: "
15
- system("ruby -c #{file}")
16
- end
18
+ Rake::TestTask.new(:test) do |t|
19
+ puts "Ruby version: #{RUBY_VERSION}"
20
+ t.libs << 'lib'
21
+ t.libs << 'test'
22
+ t.pattern = 'test/**/*_test.rb'
23
+ t.verbose = false
17
24
  end
25
+
26
+ task default: :test
@@ -1,17 +1,31 @@
1
- RAILS4 = Rails.version.to_i == 4
2
-
1
+ require 'rows_controller/resources'
2
+ require 'rows_controller/model'
3
+ require 'rows_controller/utils'
3
4
 
4
5
  class RowsController < ApplicationController
5
- require_dependency 'rows_controller/helpers'
6
+ before_action :set_resource, only: [:show, :edit, :update, :destroy]
7
+
8
+ helper_method :set_resource, :set_resources, :resource, :resources
9
+ helper_method :resource_columns, :resource_format
10
+ helper_method :model_class, :model_name
11
+ helper_method :model_symbol, :model_symbol_plural
12
+
13
+ include Rows::Model
14
+ include Rows::Resources
15
+ include Rows::Utils
16
+
17
+ def self.model_class(model_class = nil)
18
+ @_model_class = model_class unless model_class.nil?
19
+ @_model_class
20
+ end
6
21
 
7
22
  # GET /:resources[.json]
8
23
  def index
9
24
  set_resources
10
25
  end
11
26
 
12
- # GET /:resource/1[.json]
27
+ # GET /:resource/:id[.json]
13
28
  def show
14
- set_resource
15
29
  end
16
30
 
17
31
  # GET /:resource/new
@@ -19,81 +33,52 @@ class RowsController < ApplicationController
19
33
  resource_new
20
34
  end
21
35
 
22
- # GET /:resource/1/edit
36
+ # GET /:resource/:id/edit
23
37
  def edit
24
- set_resource
25
38
  end
26
39
 
27
- # POST /:resources.json
40
+ # POST /:resources[.json]
28
41
  def create
29
- respond_to do |format|
30
- if resource_create
31
- flash[:notice] = t('ui.created', model: model_name,
32
- default: "%{model} created.").html_safe
33
- format.html {
34
- if params[:commit] == 'OK'
35
- redirect_to_index
36
- else
37
- redirect_to action: 'edit', id: resource.id
38
- end
39
- }
40
- format.json { render action: 'show', status: :created, location: resource }
41
- else
42
- format.html { render action: 'new' }
43
- format.json { render json: resource.errors, status: :unprocessable_entity }
44
- end
45
- end
42
+ create_update(:resource_create, 'created')
46
43
  end
47
44
 
48
- # PATCH/PUT /:resources/1[.json]
45
+ # PATCH/PUT /:resources/:id[.json]
49
46
  def update
50
- set_resource
51
- respond_to do |format|
52
- if resource_update
53
- flash[:notice] = t('ui.updated', model: model_name).html_safe
54
- format.html {
55
- if params[:commit] == 'OK'
56
- redirect_to_index
57
- else
58
- redirect_to action: 'edit'
59
- end
60
- }
61
- format.json { head :no_content }
62
- else
63
- format.html { render action: 'edit' }
64
- format.json { render json: resource.errors, status: :unprocessable_entity }
65
- end
66
- end
47
+ create_update(:resource_update, 'updated')
67
48
  end
68
49
 
69
- # DELETE /:resources/1[.json]
50
+ # DELETE /:resources/:id[.json]
70
51
  def destroy
71
- set_resource
72
52
  resource_destroy
73
53
  flash[:notice] = t('ui.destroyed', model: model_name).html_safe unless request.xhr?
74
54
  respond_to do |format|
75
- format.html { redirect_to_index }
76
- format.js { render template: 'rows/destroy', layout: false }
55
+ format.html { redirect_to action: :index }
56
+ format.js { render template: 'rows_controller/destroy', layout: false }
77
57
  format.json { head :no_content }
78
58
  end
79
59
  end
80
60
 
81
-
82
61
  private
83
- # Never trust parameters from the scary internet, only allow the white list through.
84
- def resource_params
85
- permits = resource_whitelist
86
- if RAILS4
87
- params.require(model_symbol).permit(permits)
88
- else
89
- pars = params[model_symbol] || {}
90
- pars.keys.each { |x|
91
- unless permits.include?(x) || permits.include?({x.to_sym => []})
92
- pars.delete(x)
93
- p "** WARNING: model <#{model_name}> dropping params <#{x}>"
94
- end
95
- }
96
- pars
62
+ def create_update(which, msg)
63
+ respond_to do |format|
64
+ if self.send(which)
65
+ format.html {
66
+ flash[:notice] = t(msg, scope: :ui, model: model_name,
67
+ default: "%{model} was successfully #{msg}.").html_safe
68
+ if params[:commit] == 'OK'
69
+ redirect_to action: :index
70
+ else
71
+ redirect_to action: 'edit', id: resource.id
72
+ end
73
+ }
74
+ format.json { render action: 'show',
75
+ status: msg == 'created' ? :created : :ok,
76
+ location: resource }
77
+ else ## failed
78
+ format.html { render action: msg == 'created' ? :new : :edit }
79
+ format.json { render json: resource.errors,
80
+ status: :unprocessable_entity }
81
+ end
97
82
  end
98
83
  end
99
84
 
@@ -8,10 +8,10 @@ de:
8
8
 
9
9
  editing: 'Editiere %{model}'
10
10
  listing: 'Liste %{model}'
11
- new: 'Neu %{model}'
11
+ new: 'Neue(r/s) %{model}'
12
12
  showing: 'Zeige %{model}'
13
13
 
14
- empty_list: 'Liste %{model} is leer.'
14
+ empty_list: 'Liste %{model} ist leer.'
15
15
 
16
16
  button:
17
17
  back: "Zur&uuml;ck"
@@ -0,0 +1,20 @@
1
+ module Rows::Model
2
+
3
+ def model_class
4
+ @_model_class ||= self.class.model_class ||
5
+ params[:controller].singularize.camelize.constantize
6
+ end
7
+
8
+ def model_name
9
+ @_model_name ||= model_class.model_name.name
10
+ end
11
+
12
+ def model_symbol
13
+ @_model_symbol ||= model_class.model_name.singular
14
+ end
15
+
16
+ def model_symbol_plural
17
+ @_model_symbol_plural ||= model_class.model_name.plural
18
+ end
19
+
20
+ end
@@ -0,0 +1,78 @@
1
+ module Rows::Resources
2
+
3
+ def set_resources(rows = nil)
4
+ rows ||= model_class.all
5
+ instance_variable_set("@#{model_symbol_plural}", rows)
6
+ @rows = rows
7
+ end
8
+
9
+ def set_resource(row = nil)
10
+ row ||= model_class.find_by_id(params[:id].to_i)
11
+ instance_variable_set("@#{model_symbol}", row)
12
+ @row = row
13
+ end
14
+
15
+ def resources
16
+ @rows || set_resources
17
+ end
18
+
19
+ def resource
20
+ @row || set_resource
21
+ end
22
+
23
+ private
24
+ # low level resource methods
25
+ # can be monkey patched
26
+ def resource_new
27
+ if params[model_symbol]
28
+ set_resource model_class.new(resource_params)
29
+ else
30
+ set_resource model_class.new
31
+ end
32
+ end
33
+
34
+ def resource_create
35
+ resource_new
36
+ resource.save
37
+ end
38
+
39
+ def resource_update
40
+ if Rails::VERSION::MAJOR >= 4
41
+ resource.update(resource_params)
42
+ else
43
+ resource.update_attributes(resource_params)
44
+ end
45
+ end
46
+
47
+ def resource_destroy
48
+ resource.destroy
49
+ end
50
+
51
+ def resource_columns
52
+ return model_class.column_headers if model_class.respond_to?(:column_headers)
53
+ return ['to_s'] unless model_class.respond_to?(:content_columns)
54
+ ['id'] + model_class.content_columns.collect{|c| c.name }
55
+ end
56
+
57
+ def resource_whitelist
58
+ raise "RowsController requires private method 'resource_whitelist' in controller <#{params[:controller]}>"
59
+ end
60
+
61
+ # Never trust parameters from the scary internet, only allow the white list through.
62
+ def resource_params
63
+ permits = resource_whitelist
64
+ if params.respond_to?(:require)
65
+ params.require(model_symbol).permit(permits)
66
+ else
67
+ pars = params[model_symbol] || {}
68
+ pars.keys.each { |x|
69
+ unless permits.include?(x) || permits.include?({x.to_sym => []})
70
+ pars.delete(x)
71
+ p "** WARNING: model <#{model_name}> dropping params <#{x}>"
72
+ end
73
+ }
74
+ pars
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,19 @@
1
+ module Rows::Utils
2
+
3
+ # formatting
4
+ def resource_format(x)
5
+ return '--'.html_safe if x.nil?
6
+ bool = x.class == Time || x.class == Date || x.class == DateTime ||
7
+ x.class == ActiveSupport::TimeWithZone
8
+ return x.strftime('%d.%m.%Y').html_safe if bool
9
+ # return I18n.l(x) if bool
10
+ return x.to_s.html_safe if x.class == Fixnum
11
+ return 'X'.html_safe if x.class == TrueClass
12
+ return '&ensp;'.html_safe if x.class == FalseClass
13
+ return x.call if x.class == Proc
14
+ return '---'.html_safe if x.empty?
15
+ str = x.to_s
16
+ return str.gsub(/\r*\n/, '<br/>')
17
+ end
18
+
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Rows
2
- VERSION = "1.1.9"
2
+ VERSION = "2.0.3"
3
3
  end
@@ -1,6 +1,8 @@
1
- require 'rows_controller/engine.rb'
1
+ require 'rows_controller/engine'
2
+
3
+ module Rows
4
+ end
2
5
 
3
- require 'active_support/i18n'
4
6
  I18n.load_path << File.expand_path('../rows_controller/locales/en.yml', __FILE__)
5
7
  I18n.load_path << File.expand_path('../rows_controller/locales/de.yml', __FILE__)
6
8
  I18n.reload!
@@ -0,0 +1,53 @@
1
+ # mostly generated by Rails
2
+
3
+ require 'test_helper'
4
+
5
+ class Order::ItemsControllerTest < ActionController::TestCase
6
+ setup do
7
+ @order_item = order_items(:one)
8
+ end
9
+
10
+ test "should get index" do
11
+ get :index
12
+ assert_response :success
13
+ assert_not_nil assigns(:order_items)
14
+ end
15
+
16
+ test "should get new" do
17
+ get :new
18
+ assert_response :success
19
+ end
20
+
21
+ test "should create order_item" do
22
+ assert_difference('Order::Item.count') do
23
+ post :create, order_item: { price: @order_item.price }
24
+ end
25
+
26
+ ## assert_redirected_to order_item_path(assigns(:order_item))
27
+ assert_redirected_to edit_order_item_path(assigns(:order_item))
28
+ end
29
+
30
+ test "should show order_item" do
31
+ get :show, id: @order_item
32
+ assert_response :success
33
+ end
34
+
35
+ test "should get edit" do
36
+ get :edit, id: @order_item
37
+ assert_response :success
38
+ end
39
+
40
+ test "should update order_item" do
41
+ patch :update, id: @order_item, order_item: { price: @order_item.price }
42
+ ## assert_redirected_to order_item_path(assigns(:order_item))
43
+ assert_redirected_to edit_order_item_path(assigns(:order_item))
44
+ end
45
+
46
+ test "should destroy order_item" do
47
+ assert_difference('Order::Item.count', -1) do
48
+ delete :destroy, id: @order_item
49
+ end
50
+
51
+ assert_redirected_to order_items_path
52
+ end
53
+ end
@@ -0,0 +1,53 @@
1
+ # mostly generated by Rails
2
+
3
+ require 'test_helper'
4
+
5
+ class OrdersControllerTest < ActionController::TestCase
6
+ setup do
7
+ @order = orders(:one)
8
+ end
9
+
10
+ test "should get index" do
11
+ get :index
12
+ assert_response :success
13
+ assert_not_nil assigns(:orders)
14
+ end
15
+
16
+ test "should get new" do
17
+ get :new
18
+ assert_response :success
19
+ end
20
+
21
+ test "should create order" do
22
+ assert_difference('Order.count') do
23
+ post :create, order: { name: @order.name }
24
+ end
25
+
26
+ ## assert_redirected_to order_path(assigns(:order))
27
+ assert_redirected_to edit_order_path(assigns(:order))
28
+ end
29
+
30
+ test "should show order" do
31
+ get :show, id: @order
32
+ assert_response :success
33
+ end
34
+
35
+ test "should get edit" do
36
+ get :edit, id: @order
37
+ assert_response :success
38
+ end
39
+
40
+ test "should update order" do
41
+ patch :update, id: @order, order: { name: @order.name }
42
+ ## assert_redirected_to order_path(assigns(:order))
43
+ assert_redirected_to edit_order_path(assigns(:order))
44
+ end
45
+
46
+ test "should destroy order" do
47
+ assert_difference('Order.count', -1) do
48
+ delete :destroy, id: @order
49
+ end
50
+
51
+ assert_redirected_to orders_path
52
+ end
53
+ end