giraffesoft-resource_controller 0.5.3 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -14
- data/VERSION.yml +4 -0
- data/lib/resource_controller.rb +1 -14
- data/lib/resource_controller/base.rb +2 -2
- data/lib/resource_controller/class_methods.rb +2 -2
- data/lib/resource_controller/helpers.rb +0 -6
- data/lib/resource_controller/helpers/nested.rb +1 -1
- data/lib/resource_controller/singleton.rb +2 -2
- data/test/app/controllers/cms/personnel_controller.rb +2 -0
- data/test/app/controllers/cms/photos_controller.rb +6 -0
- data/test/app/controllers/photos_controller.rb +1 -0
- data/test/app/models/personnel.rb +3 -0
- data/test/app/models/photo.rb +1 -0
- data/test/app/views/cms/photos/edit.rhtml +17 -0
- data/test/app/views/cms/photos/index.rhtml +20 -0
- data/test/app/views/cms/photos/new.rhtml +16 -0
- data/test/app/views/cms/photos/show.rhtml +8 -0
- data/test/config/database.yml +6 -10
- data/test/config/environment.rb +4 -4
- data/test/config/environments/development.rb +0 -1
- data/test/config/initializers/inflections.rb +14 -0
- data/test/config/routes.rb +3 -0
- data/test/db/migrate/013_create_personnel.rb +11 -0
- data/test/db/migrate/014_add_personnel_id_to_photos.rb +9 -0
- data/test/db/schema.rb +9 -3
- data/test/test/fixtures/personnel.yml +5 -0
- data/test/test/functional/cms/options_controller_test.rb +1 -1
- data/test/test/functional/cms/photos_controller_test.rb +43 -0
- data/test/test/functional/cms/products_controller_test.rb +1 -1
- data/test/test/functional/comments_controller_test.rb +1 -1
- data/test/test/functional/images_controller_test.rb +1 -1
- data/test/test/functional/people_controller_test.rb +1 -1
- data/test/test/functional/photos_controller_test.rb +1 -1
- data/test/test/functional/posts_controller_test.rb +1 -1
- data/test/test/functional/projects_controller_test.rb +1 -1
- data/test/test/functional/somethings_controller_test.rb +1 -1
- data/test/test/functional/tags_controller_test.rb +1 -1
- data/test/test/functional/users_controller_test.rb +1 -1
- data/test/test/test_helper.rb +1 -1
- data/test/test/unit/accessors_test.rb +2 -2
- data/test/test/unit/account_test.rb +1 -1
- data/test/test/unit/action_options_test.rb +1 -1
- data/test/test/unit/base_test.rb +1 -1
- data/test/test/unit/comment_test.rb +1 -1
- data/test/test/unit/failable_action_options_test.rb +1 -1
- data/test/test/unit/helpers_test.rb +1 -1
- data/test/test/unit/image_test.rb +1 -1
- data/test/test/unit/option_test.rb +1 -1
- data/test/test/unit/photo_test.rb +1 -1
- data/test/test/unit/post_test.rb +1 -1
- data/test/test/unit/project_test.rb +1 -1
- data/test/test/unit/response_collector_test.rb +1 -1
- data/test/test/unit/something_test.rb +1 -1
- data/test/test/unit/tag_test.rb +1 -1
- data/test/test/unit/urligence_test.rb +1 -1
- data/test/vendor/gems/{resource_controller-0.5.2 → resource_controller-10.0.0} +0 -0
- metadata +57 -69
- data/LICENSE +0 -22
- data/Rakefile +0 -35
- data/init.rb +0 -1
- data/lib/resource_controller/version.rb +0 -9
- data/test/vendor/plugins/shoulda/Rakefile +0 -32
- data/test/vendor/plugins/shoulda/bin/convert_to_should_syntax +0 -40
- data/test/vendor/plugins/shoulda/init.rb +0 -3
- data/test/vendor/plugins/shoulda/lib/shoulda.rb +0 -43
- data/test/vendor/plugins/shoulda/lib/shoulda/active_record_helpers.rb +0 -580
- data/test/vendor/plugins/shoulda/lib/shoulda/color.rb +0 -77
- data/test/vendor/plugins/shoulda/lib/shoulda/controller_tests/controller_tests.rb +0 -467
- data/test/vendor/plugins/shoulda/lib/shoulda/controller_tests/formats/html.rb +0 -201
- data/test/vendor/plugins/shoulda/lib/shoulda/controller_tests/formats/xml.rb +0 -170
- data/test/vendor/plugins/shoulda/lib/shoulda/gem/proc_extensions.rb +0 -14
- data/test/vendor/plugins/shoulda/lib/shoulda/gem/shoulda.rb +0 -239
- data/test/vendor/plugins/shoulda/lib/shoulda/general.rb +0 -118
- data/test/vendor/plugins/shoulda/lib/shoulda/private_helpers.rb +0 -22
data/README.rdoc
CHANGED
@@ -4,21 +4,9 @@ resource_controller makes RESTful controllers easier, more maintainable, and sup
|
|
4
4
|
|
5
5
|
== Get It
|
6
6
|
|
7
|
-
|
7
|
+
Install it as a plugin:
|
8
8
|
|
9
|
-
|
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
|
|
data/VERSION.yml
ADDED
data/lib/resource_controller.rb
CHANGED
@@ -1,17 +1,4 @@
|
|
1
|
-
|
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
|
+
require_dependency 'application'
|
15
2
|
|
16
3
|
module ResourceController
|
17
4
|
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
|
@@ -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
|
data/test/app/models/photo.rb
CHANGED
@@ -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 %>
|
data/test/config/database.yml
CHANGED
@@ -1,13 +1,9 @@
|
|
1
1
|
development:
|
2
|
-
adapter:
|
3
|
-
database:
|
4
|
-
|
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:
|
10
|
-
database:
|
11
|
-
|
12
|
-
password:
|
13
|
-
socket: /tmp/mysql.sock
|
7
|
+
adapter: sqlite3
|
8
|
+
database: db/test.sqlite3
|
9
|
+
timeout: 5000
|
data/test/config/environment.rb
CHANGED
@@ -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.
|
8
|
+
RAILS_GEM_VERSION = '2.3.0' 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"
|
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
|
@@ -14,7 +14,6 @@ config.breakpoint_server = true
|
|
14
14
|
# Show full error reports and disable caching
|
15
15
|
config.action_controller.consider_all_requests_local = true
|
16
16
|
config.action_controller.perform_caching = false
|
17
|
-
config.action_view.cache_template_extensions = false
|
18
17
|
config.action_view.debug_rjs = true
|
19
18
|
|
20
19
|
# 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
|
data/test/config/routes.rb
CHANGED
data/test/db/schema.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# This file is auto-generated from the current state of the database. Instead of editing this file,
|
2
|
-
# please use the migrations feature of
|
2
|
+
# please use the migrations feature of Active Record to incrementally modify your database, and
|
3
3
|
# then regenerate this schema definition.
|
4
4
|
#
|
5
5
|
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
|
@@ -9,7 +9,7 @@
|
|
9
9
|
#
|
10
10
|
# It's strongly recommended to check this file into your version control system.
|
11
11
|
|
12
|
-
ActiveRecord::Schema.define(:version =>
|
12
|
+
ActiveRecord::Schema.define(:version => 14) do
|
13
13
|
|
14
14
|
create_table "accounts", :force => true do |t|
|
15
15
|
t.string "name"
|
@@ -33,9 +33,15 @@ ActiveRecord::Schema.define(:version => 12) do
|
|
33
33
|
t.string "title"
|
34
34
|
end
|
35
35
|
|
36
|
+
create_table "personnel", :force => true do |t|
|
37
|
+
t.datetime "created_at"
|
38
|
+
t.datetime "updated_at"
|
39
|
+
end
|
40
|
+
|
36
41
|
create_table "photos", :force => true do |t|
|
37
42
|
t.string "title"
|
38
43
|
t.integer "account_id"
|
44
|
+
t.integer "personnel_id"
|
39
45
|
end
|
40
46
|
|
41
47
|
create_table "photos_tags", :force => true do |t|
|
@@ -45,7 +51,7 @@ ActiveRecord::Schema.define(:version => 12) do
|
|
45
51
|
|
46
52
|
create_table "posts", :force => true do |t|
|
47
53
|
t.string "title", :default => ""
|
48
|
-
t.text "body"
|
54
|
+
t.text "body", :default => ""
|
49
55
|
end
|
50
56
|
|
51
57
|
create_table "products", :force => true do |t|
|
@@ -4,7 +4,7 @@ require 'cms/options_controller'
|
|
4
4
|
# Re-raise errors caught by the controller.
|
5
5
|
class Cms::OptionsController; def rescue_action(e) raise e end; end
|
6
6
|
|
7
|
-
class Cms::OptionsControllerTest <
|
7
|
+
class Cms::OptionsControllerTest < ActionController::TestCase
|
8
8
|
def setup
|
9
9
|
@controller = Cms::OptionsController.new
|
10
10
|
@request = ActionController::TestRequest.new
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
require 'cms/photos_controller'
|
3
|
+
|
4
|
+
# Re-raise errors caught by the controller.
|
5
|
+
class Cms::PhotosController; def rescue_action(e) raise e end; end
|
6
|
+
|
7
|
+
class Cms::PhotosControllerTest < ActionController::TestCase
|
8
|
+
def setup
|
9
|
+
@controller = Cms::PhotosController.new
|
10
|
+
@request = ActionController::TestRequest.new
|
11
|
+
@response = ActionController::TestResponse.new
|
12
|
+
@photo = Photo.find 1
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with personnel as parent" do
|
16
|
+
context "on get to :index" do
|
17
|
+
setup do
|
18
|
+
get :index, :personnel_id => 1
|
19
|
+
end
|
20
|
+
|
21
|
+
should_respond_with :success
|
22
|
+
should_render_template "index"
|
23
|
+
should_assign_to :photos
|
24
|
+
should_assign_to :personnel
|
25
|
+
should "scope photos to personnel" do
|
26
|
+
assert assigns(:photos).all? { |photo| photo.personnel.id == 1 }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "on post to :create" do
|
31
|
+
setup do
|
32
|
+
post :create, :personnel_id => 1, :photo => {}
|
33
|
+
end
|
34
|
+
|
35
|
+
should_redirect_to 'cms_personnel_photo_path(@photo.personnel, @photo)'
|
36
|
+
should_assign_to :photo
|
37
|
+
should_assign_to :personnel
|
38
|
+
should "scope photo to personel" do
|
39
|
+
assert personnel(:one), assigns(:photo).personnel
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -4,7 +4,7 @@ require 'cms/products_controller'
|
|
4
4
|
# Re-raise errors caught by the controller.
|
5
5
|
class Cms::ProductsController; def rescue_action(e) raise e end; end
|
6
6
|
|
7
|
-
class Cms::ProductsControllerTest <
|
7
|
+
class Cms::ProductsControllerTest < ActionController::TestCase
|
8
8
|
def setup
|
9
9
|
@controller = Cms::ProductsController.new
|
10
10
|
@request = ActionController::TestRequest.new
|