resource_controller 0.5.3 → 0.6.6

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 (80) hide show
  1. data/README.rdoc +18 -14
  2. data/VERSION.yml +5 -0
  3. data/generators/scaffold_resource/templates/rspec/routing_spec.rb +8 -8
  4. data/generators/scaffold_resource/templates/rspec/views/index_spec.rb +2 -2
  5. data/lib/resource_controller.rb +5 -14
  6. data/lib/resource_controller/base.rb +2 -2
  7. data/lib/resource_controller/class_methods.rb +2 -2
  8. data/lib/resource_controller/controller.rb +3 -2
  9. data/lib/resource_controller/helpers.rb +0 -6
  10. data/lib/resource_controller/helpers/nested.rb +1 -1
  11. data/lib/resource_controller/singleton.rb +2 -2
  12. data/test/app/controllers/{application.rb → application_controller.rb} +0 -2
  13. data/test/app/controllers/cms/personnel_controller.rb +2 -0
  14. data/test/app/controllers/cms/photos_controller.rb +6 -0
  15. data/test/app/controllers/photos_controller.rb +1 -0
  16. data/test/app/models/personnel.rb +3 -0
  17. data/test/app/models/photo.rb +1 -0
  18. data/test/app/views/cms/photos/edit.rhtml +17 -0
  19. data/test/app/views/cms/photos/index.rhtml +20 -0
  20. data/test/app/views/cms/photos/new.rhtml +16 -0
  21. data/test/app/views/cms/photos/show.rhtml +8 -0
  22. data/test/config/boot.rb +6 -5
  23. data/test/config/database.yml +6 -10
  24. data/test/config/environment.rb +4 -4
  25. data/test/config/environments/development.rb +0 -4
  26. data/test/config/initializers/inflections.rb +14 -0
  27. data/test/config/routes.rb +3 -0
  28. data/test/db/migrate/013_create_personnel.rb +11 -0
  29. data/test/db/migrate/014_add_personnel_id_to_photos.rb +9 -0
  30. data/test/db/schema.rb +9 -3
  31. data/test/test/fixtures/personnel.yml +5 -0
  32. data/test/test/functional/cms/options_controller_test.rb +1 -1
  33. data/test/test/functional/cms/photos_controller_test.rb +43 -0
  34. data/test/test/functional/cms/products_controller_test.rb +1 -1
  35. data/test/test/functional/comments_controller_test.rb +2 -9
  36. data/test/test/functional/images_controller_test.rb +1 -8
  37. data/test/test/functional/people_controller_test.rb +2 -9
  38. data/test/test/functional/photos_controller_test.rb +2 -9
  39. data/test/test/functional/posts_controller_test.rb +2 -9
  40. data/test/test/functional/projects_controller_test.rb +12 -9
  41. data/test/test/functional/somethings_controller_test.rb +2 -9
  42. data/test/test/functional/tags_controller_test.rb +2 -9
  43. data/test/test/functional/users_controller_test.rb +2 -9
  44. data/test/test/test_helper.rb +4 -3
  45. data/test/test/unit/accessors_test.rb +2 -2
  46. data/test/test/unit/account_test.rb +1 -1
  47. data/test/test/unit/action_options_test.rb +1 -1
  48. data/test/test/unit/base_test.rb +1 -1
  49. data/test/test/unit/comment_test.rb +1 -1
  50. data/test/test/unit/failable_action_options_test.rb +1 -1
  51. data/test/test/unit/helpers_test.rb +1 -1
  52. data/test/test/unit/image_test.rb +1 -1
  53. data/test/test/unit/option_test.rb +1 -1
  54. data/test/test/unit/photo_test.rb +1 -1
  55. data/test/test/unit/post_test.rb +1 -1
  56. data/test/test/unit/project_test.rb +1 -1
  57. data/test/test/unit/response_collector_test.rb +1 -1
  58. data/test/test/unit/something_test.rb +1 -1
  59. data/test/test/unit/tag_test.rb +1 -1
  60. data/test/test/unit/urligence_test.rb +1 -1
  61. metadata +162 -122
  62. data/Rakefile +0 -35
  63. data/init.rb +0 -1
  64. data/lib/resource_controller/version.rb +0 -9
  65. data/test/log/development.log +0 -3350
  66. data/test/log/test.log +0 -174947
  67. data/test/log/thin.log +0 -12
  68. data/test/vendor/plugins/shoulda/Rakefile +0 -32
  69. data/test/vendor/plugins/shoulda/bin/convert_to_should_syntax +0 -40
  70. data/test/vendor/plugins/shoulda/init.rb +0 -3
  71. data/test/vendor/plugins/shoulda/lib/shoulda.rb +0 -43
  72. data/test/vendor/plugins/shoulda/lib/shoulda/active_record_helpers.rb +0 -580
  73. data/test/vendor/plugins/shoulda/lib/shoulda/color.rb +0 -77
  74. data/test/vendor/plugins/shoulda/lib/shoulda/controller_tests/controller_tests.rb +0 -467
  75. data/test/vendor/plugins/shoulda/lib/shoulda/controller_tests/formats/html.rb +0 -201
  76. data/test/vendor/plugins/shoulda/lib/shoulda/controller_tests/formats/xml.rb +0 -170
  77. data/test/vendor/plugins/shoulda/lib/shoulda/gem/proc_extensions.rb +0 -14
  78. data/test/vendor/plugins/shoulda/lib/shoulda/gem/shoulda.rb +0 -239
  79. data/test/vendor/plugins/shoulda/lib/shoulda/general.rb +0 -118
  80. data/test/vendor/plugins/shoulda/lib/shoulda/private_helpers.rb +0 -22
@@ -4,21 +4,9 @@ resource_controller makes RESTful controllers easier, more maintainable, and sup
4
4
 
5
5
  == Get It
6
6
 
7
- Add it as a gem dependency
7
+ Install it as a plugin:
8
8
 
9
- config.gem 'resource_controller'
10
-
11
- ...or for the development version
12
-
13
- config.gem 'giraffesoft-resource_controller', :lib => 'resource_controller', :source => 'http://gems.github.com'
14
-
15
- Or install it as a gem manually
16
-
17
- sudo gem install resource_controller
18
-
19
- ...or for the development version
20
-
21
- sudo gem install giraffesoft-resource_controller
9
+ script/plugin install git://github.com/giraffesoft/resource_controller.git
22
10
 
23
11
  Or grab the source
24
12
 
@@ -84,6 +72,16 @@ Or you can create a whole new block. This syntax destroys everything that's the
84
72
  wants.js { render :template => "show.rjs" }
85
73
  end
86
74
  end
75
+
76
+ If you have a nested resource and want to redirect to the parent after create/update and destroy you can do this in the object controller
77
+
78
+ class CommentsController < ResourceController::Base
79
+ belongs_to :post
80
+
81
+ create.wants.html { redirect_to smart_url(parent_url_options) }
82
+ update.wants.html { redirect_to smart_url(parent_url_options) }
83
+ destroy.wants.html { redirect_to smart_url(parent_url_options) }
84
+ end
87
85
 
88
86
  === Scoping
89
87
 
@@ -118,6 +116,12 @@ If you want to create a singleton RESTful controller inherit from ResourceContro
118
116
  class AccountsController < ResourceController::Singleton
119
117
  end
120
118
 
119
+ ...or if need to inherit from some other class:
120
+
121
+ class AccountsController < ApplicationController
122
+ resource_controller :singleton
123
+ end
124
+
121
125
  *Note:* This type of controllers handle a single resource only so the index action and all the collection helpers (collection_url, collection_path...) are not available for them.
122
126
 
123
127
  Loading objects in singletons is similar to plural controllers with one exception. For non-nested singleton controllers you should override the object method as it defaults to nil for them.
@@ -0,0 +1,5 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 6
4
+ :build:
5
+ :patch: 6
@@ -11,20 +11,20 @@ describe <%= controller_class_name %>Controller do
11
11
  route_for(:controller => "<%= table_name %>", :action => "new").should == "/<%= table_name %>/new"
12
12
  end
13
13
 
14
- it "should map { :controller => '<%= table_name %>', :action => 'show', :id => 1 } to /<%= table_name %>/1" do
15
- route_for(:controller => "<%= table_name %>", :action => "show", :id => 1).should == "/<%= table_name %>/1"
14
+ it "should map { :controller => '<%= table_name %>', :action => 'show', :id => '1'} to /<%= table_name %>/1" do
15
+ route_for(:controller => "<%= table_name %>", :action => "show", :id => "1").should == "/<%= table_name %>/1"
16
16
  end
17
17
 
18
- it "should map { :controller => '<%= table_name %>', :action => 'edit', :id => 1 } to /<%= table_name %>/1<%= resource_edit_path %>" do
19
- route_for(:controller => "<%= table_name %>", :action => "edit", :id => 1).should == "/<%= table_name %>/1<%= resource_edit_path %>"
18
+ it "should map { :controller => '<%= table_name %>', :action => 'edit', :id => '1' } to /<%= table_name %>/1<%= resource_edit_path %>" do
19
+ route_for(:controller => "<%= table_name %>", :action => "edit", :id => "1").should == "/<%= table_name %>/1<%= resource_edit_path %>"
20
20
  end
21
21
 
22
- it "should map { :controller => '<%= table_name %>', :action => 'update', :id => 1} to /<%= table_name %>/1" do
23
- route_for(:controller => "<%= table_name %>", :action => "update", :id => 1).should == "/<%= table_name %>/1"
22
+ it "should map { :controller => '<%= table_name %>', :action => 'update', :id => '1' } to /<%= table_name %>/1" do
23
+ route_for(:controller => "<%= table_name %>", :action => "update", :id => "1").should == {:path => "/<%= table_name %>/1", :method => :put}
24
24
  end
25
25
 
26
- it "should map { :controller => '<%= table_name %>', :action => 'destroy', :id => 1} to /<%= table_name %>/1" do
27
- route_for(:controller => "<%= table_name %>", :action => "destroy", :id => 1).should == "/<%= table_name %>/1"
26
+ it "should map { :controller => '<%= table_name %>', :action => 'destroy', :id => '1' } to /<%= table_name %>/1" do
27
+ route_for(:controller => "<%= table_name %>", :action => "destroy", :id => "1").should == {:path => "/<%= table_name %>/1", :method => :delete}
28
28
  end
29
29
  end
30
30
 
@@ -11,9 +11,9 @@ describe "/<%= table_name %>/index.<%= default_file_extension %>" do
11
11
  <% end -%><% end %>
12
12
  assigns[:<%= table_name %>] = [<%= file_name %>_98, <%= file_name %>_99]
13
13
 
14
- template.stub!(:object_url).and_return(<%= file_name %>_path(@<%= file_name %>))
14
+ template.stub!(:object_url).and_return(<%= file_name %>_path(<%= file_name %>_99))
15
15
  template.stub!(:new_object_url).and_return(new_<%= file_name %>_path)
16
- template.stub!(:edit_object_url).and_return(edit_<%= file_name %>_path(@<%= file_name %>))
16
+ template.stub!(:edit_object_url).and_return(edit_<%= file_name %>_path(<%= file_name %>_99))
17
17
  end
18
18
 
19
19
  it "should render list of <%= table_name %>" do
@@ -1,17 +1,8 @@
1
- $LOAD_PATH << File.dirname(__FILE__) unless $LOAD_PATH.include?(File.dirname(__FILE__))
2
- require 'application'
3
- require 'resource_controller/accessors'
4
- require 'resource_controller/action_options'
5
- require 'resource_controller/actions'
6
- require 'resource_controller/base'
7
- require 'resource_controller/class_methods'
8
- require 'resource_controller/controller'
9
- require 'resource_controller/failable_action_options'
10
- require 'resource_controller/helpers'
11
- require 'resource_controller/response_collector'
12
- require 'resource_controller/singleton'
13
- require 'resource_controller/version'
14
- require 'urligence'
1
+ begin
2
+ require_dependency 'application_controller'
3
+ rescue LoadError => e
4
+ require_dependency 'application'
5
+ end
15
6
 
16
7
  module ResourceController
17
8
  ACTIONS = [:index, :show, :new_action, :create, :edit, :update, :destroy].freeze
@@ -4,7 +4,7 @@ module ResourceController
4
4
  #
5
5
  # Inherit from this class to create your RESTful controller. See the README for usage.
6
6
  #
7
- class Base < ApplicationController
7
+ class Base < ::ApplicationController
8
8
  unloadable
9
9
 
10
10
  def self.inherited(subclass)
@@ -12,4 +12,4 @@ module ResourceController
12
12
  subclass.class_eval { resource_controller }
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -17,8 +17,8 @@ module ResourceController
17
17
  actions_to_remove += [*config[:except]] if config[:except]
18
18
  actions_to_remove.uniq!
19
19
 
20
- actions_to_remove.each { |action| undef_method(action)}
20
+ actions_to_remove.each { |action| undef_method(action) if method_defined?(action) }
21
21
  end
22
22
 
23
23
  end
24
- end
24
+ end
@@ -11,7 +11,7 @@ module ResourceController
11
11
  NAME_ACCESSORS.each { |accessor| send(accessor, controller_name.singularize.underscore) }
12
12
 
13
13
  ACTIONS.each do |action|
14
- class_scoping_reader action, FAILABLE_ACTIONS.include?(action) ? FailableActionOptions.new : ActionOptions.new
14
+ class_scoping_reader action, FAILABLE_ACTIONS.include?(action) ? ResourceController::FailableActionOptions.new : ResourceController::ActionOptions.new
15
15
  end
16
16
 
17
17
  self.helper_method :object_url, :edit_object_url, :new_object_url, :collection_url, :object, :collection,
@@ -56,6 +56,7 @@ module ResourceController
56
56
  destroy do
57
57
  flash "Successfully removed!"
58
58
  wants.html { redirect_to collection_url }
59
+ failure.wants.html { redirect_to object_url }
59
60
  end
60
61
 
61
62
  class << self
@@ -66,4 +67,4 @@ module ResourceController
66
67
  end
67
68
  end
68
69
  end
69
- end
70
+ end
@@ -1,9 +1,3 @@
1
- require 'resource_controller/helpers/current_objects'
2
- require 'resource_controller/helpers/internal'
3
- require 'resource_controller/helpers/nested'
4
- require 'resource_controller/helpers/singleton_customizations'
5
- require 'resource_controller/helpers/urls'
6
-
7
1
  module ResourceController
8
2
  # == ResourceController::Helpers
9
3
  #
@@ -37,7 +37,7 @@ module ResourceController
37
37
  # Returns true/false based on whether or not a parent is a singleton.
38
38
  #
39
39
  def parent_singleton?
40
- !parent_type_from_request.nil?
40
+ !parent_type_from_request.nil? && parent_type_from_params.nil?
41
41
  end
42
42
 
43
43
  # Returns the current parent param, if there is a parent. (i.e. params[:post_id])
@@ -4,7 +4,7 @@ module ResourceController
4
4
  #
5
5
  # Inherit from this class to create your RESTful singleton controller. See the README for usage.
6
6
  #
7
- class Singleton < ApplicationController
7
+ class Singleton < ::ApplicationController
8
8
  unloadable
9
9
 
10
10
  def self.inherited(subclass)
@@ -12,4 +12,4 @@ module ResourceController
12
12
  subclass.class_eval { resource_controller :singleton }
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -2,6 +2,4 @@
2
2
  # Likewise, all the methods added will be available for all controllers.
3
3
 
4
4
  class ApplicationController < ActionController::Base
5
- # Pick a unique cookie name to distinguish our session data from others'
6
- session :session_key => '_myapp_session'
7
5
  end
@@ -0,0 +1,2 @@
1
+ class Cms::PersonnelController < ResourceController::Base
2
+ end
@@ -0,0 +1,6 @@
1
+ class Cms::PhotosController < ResourceController::Base
2
+ actions :all, :except => :update
3
+
4
+ belongs_to :personnel
5
+ create.flash { "#{@photo.title} was created!" }
6
+ end
@@ -1,5 +1,6 @@
1
1
  class PhotosController < ResourceController::Base
2
2
  actions :all, :except => :update
3
+ actions :all, :except => :update
3
4
 
4
5
  belongs_to :user
5
6
  create.flash { "#{@photo.title} was created!" }
@@ -0,0 +1,3 @@
1
+ class Personnel < ActiveRecord::Base
2
+ has_many :photos
3
+ end
@@ -1,4 +1,5 @@
1
1
  class Photo < ActiveRecord::Base
2
2
  has_and_belongs_to_many :tags
3
3
  belongs_to :user, :class_name => "Account", :foreign_key => "account_id"
4
+ belongs_to :personnel
4
5
  end
@@ -0,0 +1,17 @@
1
+ <h1>Editing photo</h1>
2
+
3
+ <%= error_messages_for :photo %>
4
+
5
+ <% form_for(:photo, :url => photo_path(@photo), :html => { :method => :put }) do |f| %>
6
+ <p>
7
+ <b>Title</b><br />
8
+ <%= f.text_field :title %>
9
+ </p>
10
+
11
+ <p>
12
+ <%= submit_tag "Update" %>
13
+ </p>
14
+ <% end %>
15
+
16
+ <%= link_to 'Show', photo_path(@photo) %> |
17
+ <%= link_to 'Back', photos_path %>
@@ -0,0 +1,20 @@
1
+ <h1>Listing photos</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Title</th>
6
+ </tr>
7
+
8
+ <% for photo in @photos %>
9
+ <tr>
10
+ <td><%=h photo.title %></td>
11
+ <td><%= link_to 'Show', object_url(photo) %></td>
12
+ <td><%= link_to 'Edit', edit_object_url(photo) %></td>
13
+ <td><%= link_to 'Destroy', object_url(photo), :confirm => 'Are you sure?', :method => :delete %></td>
14
+ </tr>
15
+ <% end %>
16
+ </table>
17
+
18
+ <br />
19
+
20
+ <%= link_to 'New photo', new_object_url %>
@@ -0,0 +1,16 @@
1
+ <h1>New photo</h1>
2
+
3
+ <%= error_messages_for :photo %>
4
+
5
+ <% form_for(:photo, :url => photos_path) do |f| %>
6
+ <p>
7
+ <b>Title</b><br />
8
+ <%= f.text_field :title %>
9
+ </p>
10
+
11
+ <p>
12
+ <%= submit_tag "Create" %>
13
+ </p>
14
+ <% end %>
15
+
16
+ <%= link_to 'Back', photos_path %>
@@ -0,0 +1,8 @@
1
+ <p>
2
+ <b>Title:</b>
3
+ <%=h @photo.title %>
4
+ </p>
5
+
6
+
7
+ <%= link_to 'Edit', edit_photo_path(@photo) %> |
8
+ <%= link_to 'Back', photos_path %>
@@ -44,6 +44,7 @@ module Rails
44
44
  def load_initializer
45
45
  require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
46
  Rails::Initializer.run(:install_gem_spec_stubs)
47
+ Rails::GemDependency.add_frozen_gem_path
47
48
  end
48
49
  end
49
50
 
@@ -67,7 +68,7 @@ module Rails
67
68
 
68
69
  class << self
69
70
  def rubygems_version
70
- Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
71
+ Gem::RubyGemsVersion rescue nil
71
72
  end
72
73
 
73
74
  def gem_version
@@ -82,14 +83,14 @@ module Rails
82
83
 
83
84
  def load_rubygems
84
85
  require 'rubygems'
85
-
86
- unless rubygems_version >= '0.9.4'
87
- $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
86
+ min_version = '1.3.1'
87
+ unless rubygems_version >= min_version
88
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
88
89
  exit 1
89
90
  end
90
91
 
91
92
  rescue LoadError
92
- $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
93
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
93
94
  exit 1
94
95
  end
95
96
 
@@ -1,13 +1,9 @@
1
1
  development:
2
- adapter: mysql
3
- database: resource_controller_test
4
- username: root
5
- password:
6
- socket: /tmp/mysql.sock
2
+ adapter: sqlite3
3
+ database: db/test.sqlite3
4
+ timeout: 5000
7
5
 
8
6
  test:
9
- adapter: mysql
10
- database: resource_controller_test
11
- username: root
12
- password:
13
- socket: /tmp/mysql.sock
7
+ adapter: sqlite3
8
+ database: db/test.sqlite3
9
+ timeout: 5000
@@ -5,7 +5,7 @@
5
5
  # ENV['RAILS_ENV'] ||= 'production'
6
6
 
7
7
  # Specifies gem version of Rails to use when vendor/rails is not present
8
- RAILS_GEM_VERSION = '2.1.1' unless defined? RAILS_GEM_VERSION
8
+ RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
9
9
 
10
10
  # Bootstrap the Rails environment, frameworks, and default configuration
11
11
  require File.join(File.dirname(__FILE__), 'boot')
@@ -20,7 +20,7 @@ Rails::Initializer.run do |config|
20
20
  # config.plugins = %W( exception_notification ssl_requirement )
21
21
 
22
22
  # Add additional load paths for your own custom dirs
23
- config.load_paths += %W( #{RAILS_ROOT}/../lib )
23
+ # config.load_paths += %W( #{RAILS_ROOT}/../lib )
24
24
 
25
25
  # Force all environments to use the same logger level
26
26
  # (by default production uses :info, the others :debug)
@@ -29,6 +29,8 @@ Rails::Initializer.run do |config|
29
29
  # Use the database for sessions instead of the file system
30
30
  # (create the session table with 'rake db:sessions:create')
31
31
  # config.action_controller.session_store = :active_record_store
32
+ config.gem "resource_controller", :version => "10.0.0"
33
+ config.gem "thoughtbot-shoulda", :lib => "shoulda/rails", :version => "2.9.0"
32
34
 
33
35
  # Use SQL instead of Active Record's schema dumper when creating the test database.
34
36
  # This is necessary if your schema can't be completely dumped by the schema dumper,
@@ -44,6 +46,4 @@ Rails::Initializer.run do |config|
44
46
  # See Rails::Configuration for more options
45
47
 
46
48
  config.action_controller.session = { :session_key => "_myapp_session", :secret => "6c1372e61789239a727cdbc8252eb6da" }
47
-
48
- config.gem 'resource_controller'
49
49
  end
@@ -8,13 +8,9 @@ config.cache_classes = false
8
8
  # Log error messages when you accidentally call methods on nil.
9
9
  config.whiny_nils = true
10
10
 
11
- # Enable the breakpoint server that script/breakpointer connects to
12
- config.breakpoint_server = true
13
-
14
11
  # Show full error reports and disable caching
15
12
  config.action_controller.consider_all_requests_local = true
16
13
  config.action_controller.perform_caching = false
17
- config.action_view.cache_template_extensions = false
18
14
  config.action_view.debug_rjs = true
19
15
 
20
16
  # Don't care if the mailer can't send
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
11
+
12
+ ActiveSupport::Inflector.inflections do |inflect|
13
+ inflect.irregular "personnel", "personnel"
14
+ end
@@ -20,6 +20,9 @@ ActionController::Routing::Routes.draw do |map|
20
20
 
21
21
  map.namespace :cms do |cms|
22
22
  cms.resources :products, :has_many => :options
23
+ cms.resources :personnel do |personnel|
24
+ personnel.resources :photos
25
+ end
23
26
  end
24
27
 
25
28
  map.resources :posts do |post|