dry_crud 1.2.7 → 1.3.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/README.rdoc +60 -27
- data/Rakefile +3 -1
- data/VERSION +1 -1
- data/lib/generators/dry_crud/dry_crud_generator.rb +3 -3
- data/lib/generators/dry_crud/templates/INSTALL +3 -1
- data/lib/generators/dry_crud/templates/app/controllers/crud_controller.rb +106 -90
- data/lib/generators/dry_crud/templates/app/controllers/list_controller.rb +90 -74
- data/lib/generators/dry_crud/templates/app/controllers/render_inheritable.rb +34 -33
- data/lib/generators/dry_crud/templates/app/helpers/crud_helper.rb +39 -23
- data/lib/generators/dry_crud/templates/app/helpers/list_helper.rb +11 -9
- data/lib/generators/dry_crud/templates/app/helpers/standard_form_builder.rb +55 -47
- data/lib/generators/dry_crud/templates/app/helpers/standard_helper.rb +134 -86
- data/lib/generators/dry_crud/templates/app/helpers/standard_table_builder.rb +41 -35
- data/lib/generators/dry_crud/templates/app/views/crud/_actions_edit.html.erb +1 -0
- data/lib/generators/dry_crud/templates/app/views/crud/edit.html.erb +3 -3
- data/lib/generators/dry_crud/templates/app/views/crud/new.html.erb +2 -2
- data/lib/generators/dry_crud/templates/app/views/crud/show.html.erb +3 -3
- data/lib/generators/dry_crud/templates/app/views/layouts/crud.html.erb +9 -7
- data/lib/generators/dry_crud/templates/app/views/list/_search.html.erb +1 -1
- data/lib/generators/dry_crud/templates/app/views/list/index.html.erb +4 -4
- data/lib/generators/dry_crud/templates/app/views/shared/_error_messages.html.erb +3 -1
- data/lib/generators/dry_crud/templates/config/locales/en_crud.yml +63 -0
- data/lib/generators/dry_crud/templates/test/crud_test_model.rb +93 -58
- data/lib/generators/dry_crud/templates/test/custom_assertions.rb +24 -13
- data/lib/generators/dry_crud/templates/test/functional/crud_controller_test_helper.rb +26 -56
- data/lib/generators/dry_crud/templates/test/functional/crud_test_models_controller_test.rb +47 -41
- data/lib/generators/dry_crud/templates/test/unit/custom_assertions_test.rb +28 -24
- data/lib/generators/dry_crud/templates/test/unit/helpers/crud_helper_test.rb +20 -34
- data/lib/generators/dry_crud/templates/test/unit/helpers/list_helper_test.rb +39 -53
- data/lib/generators/dry_crud/templates/test/unit/helpers/render_inheritable_test.rb +33 -33
- data/lib/generators/dry_crud/templates/test/unit/helpers/standard_form_builder_test.rb +27 -27
- data/lib/generators/dry_crud/templates/test/unit/helpers/standard_helper_test.rb +103 -50
- data/lib/generators/dry_crud/templates/test/unit/helpers/standard_table_builder_test.rb +52 -24
- data/test/templates/Gemfile +34 -0
- data/test/templates/app/controllers/ajax_controller.rb +3 -3
- data/test/templates/app/controllers/application_controller.rb +1 -1
- data/test/templates/app/controllers/cities_controller.rb +2 -5
- data/test/templates/app/controllers/people_controller.rb +5 -5
- data/test/templates/app/controllers/vips_controller.rb +6 -11
- data/test/templates/app/helpers/people_helper.rb +2 -2
- data/test/templates/app/models/city.rb +9 -9
- data/test/templates/app/models/person.rb +5 -4
- data/test/templates/app/views/ajax/_actions_index.html.erb +2 -2
- data/test/templates/app/views/cities/_form.html.erb +5 -1
- data/test/templates/app/views/layouts/_menu.html.erb +3 -3
- data/test/templates/app/views/people/_attrs.html.erb +3 -3
- data/test/templates/config/database.yml +22 -0
- data/test/templates/config/locales/en_cities.yml +56 -0
- data/test/templates/config/routes.rb +5 -5
- data/test/templates/db/migrate/20100511174904_create_people_and_cities.rb +5 -2
- data/test/templates/db/seeds.rb +38 -29
- data/test/templates/test/functional/cities_controller_test.rb +12 -12
- data/test/templates/test/functional/people_controller_test.rb +10 -10
- metadata +11 -7
@@ -1,79 +1,86 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class StandardTableBuilderTest < ActionView::TestCase
|
4
|
-
|
4
|
+
|
5
5
|
# set dummy helper class for ActionView::TestCase
|
6
6
|
self.helper_class = StandardHelper
|
7
|
-
|
7
|
+
|
8
8
|
attr_reader :table
|
9
|
-
|
9
|
+
|
10
10
|
def setup
|
11
11
|
@table = StandardTableBuilder.new(["foo", "bahr"], self)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def format_size(obj)
|
15
15
|
"#{obj.size} chars"
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
test "html header" do
|
19
19
|
table.attrs :upcase, :size
|
20
|
-
|
20
|
+
|
21
21
|
dom = '<tr><th>Upcase</th><th>Size</th></tr>'
|
22
|
-
|
22
|
+
|
23
23
|
assert_dom_equal dom, table.send(:html_header)
|
24
24
|
end
|
25
25
|
|
26
26
|
test "single attr row" do
|
27
27
|
table.attrs :upcase, :size
|
28
|
-
|
28
|
+
|
29
29
|
dom = '<tr class="even"><td>FOO</td><td>3 chars</td></tr>'
|
30
|
-
|
30
|
+
|
31
31
|
assert_dom_equal dom, table.send(:html_row, "foo")
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
test "custom row" do
|
35
35
|
table.col("Header", :class => 'hula') {|e| "Weights #{e.size} kg" }
|
36
|
-
|
36
|
+
|
37
37
|
dom = '<tr class="even"><td class="hula">Weights 3 kg</td></tr>'
|
38
|
-
|
38
|
+
|
39
39
|
assert_dom_equal dom, table.send(:html_row, "foo")
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
test "attr col output" do
|
43
43
|
table.attrs :upcase
|
44
44
|
col = table.cols.first
|
45
|
-
|
45
|
+
|
46
46
|
assert_equal "<th>Upcase</th>", col.html_header
|
47
47
|
assert_equal "FOO", col.content("foo")
|
48
48
|
assert_equal "<td>FOO</td>", col.html_cell("foo")
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
test "attr col content with custom format_size method" do
|
52
52
|
table.attrs :size
|
53
53
|
col = table.cols.first
|
54
|
-
|
54
|
+
|
55
55
|
assert_equal "4 chars", col.content("abcd")
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
test "two x two table" do
|
59
59
|
dom = <<-FIN
|
60
60
|
<table class="list">
|
61
|
+
<thead>
|
61
62
|
<tr><th>Upcase</th><th>Size</th></tr>
|
63
|
+
</thead>
|
64
|
+
<tbody>
|
62
65
|
<tr class="even"><td>FOO</td><td>3 chars</td></tr>
|
63
66
|
<tr class="odd"><td>BAHR</td><td>4 chars</td></tr>
|
67
|
+
</tbody>
|
64
68
|
</table>
|
65
69
|
FIN
|
66
70
|
dom.gsub!(/[\n\t]/, "").gsub!(/\s{2,}/, "")
|
67
|
-
|
71
|
+
|
68
72
|
table.attrs :upcase, :size
|
69
|
-
|
73
|
+
|
70
74
|
assert_dom_equal dom, table.to_html
|
71
75
|
end
|
72
|
-
|
73
|
-
test "table with before and after cells" do
|
76
|
+
|
77
|
+
test "table with before and after cells" do
|
74
78
|
dom = <<-FIN
|
75
79
|
<table class="list">
|
80
|
+
<thead>
|
76
81
|
<tr><th>head</th><th>Upcase</th><th>Size</th><th></th></tr>
|
82
|
+
</thead>
|
83
|
+
<tbody>
|
77
84
|
<tr class="even">
|
78
85
|
<td class='left'><a href='/'>foo</a></td>
|
79
86
|
<td>FOO</td>
|
@@ -86,16 +93,37 @@ class StandardTableBuilderTest < ActionView::TestCase
|
|
86
93
|
<td>4 chars</td>
|
87
94
|
<td>Never bahr</td>
|
88
95
|
</tr>
|
96
|
+
</tbody>
|
89
97
|
</table>
|
90
98
|
FIN
|
91
99
|
dom.gsub!(/[\n\t]/, "").gsub!(/\s{2,}/, "")
|
92
|
-
|
100
|
+
|
93
101
|
table.col('head', :class => 'left') { |e| link_to e, "/" }
|
94
102
|
table.attrs :upcase, :size
|
95
103
|
table.col { |e| "Never #{e}" }
|
96
|
-
|
97
|
-
|
104
|
+
|
105
|
+
|
98
106
|
assert_dom_equal dom, table.to_html
|
99
107
|
end
|
100
108
|
|
109
|
+
test "empty entries collection renders empty table" do
|
110
|
+
dom = <<-FIN
|
111
|
+
<table class="list">
|
112
|
+
<thead>
|
113
|
+
<tr><th>head</th><th>Upcase</th><th>Size</th><th></th></tr>
|
114
|
+
</thead>
|
115
|
+
<tbody>
|
116
|
+
</tbody>
|
117
|
+
</table>
|
118
|
+
FIN
|
119
|
+
dom.gsub!(/[\n\t]/, "").gsub!(/\s{2,}/, "")
|
120
|
+
|
121
|
+
table = StandardTableBuilder.new([], self)
|
122
|
+
table.col('head', :class => 'left') { |e| link_to e, "/" }
|
123
|
+
table.attrs :upcase, :size
|
124
|
+
table.col { |e| "Never #{e}" }
|
125
|
+
|
126
|
+
assert_dom_equal dom, table.to_html
|
127
|
+
end
|
128
|
+
|
101
129
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails'
|
4
|
+
|
5
|
+
# Bundle edge Rails instead:
|
6
|
+
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
7
|
+
|
8
|
+
gem 'sqlite3', :platforms => :ruby
|
9
|
+
|
10
|
+
gem 'jdbc-sqlite3', '3.6.14.2.056', :platforms => :jruby
|
11
|
+
gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
|
12
|
+
|
13
|
+
# Use unicorn as the web server
|
14
|
+
# gem 'unicorn'
|
15
|
+
|
16
|
+
# Deploy with Capistrano
|
17
|
+
# gem 'capistrano'
|
18
|
+
|
19
|
+
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
|
20
|
+
# gem 'ruby-debug'
|
21
|
+
# gem 'ruby-debug19', :require => 'ruby-debug'
|
22
|
+
|
23
|
+
# Bundle the extra gems:
|
24
|
+
# gem 'bj'
|
25
|
+
# gem 'nokogiri'
|
26
|
+
# gem 'sqlite3-ruby', :require => 'sqlite3'
|
27
|
+
# gem 'aws-s3', :require => 'aws/s3'
|
28
|
+
|
29
|
+
# Bundle gems for the local environment. Make sure to
|
30
|
+
# put test-only gems in this group so their generators
|
31
|
+
# and rake tasks are available in development mode:
|
32
|
+
# group :development, :test do
|
33
|
+
# gem 'webrat'
|
34
|
+
# end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
class PeopleController < AjaxController
|
2
|
-
|
2
|
+
|
3
3
|
self.search_columns = [:name, :children, :rating, :income, :birthdate, :remarks]
|
4
|
-
|
4
|
+
|
5
5
|
self.sort_mappings = {:city_id => 'cities.name'}
|
6
|
-
|
6
|
+
|
7
7
|
protected
|
8
|
-
|
8
|
+
|
9
9
|
def list_entries
|
10
10
|
super.includes(:city).order('people.name, cities.country_code, cities.name')
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
end
|
@@ -1,24 +1,19 @@
|
|
1
1
|
class VipsController < ListController
|
2
|
-
|
2
|
+
|
3
3
|
self.search_columns = [:name, :children, :rating, :remarks]
|
4
|
-
|
4
|
+
|
5
5
|
self.sort_mappings = {:city_id => 'cities.name'}
|
6
|
-
|
7
|
-
def index
|
8
|
-
@title = 'Listing VIPs'
|
9
|
-
super
|
10
|
-
end
|
11
|
-
|
6
|
+
|
12
7
|
protected
|
13
|
-
|
8
|
+
|
14
9
|
class << self
|
15
10
|
def model_class
|
16
11
|
Person
|
17
12
|
end
|
18
13
|
end
|
19
|
-
|
14
|
+
|
20
15
|
def list_entries
|
21
16
|
super.where('rating > 5').includes(:city).order('people.name, cities.country_code, cities.name')
|
22
17
|
end
|
23
|
-
|
18
|
+
|
24
19
|
end
|
@@ -1,25 +1,25 @@
|
|
1
1
|
class City < ActiveRecord::Base
|
2
|
-
|
2
|
+
|
3
3
|
has_many :people
|
4
4
|
|
5
5
|
validates :name, :presence => true
|
6
6
|
validates :country_code, :presence => true
|
7
|
-
|
7
|
+
|
8
8
|
before_destroy :protect_with_inhabitants
|
9
|
-
|
9
|
+
|
10
10
|
default_scope order('country_code, name')
|
11
|
-
|
12
|
-
def
|
11
|
+
|
12
|
+
def to_s
|
13
13
|
"#{name} (#{country_code})"
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
protected
|
17
|
-
|
17
|
+
|
18
18
|
def protect_with_inhabitants
|
19
19
|
if people.exists?
|
20
|
-
errors.add(:base,
|
20
|
+
errors.add(:base, :protect_with_inhabitants)
|
21
21
|
false
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= render :partial => 'crud/actions_index' %>
|
1
|
+
<%= render :partial => 'crud/actions_index' %>
|
2
2
|
|
3
|
-
<%= link_action '
|
3
|
+
<%= link_action ti(:'link.ajax'), nil, {:action => 'ajax'}, :method => :get, :remote => true %>
|
4
4
|
<div id="response"></div>
|
@@ -1,4 +1,8 @@
|
|
1
1
|
<%= crud_form do |f| -%>
|
2
2
|
<%= f.labeled_input_field :name %>
|
3
|
-
<%= f.labeled_collection_select(:country_code,
|
3
|
+
<%= f.labeled_collection_select(:country_code,
|
4
|
+
['BR', 'CH', 'DE', 'GB', 'JP', 'USA'],
|
5
|
+
:to_s,
|
6
|
+
:to_s,
|
7
|
+
f.select_options(:country_code)) %>
|
4
8
|
<% end -%>
|
@@ -1,3 +1,3 @@
|
|
1
|
-
<li><%= link_to '
|
2
|
-
<li><%= link_to '
|
3
|
-
<li><%= link_to '
|
1
|
+
<li><%= link_to t(:'global.menu.people'), people_path %></li>
|
2
|
+
<li><%= link_to t(:'global.menu.cities'), cities_path %></li>
|
3
|
+
<li><%= link_to t(:'global.menu.vips'), vips_path %></li>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<%= render_attrs @entry, *default_attrs %>
|
2
|
-
<%= labeled(
|
3
|
-
<%= labeled(
|
4
|
-
<%= link_to "
|
2
|
+
<%= labeled(ti(:i_think_its), ti(:nice)) %>
|
3
|
+
<%= labeled(ti(:check_google)) do %>
|
4
|
+
<%= link_to ti(:"link.maps"), "http://map.google.com/?q=#{@entry.name}" %>
|
5
5
|
<% end %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
development:
|
4
|
+
adapter: <%= defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3' %>
|
5
|
+
database: db/development.sqlite3
|
6
|
+
pool: 5
|
7
|
+
timeout: 5000
|
8
|
+
|
9
|
+
# Warning: The database defined as "test" will be erased and
|
10
|
+
# re-generated from your development database when you run "rake".
|
11
|
+
# Do not set this db to the same as development or production.
|
12
|
+
test:
|
13
|
+
adapter: <%= defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3' %>
|
14
|
+
database: db/test.sqlite3
|
15
|
+
pool: 5
|
16
|
+
timeout: 5000
|
17
|
+
|
18
|
+
production:
|
19
|
+
adapter: <%= defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3' %>
|
20
|
+
database: db/production.sqlite3
|
21
|
+
pool: 5
|
22
|
+
timeout: 5000
|
@@ -0,0 +1,56 @@
|
|
1
|
+
en:
|
2
|
+
global:
|
3
|
+
menu:
|
4
|
+
people: People
|
5
|
+
cities: Cities
|
6
|
+
vips: VIPs
|
7
|
+
link:
|
8
|
+
maps: Maps
|
9
|
+
ajax:
|
10
|
+
global:
|
11
|
+
link:
|
12
|
+
ajax: Ajahx
|
13
|
+
# cities controller
|
14
|
+
cities:
|
15
|
+
global:
|
16
|
+
confirm_delete: You kill city?
|
17
|
+
button:
|
18
|
+
save: Save City
|
19
|
+
index:
|
20
|
+
title: All cities of the world
|
21
|
+
list:
|
22
|
+
no_list_entries: Nada citta
|
23
|
+
new:
|
24
|
+
button:
|
25
|
+
save: Create City
|
26
|
+
update:
|
27
|
+
flash:
|
28
|
+
success: The %{model} got an update
|
29
|
+
|
30
|
+
# people controller
|
31
|
+
people:
|
32
|
+
global:
|
33
|
+
confirm_delete: You delete pipl?
|
34
|
+
attrs:
|
35
|
+
i_think_its: I think it's
|
36
|
+
nice: Nice
|
37
|
+
check_google: Check Google
|
38
|
+
|
39
|
+
# vips controller
|
40
|
+
vips:
|
41
|
+
index:
|
42
|
+
title: Listing VIPs
|
43
|
+
no_list_entries: No VIPs found
|
44
|
+
|
45
|
+
# model associations
|
46
|
+
activerecord:
|
47
|
+
errors:
|
48
|
+
models:
|
49
|
+
city:
|
50
|
+
protect_with_inhabitants: You cannot destroy this city as long as it has any inhabitants.
|
51
|
+
associations:
|
52
|
+
person:
|
53
|
+
no_entry: Nobody
|
54
|
+
none_available: Nobody here
|
55
|
+
city:
|
56
|
+
none_available: No City
|