rows_controller 0.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.
- data/.rspec +2 -0
- data/.rvmrc +3 -0
- data/.watchr +56 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +136 -0
- data/MIT-LICENSE +20 -0
- data/README.md +91 -0
- data/Rakefile +30 -0
- data/app/controllers/rows_controller.rb +80 -0
- data/app/controllers/rows_controller/helpers.rb +86 -0
- data/app/views/rows/_form.html.erb +3 -0
- data/app/views/rows/_list.html.erb +31 -0
- data/app/views/rows/_submit.html.erb +22 -0
- data/app/views/rows/_submit_part.html.erb +4 -0
- data/app/views/rows/destroy.js.erb +1 -0
- data/app/views/rows/edit.html.erb +22 -0
- data/app/views/rows/index.html.erb +20 -0
- data/app/views/rows/new.html.erb +22 -0
- data/app/views/rows/show.html.erb +25 -0
- data/app/views/shared/_error_explanation.html.erb +14 -0
- data/app/views/shared/_flash.html.erb +9 -0
- data/lib/rows_controller.rb +5 -0
- data/lib/rows_controller/engine.rb +4 -0
- data/lib/rows_controller/locales/en.yml +33 -0
- data/lib/rows_controller/version.rb +3 -0
- data/rows_controller.gemspec +27 -0
- data/spec/controllers/orders_spec.rb +65 -0
- data/spec/controllers/rows_spec.rb +19 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/orders_controller.rb +3 -0
- data/spec/dummy/app/models/order.rb +10 -0
- data/spec/dummy/app/views/layouts/application.html.erb +13 -0
- data/spec/dummy/app/views/orders/_form.html.erb +12 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +49 -0
- data/spec/dummy/config/boot.rb +9 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +60 -0
- data/spec/dummy/config/environments/test.rb +40 -0
- data/spec/dummy/config/initializers/secret_token.rb +1 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/routes.rb +7 -0
- data/spec/dummy/db/migrate/001_create_orders.rb +10 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/integration/order_spec.rb +45 -0
- data/spec/models/order_spec.rb +7 -0
- data/spec/spec_helper.rb +63 -0
- data/spec/support/describe_private.rb +14 -0
- metadata +164 -0
data/.rspec
ADDED
data/.rvmrc
ADDED
data/.watchr
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
def run(cmd)
|
2
|
+
puts "***** #{cmd}"
|
3
|
+
system "/usr/bin/time --format 'Elapsed time %E' #{cmd}"
|
4
|
+
end
|
5
|
+
|
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(' ')}"
|
14
|
+
end
|
15
|
+
|
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
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
watch('spec/.*/*_spec\.rb') { |match| run "rspec #{match[0]}" }
|
31
|
+
watch('spec/.*/.*/*_spec\.rb') { |match| run "rspec #{match[0]}" }
|
32
|
+
|
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
|
41
|
+
}
|
42
|
+
|
43
|
+
watch('app/views/(.*)?\.erb') { |match|
|
44
|
+
puts "** touched #{match[1]}"
|
45
|
+
run_without ['models']
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
# Ctrl-\ or ctrl-4
|
50
|
+
Signal.trap('QUIT') do
|
51
|
+
puts "\n--- Running all tests ---\n"
|
52
|
+
run 'rake spec'
|
53
|
+
end
|
54
|
+
|
55
|
+
# Ctrl-C
|
56
|
+
Signal.trap('INT') { abort("Interrupted\n") }
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "rails", '3.1.0'
|
4
|
+
gem 'jquery-rails'
|
5
|
+
gem 'decent_exposure'
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem "capybara"
|
9
|
+
gem 'rspec-rails'
|
10
|
+
end
|
11
|
+
|
12
|
+
group :development, :test do
|
13
|
+
gem "sqlite3"
|
14
|
+
gem 'watchr'
|
15
|
+
gem 'spork'
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (3.1.0)
|
5
|
+
actionpack (= 3.1.0)
|
6
|
+
mail (~> 2.3.0)
|
7
|
+
actionpack (3.1.0)
|
8
|
+
activemodel (= 3.1.0)
|
9
|
+
activesupport (= 3.1.0)
|
10
|
+
builder (~> 3.0.0)
|
11
|
+
erubis (~> 2.7.0)
|
12
|
+
i18n (~> 0.6)
|
13
|
+
rack (~> 1.3.2)
|
14
|
+
rack-cache (~> 1.0.3)
|
15
|
+
rack-mount (~> 0.8.2)
|
16
|
+
rack-test (~> 0.6.1)
|
17
|
+
sprockets (~> 2.0.0)
|
18
|
+
activemodel (3.1.0)
|
19
|
+
activesupport (= 3.1.0)
|
20
|
+
bcrypt-ruby (~> 3.0.0)
|
21
|
+
builder (~> 3.0.0)
|
22
|
+
i18n (~> 0.6)
|
23
|
+
activerecord (3.1.0)
|
24
|
+
activemodel (= 3.1.0)
|
25
|
+
activesupport (= 3.1.0)
|
26
|
+
arel (~> 2.2.1)
|
27
|
+
tzinfo (~> 0.3.29)
|
28
|
+
activeresource (3.1.0)
|
29
|
+
activemodel (= 3.1.0)
|
30
|
+
activesupport (= 3.1.0)
|
31
|
+
activesupport (3.1.0)
|
32
|
+
multi_json (~> 1.0)
|
33
|
+
arel (2.2.1)
|
34
|
+
bcrypt-ruby (3.0.1)
|
35
|
+
builder (3.0.0)
|
36
|
+
capybara (1.1.2)
|
37
|
+
mime-types (>= 1.16)
|
38
|
+
nokogiri (>= 1.3.3)
|
39
|
+
rack (>= 1.0.0)
|
40
|
+
rack-test (>= 0.5.4)
|
41
|
+
selenium-webdriver (~> 2.0)
|
42
|
+
xpath (~> 0.1.4)
|
43
|
+
childprocess (0.3.0)
|
44
|
+
ffi (~> 1.0.6)
|
45
|
+
decent_exposure (1.0.2)
|
46
|
+
diff-lcs (1.1.3)
|
47
|
+
erubis (2.7.0)
|
48
|
+
ffi (1.0.11)
|
49
|
+
hike (1.2.1)
|
50
|
+
i18n (0.6.0)
|
51
|
+
jquery-rails (1.0.19)
|
52
|
+
railties (~> 3.0)
|
53
|
+
thor (~> 0.14)
|
54
|
+
json (1.6.4)
|
55
|
+
mail (2.3.0)
|
56
|
+
i18n (>= 0.4.0)
|
57
|
+
mime-types (~> 1.16)
|
58
|
+
treetop (~> 1.4.8)
|
59
|
+
mime-types (1.17.2)
|
60
|
+
multi_json (1.0.4)
|
61
|
+
nokogiri (1.5.0)
|
62
|
+
polyglot (0.3.3)
|
63
|
+
rack (1.3.6)
|
64
|
+
rack-cache (1.0.3)
|
65
|
+
rack (>= 0.4)
|
66
|
+
rack-mount (0.8.3)
|
67
|
+
rack (>= 1.0.0)
|
68
|
+
rack-ssl (1.3.2)
|
69
|
+
rack
|
70
|
+
rack-test (0.6.1)
|
71
|
+
rack (>= 1.0)
|
72
|
+
rails (3.1.0)
|
73
|
+
actionmailer (= 3.1.0)
|
74
|
+
actionpack (= 3.1.0)
|
75
|
+
activerecord (= 3.1.0)
|
76
|
+
activeresource (= 3.1.0)
|
77
|
+
activesupport (= 3.1.0)
|
78
|
+
bundler (~> 1.0)
|
79
|
+
railties (= 3.1.0)
|
80
|
+
railties (3.1.0)
|
81
|
+
actionpack (= 3.1.0)
|
82
|
+
activesupport (= 3.1.0)
|
83
|
+
rack-ssl (~> 1.3.2)
|
84
|
+
rake (>= 0.8.7)
|
85
|
+
rdoc (~> 3.4)
|
86
|
+
thor (~> 0.14.6)
|
87
|
+
rake (0.9.2.2)
|
88
|
+
rdoc (3.12)
|
89
|
+
json (~> 1.4)
|
90
|
+
rspec (2.8.0)
|
91
|
+
rspec-core (~> 2.8.0)
|
92
|
+
rspec-expectations (~> 2.8.0)
|
93
|
+
rspec-mocks (~> 2.8.0)
|
94
|
+
rspec-core (2.8.0)
|
95
|
+
rspec-expectations (2.8.0)
|
96
|
+
diff-lcs (~> 1.1.2)
|
97
|
+
rspec-mocks (2.8.0)
|
98
|
+
rspec-rails (2.8.1)
|
99
|
+
actionpack (>= 3.0)
|
100
|
+
activesupport (>= 3.0)
|
101
|
+
railties (>= 3.0)
|
102
|
+
rspec (~> 2.8.0)
|
103
|
+
rubyzip (0.9.5)
|
104
|
+
selenium-webdriver (2.16.0)
|
105
|
+
childprocess (>= 0.2.5)
|
106
|
+
ffi (~> 1.0.9)
|
107
|
+
multi_json (~> 1.0.4)
|
108
|
+
rubyzip
|
109
|
+
spork (0.8.5)
|
110
|
+
sprockets (2.0.3)
|
111
|
+
hike (~> 1.2)
|
112
|
+
rack (~> 1.0)
|
113
|
+
tilt (~> 1.1, != 1.3.0)
|
114
|
+
sqlite3 (1.3.5)
|
115
|
+
thor (0.14.6)
|
116
|
+
tilt (1.3.3)
|
117
|
+
treetop (1.4.10)
|
118
|
+
polyglot
|
119
|
+
polyglot (>= 0.3.1)
|
120
|
+
tzinfo (0.3.31)
|
121
|
+
watchr (0.7)
|
122
|
+
xpath (0.1.4)
|
123
|
+
nokogiri (~> 1.3)
|
124
|
+
|
125
|
+
PLATFORMS
|
126
|
+
ruby
|
127
|
+
|
128
|
+
DEPENDENCIES
|
129
|
+
capybara
|
130
|
+
decent_exposure
|
131
|
+
jquery-rails
|
132
|
+
rails (= 3.1.0)
|
133
|
+
rspec-rails
|
134
|
+
spork
|
135
|
+
sqlite3
|
136
|
+
watchr
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 Dittmar Krall - http://matique.de
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
Rows
|
2
|
+
====
|
3
|
+
|
4
|
+
DRYs Rails controllers. Imagine replacing that @order by 'resource' in the
|
5
|
+
controllers/views and, imho, an area for DRYing appears.
|
6
|
+
Instead of:
|
7
|
+
|
8
|
+
class OrdersController < ApplicationController
|
9
|
+
...
|
10
|
+
|
11
|
+
use:
|
12
|
+
|
13
|
+
class OrdersController < RowsController # < ApplicationController
|
14
|
+
|
15
|
+
|
16
|
+
The OrdersController may end there as RowsController has all the usual
|
17
|
+
methods (index, show, edit,...).
|
18
|
+
|
19
|
+
The methods may be redefined in OrdersController overwritting the
|
20
|
+
methods from RowsController.
|
21
|
+
|
22
|
+
Protected low level methods like 'resources' may be redefined as well.
|
23
|
+
An example:
|
24
|
+
|
25
|
+
def resources
|
26
|
+
@_resources ||= model_class.paginate(:page => params[:page])
|
27
|
+
end
|
28
|
+
|
29
|
+
RowsController inherites from ApplicationController, i.e. all the helpers
|
30
|
+
defined there will be available.
|
31
|
+
|
32
|
+
|
33
|
+
Customization of views
|
34
|
+
----------------------
|
35
|
+
|
36
|
+
Providing e.g. an "#{Rails.root}/app/views/order/index.html.erb"
|
37
|
+
overwrites the default view as Rails will first look
|
38
|
+
into the directory "#{Rails.root}/app/views" before looking
|
39
|
+
into the RowsController.
|
40
|
+
|
41
|
+
|
42
|
+
model_class
|
43
|
+
-----------
|
44
|
+
|
45
|
+
RowsController guesses the model from params[:controller]. This can
|
46
|
+
be changed by e.g.:
|
47
|
+
|
48
|
+
class OrdersController < RowsController
|
49
|
+
model_class Booking
|
50
|
+
|
51
|
+
The model class can be retrieved with model_class.
|
52
|
+
|
53
|
+
|
54
|
+
Copy
|
55
|
+
----
|
56
|
+
|
57
|
+
The method "copy" was added to the RowsController as several applications
|
58
|
+
required it. "copy" is like "new", however its attributes are initialized
|
59
|
+
from an existing resource. The "id" of the cloned resource
|
60
|
+
is set to nil.
|
61
|
+
|
62
|
+
Usage of "copy" requires a defining in config/routes.rb. An example:
|
63
|
+
|
64
|
+
resources :orders
|
65
|
+
get 'copy', :on => :member
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
Installation and Testing
|
70
|
+
------------------------
|
71
|
+
|
72
|
+
As usual:
|
73
|
+
|
74
|
+
gem 'rows_controller' # in Gemfile
|
75
|
+
bundle
|
76
|
+
( cd spec/dummy; rake db:create db:migrate )
|
77
|
+
rake
|
78
|
+
|
79
|
+
|
80
|
+
Credits
|
81
|
+
-------
|
82
|
+
|
83
|
+
Inspiration from the web.
|
84
|
+
Look for:
|
85
|
+
|
86
|
+
- Radiant
|
87
|
+
- inherited_resources
|
88
|
+
- decent_exposure
|
89
|
+
|
90
|
+
|
91
|
+
Copyright (c) 2009-2011 [Dittmar Krall], released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler'
|
5
|
+
require 'bundler/setup'
|
6
|
+
rescue LoadError
|
7
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rspec/core'
|
11
|
+
require 'rspec/core/rake_task'
|
12
|
+
|
13
|
+
Bundler::GemHelper.install_tasks
|
14
|
+
RSpec::Core::RakeTask.new(:spec)
|
15
|
+
|
16
|
+
task :default => :spec
|
17
|
+
|
18
|
+
|
19
|
+
desc "Clean automatically generated files"
|
20
|
+
task :clean do
|
21
|
+
FileUtils.rm_rf "pkg"
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Check syntax"
|
25
|
+
task :syntax do
|
26
|
+
Dir["**/*.rb"].each do |file|
|
27
|
+
print "#{file}: "
|
28
|
+
system("ruby -c #{file}")
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class RowsController < ApplicationController
|
2
|
+
require_dependency 'rows_controller/helpers'
|
3
|
+
|
4
|
+
respond_to :html, :xml
|
5
|
+
|
6
|
+
def index
|
7
|
+
respond_with(resources)
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
respond_with(resource)
|
12
|
+
end
|
13
|
+
|
14
|
+
def new
|
15
|
+
respond_with(resource)
|
16
|
+
end
|
17
|
+
|
18
|
+
def edit
|
19
|
+
respond_with(resource)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create
|
23
|
+
# merge_bag
|
24
|
+
msg = t('ui.created', :model => model_name,
|
25
|
+
:default => "%{model} created.")
|
26
|
+
save_and_respond(msg, 'rows/new')
|
27
|
+
end
|
28
|
+
|
29
|
+
def update
|
30
|
+
# merge_bag
|
31
|
+
msg = t('ui.updated', :model => model_name,
|
32
|
+
:default => "%{model} updated.")
|
33
|
+
save_and_respond(msg, 'rows/edit')
|
34
|
+
end
|
35
|
+
|
36
|
+
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' }
|
41
|
+
end
|
42
|
+
flash[:notice] = t('ui.deleted', :model => model_name,
|
43
|
+
:default => "%{model} deleted.")
|
44
|
+
end
|
45
|
+
|
46
|
+
def copy
|
47
|
+
@_resource = resource.dup
|
48
|
+
@_resource.id = nil
|
49
|
+
respond_with(resource) do |format|
|
50
|
+
format.html { render :action => :new }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
private
|
56
|
+
def save_and_respond(notice, failure_template)
|
57
|
+
if resource.save
|
58
|
+
respond_with(resource)
|
59
|
+
flash[:notice] = notice
|
60
|
+
else
|
61
|
+
respond_with(resource) do |format|
|
62
|
+
format.html { render :template => failure_template, :id => resource.id }
|
63
|
+
format.xml { render :xml => resource.errors, :status => :unprocessable_entity }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# May be useful:
|
69
|
+
# def multi_deletion
|
70
|
+
# items = params[:multi_deletion] || []
|
71
|
+
# items -= ['']
|
72
|
+
# items.map {|id| model_class.find(id).destroy }
|
73
|
+
# redirect_to :action => :index
|
74
|
+
# end
|
75
|
+
|
76
|
+
# def merge_bag
|
77
|
+
# self.params = model_class.merge({}, self.params) if model_class.respond_to?(:merge)
|
78
|
+
# end
|
79
|
+
|
80
|
+
end
|