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.
Files changed (54) hide show
  1. data/README.rdoc +60 -27
  2. data/Rakefile +3 -1
  3. data/VERSION +1 -1
  4. data/lib/generators/dry_crud/dry_crud_generator.rb +3 -3
  5. data/lib/generators/dry_crud/templates/INSTALL +3 -1
  6. data/lib/generators/dry_crud/templates/app/controllers/crud_controller.rb +106 -90
  7. data/lib/generators/dry_crud/templates/app/controllers/list_controller.rb +90 -74
  8. data/lib/generators/dry_crud/templates/app/controllers/render_inheritable.rb +34 -33
  9. data/lib/generators/dry_crud/templates/app/helpers/crud_helper.rb +39 -23
  10. data/lib/generators/dry_crud/templates/app/helpers/list_helper.rb +11 -9
  11. data/lib/generators/dry_crud/templates/app/helpers/standard_form_builder.rb +55 -47
  12. data/lib/generators/dry_crud/templates/app/helpers/standard_helper.rb +134 -86
  13. data/lib/generators/dry_crud/templates/app/helpers/standard_table_builder.rb +41 -35
  14. data/lib/generators/dry_crud/templates/app/views/crud/_actions_edit.html.erb +1 -0
  15. data/lib/generators/dry_crud/templates/app/views/crud/edit.html.erb +3 -3
  16. data/lib/generators/dry_crud/templates/app/views/crud/new.html.erb +2 -2
  17. data/lib/generators/dry_crud/templates/app/views/crud/show.html.erb +3 -3
  18. data/lib/generators/dry_crud/templates/app/views/layouts/crud.html.erb +9 -7
  19. data/lib/generators/dry_crud/templates/app/views/list/_search.html.erb +1 -1
  20. data/lib/generators/dry_crud/templates/app/views/list/index.html.erb +4 -4
  21. data/lib/generators/dry_crud/templates/app/views/shared/_error_messages.html.erb +3 -1
  22. data/lib/generators/dry_crud/templates/config/locales/en_crud.yml +63 -0
  23. data/lib/generators/dry_crud/templates/test/crud_test_model.rb +93 -58
  24. data/lib/generators/dry_crud/templates/test/custom_assertions.rb +24 -13
  25. data/lib/generators/dry_crud/templates/test/functional/crud_controller_test_helper.rb +26 -56
  26. data/lib/generators/dry_crud/templates/test/functional/crud_test_models_controller_test.rb +47 -41
  27. data/lib/generators/dry_crud/templates/test/unit/custom_assertions_test.rb +28 -24
  28. data/lib/generators/dry_crud/templates/test/unit/helpers/crud_helper_test.rb +20 -34
  29. data/lib/generators/dry_crud/templates/test/unit/helpers/list_helper_test.rb +39 -53
  30. data/lib/generators/dry_crud/templates/test/unit/helpers/render_inheritable_test.rb +33 -33
  31. data/lib/generators/dry_crud/templates/test/unit/helpers/standard_form_builder_test.rb +27 -27
  32. data/lib/generators/dry_crud/templates/test/unit/helpers/standard_helper_test.rb +103 -50
  33. data/lib/generators/dry_crud/templates/test/unit/helpers/standard_table_builder_test.rb +52 -24
  34. data/test/templates/Gemfile +34 -0
  35. data/test/templates/app/controllers/ajax_controller.rb +3 -3
  36. data/test/templates/app/controllers/application_controller.rb +1 -1
  37. data/test/templates/app/controllers/cities_controller.rb +2 -5
  38. data/test/templates/app/controllers/people_controller.rb +5 -5
  39. data/test/templates/app/controllers/vips_controller.rb +6 -11
  40. data/test/templates/app/helpers/people_helper.rb +2 -2
  41. data/test/templates/app/models/city.rb +9 -9
  42. data/test/templates/app/models/person.rb +5 -4
  43. data/test/templates/app/views/ajax/_actions_index.html.erb +2 -2
  44. data/test/templates/app/views/cities/_form.html.erb +5 -1
  45. data/test/templates/app/views/layouts/_menu.html.erb +3 -3
  46. data/test/templates/app/views/people/_attrs.html.erb +3 -3
  47. data/test/templates/config/database.yml +22 -0
  48. data/test/templates/config/locales/en_cities.yml +56 -0
  49. data/test/templates/config/routes.rb +5 -5
  50. data/test/templates/db/migrate/20100511174904_create_people_and_cities.rb +5 -2
  51. data/test/templates/db/seeds.rb +38 -29
  52. data/test/templates/test/functional/cities_controller_test.rb +12 -12
  53. data/test/templates/test/functional/people_controller_test.rb +10 -10
  54. 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,7 +1,7 @@
1
1
  class AjaxController < CrudController
2
-
2
+
3
3
  def ajax
4
-
4
+
5
5
  end
6
-
6
+
7
7
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  class ApplicationController < ActionController::Base
5
5
  helper :standard
6
-
6
+
7
7
  protect_from_forgery # See ActionController::RequestForgeryProtection for details
8
8
 
9
9
  # Scrub sensitive parameters from your log
@@ -1,11 +1,8 @@
1
1
  class CitiesController < AjaxController
2
-
2
+
3
3
  def show
4
4
  respond_to do |format|
5
- format.html do
6
- flash.keep
7
- redirect_to_index
8
- end
5
+ format.html { redirect_to_index flash }
9
6
  format.xml { render :xml => @entry }
10
7
  end
11
8
  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,8 +1,8 @@
1
1
  module PeopleHelper
2
-
2
+
3
3
  def format_income(person)
4
4
  income = person.income
5
5
  income.present? ? "#{f(income)} $" : StandardHelper::EMPTY_STRING
6
6
  end
7
-
7
+
8
8
  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 label
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, "You cannot destroy this city as long as it has any inhabitants")
20
+ errors.add(:base, :protect_with_inhabitants)
21
21
  false
22
22
  end
23
23
  end
24
-
24
+
25
25
  end
@@ -1,9 +1,10 @@
1
1
  class Person < ActiveRecord::Base
2
2
 
3
- alias_attribute :label, :name
4
-
5
3
  belongs_to :city
6
-
4
+
7
5
  validates :name, :presence => true
8
-
6
+
7
+ def to_s
8
+ name
9
+ end
9
10
  end
@@ -1,4 +1,4 @@
1
- <%= render :partial => 'crud/actions_index' %>
1
+ <%= render :partial => 'crud/actions_index' %>
2
2
 
3
- <%= link_action 'Ajahx', nil, {:action => 'ajax'}, :method => :get, :remote => true %>
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, ['BR', 'CH', 'DE', 'GB', 'JP', 'USA'], :to_s, :to_s, { :prompt => "Please select" })%>
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 'People', people_path %></li>
2
- <li><%= link_to 'Cities', cities_path %></li>
3
- <li><%= link_to 'VIPs', vips_path %></li>
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("I thinks its", "nice") %>
3
- <%= labeled("Check google") do %>
4
- <%= link_to "Maps", "http://map.google.com/?q=#{@entry.name}" %>
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