rows_controller 0.4.4 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.watchr +39 -43
  3. data/Gemfile +5 -2
  4. data/Gemfile.lock +72 -77
  5. data/MIT-LICENSE +1 -1
  6. data/README.md +20 -4
  7. data/app/controllers/rows_controller.rb +68 -53
  8. data/app/controllers/rows_controller/helpers.rb +68 -40
  9. data/app/controllers/rows_ext_controller.rb +18 -0
  10. data/app/views/rows/_form.slim +2 -0
  11. data/app/views/rows/_list.slim +18 -0
  12. data/app/views/rows/_list_footer.slim +5 -0
  13. data/app/views/rows/_list_header.slim +7 -0
  14. data/app/views/rows/_list_row.slim +10 -0
  15. data/app/views/rows/_row_buttons.slim +14 -0
  16. data/app/views/rows/_submit.slim +19 -0
  17. data/app/views/rows/_submit_part.slim +4 -0
  18. data/app/views/rows/edit.slim +17 -0
  19. data/app/views/rows/index.slim +10 -0
  20. data/app/views/rows/new.slim +16 -0
  21. data/app/views/rows/show.slim +17 -0
  22. data/app/views/shared/_error_explanation.slim +10 -0
  23. data/app/views/shared/_show_flash.slim +9 -0
  24. data/lib/rows_controller.rb +1 -0
  25. data/lib/rows_controller/locales/de.yml +23 -0
  26. data/lib/rows_controller/locales/en.yml +16 -27
  27. data/lib/rows_controller/version.rb +1 -1
  28. data/spec/controllers/orders_spec.rb +28 -3
  29. data/spec/controllers/rows_ext_spec.rb +6 -0
  30. data/spec/controllers/rows_spec.rb +5 -0
  31. data/spec/dummy/app/controllers/orders_controller.rb +11 -2
  32. data/spec/dummy/app/models/order.rb +5 -4
  33. data/spec/dummy/app/views/layouts/application.html.erb +1 -1
  34. data/spec/dummy/db/schema.rb +2 -2
  35. data/spec/{integration → features}/order_spec.rb +12 -3
  36. data/spec/spec_helper.rb +19 -52
  37. metadata +31 -34
  38. data/.rvmrc +0 -4
  39. data/app/views/rows/_form.html.erb +0 -3
  40. data/app/views/rows/_list.html.erb +0 -30
  41. data/app/views/rows/_submit.html.erb +0 -22
  42. data/app/views/rows/_submit_part.html.erb +0 -4
  43. data/app/views/rows/edit.html.erb +0 -22
  44. data/app/views/rows/index.html.erb +0 -17
  45. data/app/views/rows/new.html.erb +0 -22
  46. data/app/views/rows/show.html.erb +0 -24
  47. data/app/views/shared/_error_explanation.html.erb +0 -14
  48. data/app/views/shared/_flash.html.erb +0 -9
  49. data/spec/support/describe_private.rb +0 -14
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8350895106158002e0b1bd6319c3867cc66f4f1d
4
+ data.tar.gz: a83f127435c76d5541c453101fc8f3e372694e64
5
+ SHA512:
6
+ metadata.gz: 3ff1628935d87ebc1537af200bab7b9dc45b91cae95d51659bca0f2e4d26ffd3611de29f7fabf94ae0b8df279d922dd38f65bb3c91162883a24b891931d4ce75
7
+ data.tar.gz: 54244a7a196a7d540138dec17a1c12805af50f2026d634ee8eb2aac0296fa5909bd22d057357a56197b928497396532d72d065fe9a1e83b024f721ebf3de7a2e
data/.watchr CHANGED
@@ -1,56 +1,52 @@
1
- def run(cmd)
2
- puts "***** #{cmd}"
3
- system "/usr/bin/time --format 'Elapsed time %E' #{cmd}"
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
4
9
  end
5
10
 
6
- def run_without(list)
7
- all = Dir.glob("spec/**/*_spec.rb")
8
- res = []
9
- list.each { |str|
10
- files = Dir.glob("spec/**/#{str}/*_spec.rb")
11
- res << files
12
- }
13
- run "rspec #{(all - res.flatten).sort.uniq.join(' ')}"
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}"
14
15
  end
15
16
 
16
- def run_matching(name)
17
- arr = name.gsub('_', '/').split('/')
18
- bool = false
19
- arr.each { |str|
20
- files = Dir.glob("spec/**/#{str}_spec.rb")
21
- files.each { |file|
22
- bool = true
23
- run "rspec #{file}"
24
- }
25
- }
26
- puts "***** Changed #{name}; not yet done" unless bool
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
27
23
  end
28
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
29
 
30
- watch('spec/.*/*_spec\.rb') { |match| run "rspec #{match[0]}" }
31
- watch('spec/.*/.*/*_spec\.rb') { |match| run "rspec #{match[0]}" }
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
32
37
 
33
- watch('app/(.*)?\.rb') { |match|
34
- puts "** touched #{match[1]}"
35
- file = "spec/#{match[1]}_spec.rb"
36
- if File.exists?(file)
37
- run "rspec #{file}"
38
- else
39
- run_matching match[1]
40
- end
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
41
  }
42
-
43
- watch('app/views/(.*)?\.erb') { |match|
44
- puts "** touched #{match[1]}"
45
- run_without ['models']
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
46
  }
47
47
 
48
-
49
48
  # Ctrl-\ or ctrl-4
50
- Signal.trap('QUIT') do
51
- puts "\n--- Running all tests ---\n"
52
- run 'rake spec'
53
- end
54
-
49
+ Signal.trap('QUIT') { run_all_tests }
55
50
  # Ctrl-C
56
- Signal.trap('INT') { abort("Interrupted\n") }
51
+ Signal.trap('INT') { abort("Interrupted\n") }
52
+ usage
data/Gemfile CHANGED
@@ -1,15 +1,18 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem 'rails'
4
+ #gem 'rails', '4.0.0.rc1'
4
5
  gem 'jquery-rails'
6
+ gem 'slim'
5
7
 
6
8
  group :test do
7
- gem "capybara"
9
+ gem 'capybara'
8
10
  gem 'rspec-rails'
9
11
  end
10
12
 
11
13
  group :development, :test do
12
- gem "sqlite3"
14
+ gem 'sqlite3'
13
15
  gem 'watchr'
14
16
  gem 'spork'
17
+ gem 'simplecov', require: false
15
18
  end
data/Gemfile.lock CHANGED
@@ -1,123 +1,116 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- actionmailer (3.2.7)
5
- actionpack (= 3.2.7)
6
- mail (~> 2.4.4)
7
- actionpack (3.2.7)
8
- activemodel (= 3.2.7)
9
- activesupport (= 3.2.7)
4
+ actionmailer (3.2.13)
5
+ actionpack (= 3.2.13)
6
+ mail (~> 2.5.3)
7
+ actionpack (3.2.13)
8
+ activemodel (= 3.2.13)
9
+ activesupport (= 3.2.13)
10
10
  builder (~> 3.0.0)
11
11
  erubis (~> 2.7.0)
12
12
  journey (~> 1.0.4)
13
- rack (~> 1.4.0)
13
+ rack (~> 1.4.5)
14
14
  rack-cache (~> 1.2)
15
15
  rack-test (~> 0.6.1)
16
- sprockets (~> 2.1.3)
17
- activemodel (3.2.7)
18
- activesupport (= 3.2.7)
16
+ sprockets (~> 2.2.1)
17
+ activemodel (3.2.13)
18
+ activesupport (= 3.2.13)
19
19
  builder (~> 3.0.0)
20
- activerecord (3.2.7)
21
- activemodel (= 3.2.7)
22
- activesupport (= 3.2.7)
20
+ activerecord (3.2.13)
21
+ activemodel (= 3.2.13)
22
+ activesupport (= 3.2.13)
23
23
  arel (~> 3.0.2)
24
24
  tzinfo (~> 0.3.29)
25
- activeresource (3.2.7)
26
- activemodel (= 3.2.7)
27
- activesupport (= 3.2.7)
28
- activesupport (3.2.7)
29
- i18n (~> 0.6)
25
+ activeresource (3.2.13)
26
+ activemodel (= 3.2.13)
27
+ activesupport (= 3.2.13)
28
+ activesupport (3.2.13)
29
+ i18n (= 0.6.1)
30
30
  multi_json (~> 1.0)
31
- addressable (2.3.2)
32
31
  arel (3.0.2)
33
- builder (3.0.0)
34
- capybara (1.1.2)
32
+ builder (3.0.4)
33
+ capybara (2.1.0)
35
34
  mime-types (>= 1.16)
36
35
  nokogiri (>= 1.3.3)
37
36
  rack (>= 1.0.0)
38
37
  rack-test (>= 0.5.4)
39
- selenium-webdriver (~> 2.0)
40
- xpath (~> 0.1.4)
41
- childprocess (0.3.4)
42
- ffi (~> 1.0, >= 1.0.6)
43
- diff-lcs (1.1.3)
38
+ xpath (~> 2.0)
39
+ diff-lcs (1.2.4)
44
40
  erubis (2.7.0)
45
- ffi (1.1.1)
46
- hike (1.2.1)
47
- i18n (0.6.0)
41
+ hike (1.2.2)
42
+ i18n (0.6.1)
48
43
  journey (1.0.4)
49
- jquery-rails (2.0.2)
50
- railties (>= 3.2.0, < 5.0)
51
- thor (~> 0.14)
52
- json (1.7.4)
53
- libwebsocket (0.1.5)
54
- addressable
55
- mail (2.4.4)
56
- i18n (>= 0.4.0)
44
+ jquery-rails (3.0.0)
45
+ railties (>= 3.0, < 5.0)
46
+ thor (>= 0.14, < 2.0)
47
+ json (1.8.0)
48
+ mail (2.5.4)
57
49
  mime-types (~> 1.16)
58
50
  treetop (~> 1.4.8)
59
- mime-types (1.19)
60
- multi_json (1.3.6)
61
- nokogiri (1.5.5)
51
+ mime-types (1.23)
52
+ multi_json (1.7.4)
53
+ nokogiri (1.5.9)
62
54
  polyglot (0.3.3)
63
- rack (1.4.1)
55
+ rack (1.4.5)
64
56
  rack-cache (1.2)
65
57
  rack (>= 0.4)
66
- rack-ssl (1.3.2)
58
+ rack-ssl (1.3.3)
67
59
  rack
68
- rack-test (0.6.1)
60
+ rack-test (0.6.2)
69
61
  rack (>= 1.0)
70
- rails (3.2.7)
71
- actionmailer (= 3.2.7)
72
- actionpack (= 3.2.7)
73
- activerecord (= 3.2.7)
74
- activeresource (= 3.2.7)
75
- activesupport (= 3.2.7)
62
+ rails (3.2.13)
63
+ actionmailer (= 3.2.13)
64
+ actionpack (= 3.2.13)
65
+ activerecord (= 3.2.13)
66
+ activeresource (= 3.2.13)
67
+ activesupport (= 3.2.13)
76
68
  bundler (~> 1.0)
77
- railties (= 3.2.7)
78
- railties (3.2.7)
79
- actionpack (= 3.2.7)
80
- activesupport (= 3.2.7)
69
+ railties (= 3.2.13)
70
+ railties (3.2.13)
71
+ actionpack (= 3.2.13)
72
+ activesupport (= 3.2.13)
81
73
  rack-ssl (~> 1.3.2)
82
74
  rake (>= 0.8.7)
83
75
  rdoc (~> 3.4)
84
76
  thor (>= 0.14.6, < 2.0)
85
- rake (0.9.2.2)
86
- rdoc (3.12)
77
+ rake (10.0.4)
78
+ rdoc (3.12.2)
87
79
  json (~> 1.4)
88
- rspec (2.11.0)
89
- rspec-core (~> 2.11.0)
90
- rspec-expectations (~> 2.11.0)
91
- rspec-mocks (~> 2.11.0)
92
- rspec-core (2.11.1)
93
- rspec-expectations (2.11.2)
94
- diff-lcs (~> 1.1.3)
95
- rspec-mocks (2.11.1)
96
- rspec-rails (2.11.0)
80
+ rspec-core (2.13.1)
81
+ rspec-expectations (2.13.0)
82
+ diff-lcs (>= 1.1.3, < 2.0)
83
+ rspec-mocks (2.13.1)
84
+ rspec-rails (2.13.2)
97
85
  actionpack (>= 3.0)
98
86
  activesupport (>= 3.0)
99
87
  railties (>= 3.0)
100
- rspec (~> 2.11.0)
101
- rubyzip (0.9.9)
102
- selenium-webdriver (2.25.0)
103
- childprocess (>= 0.2.5)
104
- libwebsocket (~> 0.1.3)
88
+ rspec-core (~> 2.13.0)
89
+ rspec-expectations (~> 2.13.0)
90
+ rspec-mocks (~> 2.13.0)
91
+ simplecov (0.7.1)
105
92
  multi_json (~> 1.0)
106
- rubyzip
93
+ simplecov-html (~> 0.7.1)
94
+ simplecov-html (0.7.1)
95
+ slim (2.0.0)
96
+ temple (~> 0.6.5)
97
+ tilt (~> 1.3, >= 1.3.3)
107
98
  spork (0.9.2)
108
- sprockets (2.1.3)
99
+ sprockets (2.2.2)
109
100
  hike (~> 1.2)
101
+ multi_json (~> 1.0)
110
102
  rack (~> 1.0)
111
103
  tilt (~> 1.1, != 1.3.0)
112
- sqlite3 (1.3.6)
113
- thor (0.15.4)
114
- tilt (1.3.3)
115
- treetop (1.4.10)
104
+ sqlite3 (1.3.7)
105
+ temple (0.6.5)
106
+ thor (0.18.1)
107
+ tilt (1.4.1)
108
+ treetop (1.4.12)
116
109
  polyglot
117
110
  polyglot (>= 0.3.1)
118
- tzinfo (0.3.33)
111
+ tzinfo (0.3.37)
119
112
  watchr (0.7)
120
- xpath (0.1.4)
113
+ xpath (2.0.0)
121
114
  nokogiri (~> 1.3)
122
115
 
123
116
  PLATFORMS
@@ -128,6 +121,8 @@ DEPENDENCIES
128
121
  jquery-rails
129
122
  rails
130
123
  rspec-rails
124
+ simplecov
125
+ slim
131
126
  spork
132
127
  sqlite3
133
128
  watchr
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2011 Dittmar Krall - http://matique.de
1
+ Copyright 2009-2013 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
@@ -19,7 +19,7 @@ methods (index, show, edit,...).
19
19
  The methods may be redefined in OrdersController overwritting the
20
20
  methods from RowsController.
21
21
 
22
- Protected low level methods like 'resources' may be redefined as well.
22
+ Low level methods like 'resources' may be redefined as well.
23
23
  An example:
24
24
 
25
25
  def resources
@@ -34,10 +34,13 @@ Customization of views
34
34
  ----------------------
35
35
 
36
36
  Providing e.g. an "#{Rails.root}/app/views/order/index.html.erb"
37
- overwrites the default view as Rails will first look
37
+ overwrites the default Rows view as Rails will first look
38
38
  into the directory "#{Rails.root}/app/views" before looking
39
39
  into the RowsController.
40
40
 
41
+ Similarly, partials '_row_buttons' and '_list_footer' may be overwritten
42
+ as well.
43
+
41
44
 
42
45
  model_class
43
46
  -----------
@@ -51,11 +54,24 @@ be changed by e.g.:
51
54
  The model class can be retrieved with model_class.
52
55
 
53
56
 
57
+ Rails 4
58
+ -------
59
+
60
+ This gem is intended for Rails 4.
61
+ For older Rails versions feel free to switch to "gem 'rows_controller', '0.4.4'".
62
+
63
+ Rails 4 introduced strong parameters.
64
+ To support them a private method 'resource_whitelist' is required
65
+ in the controllers.
66
+ Alternatively you may define a private method 'resource_params'
67
+ in the controller to filter params.
68
+
69
+
54
70
  ## Enhancements
55
71
 
56
72
  ### copy
57
73
 
58
- The method "copy" was added to the RowsController.
74
+ The method "copy" was added to the RowsExtController.
59
75
  "copy" is like "new", however its attributes are initialized
60
76
  from an existing resource.
61
77
  The "id" of the cloned resource is set to nil.
@@ -94,4 +110,4 @@ Look for:
94
110
  - decent_exposure
95
111
 
96
112
 
97
- Copyright (c) 2009-2012 [Dittmar Krall], released under the MIT license
113
+ Copyright (c) 2009-2013 [Dittmar Krall], released under the MIT license
@@ -1,86 +1,101 @@
1
+ RAILS4 = Rails.version.to_i == 4
2
+
3
+
1
4
  class RowsController < ApplicationController
2
5
  require_dependency 'rows_controller/helpers'
3
6
 
4
- respond_to :html, :xml, :json
5
-
7
+ # GET /:resources[.json]
6
8
  def index
7
- respond_with(resources)
9
+ set_resources
8
10
  end
9
11
 
12
+ # GET /:resource/1[.json]
10
13
  def show
11
- respond_with(resource)
14
+ set_resource
12
15
  end
13
16
 
17
+ # GET /:resource/new
14
18
  def new
15
- respond_with(resource)
19
+ resource_new
16
20
  end
17
21
 
22
+ # GET /:resource/1/edit
18
23
  def edit
19
- respond_with(resource)
24
+ set_resource
20
25
  end
21
26
 
27
+ # POST /:resources.json
22
28
  def create
23
- # merge_bag
24
- msg = t('ui.created', :model => model_name,
25
- :default => "%{model} created.")
26
- save_and_respond(msg, 'rows/new')
29
+ respond_to do |format|
30
+ if resource_create
31
+ flash[:notice] = t('ui.created', model: model_name,
32
+ default: "%{model} created.")
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
27
46
  end
28
47
 
48
+ # PATCH/PUT /:resources/1[.json]
29
49
  def update
30
- # merge_bag
31
- msg = t('ui.updated', :model => model_name,
32
- :default => "%{model} updated.")
33
- save_and_respond(msg, 'rows/edit')
50
+ set_resource
51
+ respond_to do |format|
52
+ if resource_update
53
+ flash[:notice] = t('ui.updated', model: model_name,
54
+ default: "%{model} updated.")
55
+ format.html {
56
+ if params[:commit] == 'OK'
57
+ redirect_to_index
58
+ else
59
+ redirect_to action: 'edit'
60
+ end
61
+ }
62
+ format.json { head :no_content }
63
+ else
64
+ format.html { render action: 'edit' }
65
+ format.json { render json: resource.errors, status: :unprocessable_entity }
66
+ end
67
+ end
34
68
  end
35
69
 
70
+ # DELETE /:resources/1[.json]
36
71
  def destroy
37
- resource.destroy
38
- respond_with(resource) do |format|
39
- format.html { redirect_to :action => :index }
40
- format.js { render :template => 'rows/destroy' }
72
+ set_resource
73
+ resource_destroy
74
+ flash[:notice] = t('ui.destroyed', model: model_name) unless request.xhr?
75
+ respond_to do |format|
76
+ format.html { redirect_to_index }
77
+ format.js { render template: 'rows/destroy', layout: false }
41
78
  format.json { head :no_content }
42
79
  end
43
- flash[:notice] = t('ui.deleted', :model => model_name,
44
- :default => "%{model} deleted.")
45
- end
46
-
47
- def copy
48
- @_resource = resource.dup
49
- @_resource.id = nil
50
- respond_with(resource) do |format|
51
- format.html { render :action => :new }
52
- end
53
80
  end
54
81
 
55
82
 
56
83
  private
57
- def save_and_respond(notice, failure_template)
58
- if resource.save
59
- respond_with(resource) do |format|
60
- format.html { redirect_to :action => :edit, :id => resource.id }
61
- format.xml { render :xml => resource.errors, :status => :unprocessable_entity }
62
- format.json { head :no_content }
63
- end
64
- flash[:notice] = notice
84
+ # Never trust parameters from the scary internet, only allow the white list through.
85
+ def resource_params
86
+ permits = resource_whitelist
87
+ if RAILS4
88
+ params.require(model_symbol).permit(permits)
65
89
  else
66
- respond_with(resource) do |format|
67
- format.html { render :template => failure_template, :id => resource.id }
68
- format.xml { render xml: resource.errors, :status => :unprocessable_entity }
69
- format.json { render json: resource.errors, :status => :unprocessable_entity }
70
- end
90
+ pars = params[model_symbol] || {}
91
+ pars.keys.each { |x|
92
+ unless permits.include?(x)
93
+ pars.delete(x)
94
+ p "** WARNING: model <#{model_name}> dropping params <#{x}>"
95
+ end
96
+ }
97
+ pars
71
98
  end
72
99
  end
73
100
 
74
- # May be useful:
75
- # def multi_deletion
76
- # items = params[:multi_deletion] || []
77
- # items -= ['']
78
- # items.map {|id| model_class.find(id).destroy }
79
- # redirect_to :action => :index
80
- # end
81
-
82
- # def merge_bag
83
- # self.params = model_class.merge({}, self.params) if model_class.respond_to?(:merge)
84
- # end
85
-
86
101
  end