giraffesoft-resource_controller 0.4.9 → 0.4.10
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 +312 -1
- data/lib/resource_controller.rb +10 -5
- data/lib/resource_controller/class_methods.rb +3 -1
- data/lib/resource_controller/controller.rb +6 -0
- data/lib/resource_controller/helpers/nested.rb +21 -3
- data/lib/resource_controller/helpers/singleton_customizations.rb +60 -0
- data/lib/resource_controller/helpers/urls.rb +5 -1
- data/lib/resource_controller/singleton.rb +15 -0
- data/lib/resource_controller/version.rb +1 -1
- data/lib/tasks/gem.rake +1 -1
- data/test/app/controllers/accounts_controller.rb +6 -0
- data/test/app/controllers/cms/products_controller.rb +1 -1
- data/test/app/controllers/images_controller.rb +4 -0
- data/test/app/controllers/options_controller.rb +8 -0
- data/test/app/helpers/accounts_helper.rb +2 -0
- data/test/app/helpers/images_helper.rb +2 -0
- data/test/app/models/account.rb +1 -0
- data/test/app/models/image.rb +3 -0
- data/test/app/models/user.rb +3 -0
- data/test/app/views/accounts/_form.html.erb +4 -0
- data/test/app/views/accounts/edit.html.erb +14 -0
- data/test/app/views/accounts/new.html.erb +12 -0
- data/test/app/views/accounts/show.html.erb +5 -0
- data/test/app/views/images/_form.html.erb +4 -0
- data/test/app/views/images/edit.html.erb +14 -0
- data/test/app/views/images/new.html.erb +12 -0
- data/test/app/views/options/_form.html.erb +8 -0
- data/test/app/views/options/edit.html.erb +16 -0
- data/test/app/views/options/index.html.erb +21 -0
- data/test/app/views/options/new.html.erb +12 -0
- data/test/app/views/options/show.html.erb +10 -0
- data/test/config/database.yml +0 -3
- data/test/config/environment.rb +2 -2
- data/test/config/routes.rb +8 -1
- data/test/db/migrate/002_create_products.rb +1 -1
- data/test/db/migrate/004_create_options.rb +3 -2
- data/test/db/migrate/011_create_images.rb +12 -0
- data/test/db/migrate/012_create_users.rb +11 -0
- data/test/db/schema.rb +13 -6
- data/test/test/fixtures/images.yml +6 -0
- data/test/test/fixtures/users.yml +5 -0
- data/test/test/functional/images_controller_test.rb +37 -0
- data/test/test/unit/helpers/current_objects_test.rb +6 -0
- data/test/test/unit/helpers/nested_test.rb +5 -1
- data/test/test/unit/helpers/singleton_current_objects_test.rb +68 -0
- data/test/test/unit/helpers/singleton_nested_test.rb +77 -0
- data/test/test/unit/helpers/singleton_urls_test.rb +67 -0
- data/test/test/unit/helpers/urls_test.rb +5 -1
- data/test/test/unit/image_test.rb +7 -0
- metadata +35 -2
@@ -110,7 +110,11 @@ module ResourceController::Helpers::Urls
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def parent_url_options
|
113
|
-
parent?
|
113
|
+
if parent?
|
114
|
+
parent_singleton? ? parent_type.to_sym : [parent_type.to_sym, parent_object]
|
115
|
+
else
|
116
|
+
nil
|
117
|
+
end
|
114
118
|
end
|
115
119
|
|
116
120
|
# Returns all of the current namespaces of the current controller, symbolized, in array form.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ResourceController
|
2
|
+
|
3
|
+
# == ResourceController::Singleton
|
4
|
+
#
|
5
|
+
# Inherit from this class to create your RESTful singleton controller. See the README for usage.
|
6
|
+
#
|
7
|
+
class Singleton < ApplicationController
|
8
|
+
unloadable
|
9
|
+
|
10
|
+
def self.inherited(subclass)
|
11
|
+
super
|
12
|
+
subclass.class_eval { resource_controller :singleton }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/tasks/gem.rake
CHANGED
@@ -43,7 +43,7 @@ task :gem => :tag_warn
|
|
43
43
|
|
44
44
|
namespace :gem do
|
45
45
|
desc 'Upload gems to rubyforge.org'
|
46
|
-
task :
|
46
|
+
task :rubyforge => :gem do
|
47
47
|
sh 'rubyforge login'
|
48
48
|
sh "rubyforge add_release giraffesoft resource_controller #{ResourceController::VERSION::STRING} pkg/#{spec.full_name}.gem"
|
49
49
|
sh "rubyforge add_file giraffesoft resource_controller #{ResourceController::VERSION::STRING} pkg/#{spec.full_name}.gem"
|
data/test/app/models/account.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
<h1>Editing Account</h1>
|
2
|
+
|
3
|
+
<%= error_messages_for :account %>
|
4
|
+
|
5
|
+
<% form_for(:account, :url => object_url, :html => { :method => :put }) do |f| %>
|
6
|
+
<%= render :partial => "form", :locals => { :f => f } %>
|
7
|
+
<p>
|
8
|
+
<%=submit_tag "Update"%>
|
9
|
+
</p>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<br/>
|
13
|
+
|
14
|
+
<%= link_to 'Show', object_url %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h1>New Account</h1>
|
2
|
+
|
3
|
+
<%= error_messages_for :account %>
|
4
|
+
|
5
|
+
<% form_for(:account, :url => object_url) do |f| %>
|
6
|
+
<%= render :partial => "form", :locals => { :f => f } %>
|
7
|
+
<p>
|
8
|
+
<%= submit_tag "Create" %>
|
9
|
+
</p>
|
10
|
+
<% end %>
|
11
|
+
<br/>
|
12
|
+
<%= link_to 'Back', object_url %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<h1>Editing Image</h1>
|
2
|
+
|
3
|
+
<%= error_messages_for :image %>
|
4
|
+
|
5
|
+
<% form_for(:image, :url => object_url, :html => { :method => :put }) do |f| %>
|
6
|
+
<%= render :partial => "form", :locals => { :f => f } %>
|
7
|
+
<p>
|
8
|
+
<%=submit_tag "Update"%>
|
9
|
+
</p>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<br/>
|
13
|
+
|
14
|
+
<%= link_to 'Show', object_url %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h1>New Image</h1>
|
2
|
+
|
3
|
+
<%= error_messages_for :image %>
|
4
|
+
|
5
|
+
<% form_for(:image, :url => object_url) do |f| %>
|
6
|
+
<%= render :partial => "form", :locals => { :f => f } %>
|
7
|
+
<p>
|
8
|
+
<%= submit_tag "Create" %>
|
9
|
+
</p>
|
10
|
+
<% end %>
|
11
|
+
<br/>
|
12
|
+
<%= link_to 'Back', object_url %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<h1>Editing Option</h1>
|
2
|
+
|
3
|
+
<%= error_messages_for :option %>
|
4
|
+
|
5
|
+
<% form_for(:option, :url => object_url, :html => { :method => :put }) do |f| %>
|
6
|
+
<%= render :partial => "form", :locals => { :f => f } %>
|
7
|
+
<p>
|
8
|
+
<%=submit_tag "Update"%>
|
9
|
+
</p>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<br/>
|
13
|
+
|
14
|
+
<%= link_to 'Show', object_url %>
|
15
|
+
|
|
16
|
+
<%= link_to 'Back', collection_url %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<h1>Listing Options</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>Account</th>
|
6
|
+
<th>Title</th>
|
7
|
+
</tr>
|
8
|
+
<%- @options.each do |option|%>
|
9
|
+
<tr>
|
10
|
+
<td><%=h option.account_id %></td>
|
11
|
+
<td><%=h option.title %></td>
|
12
|
+
|
13
|
+
<td><%=link_to 'Show', object_url(option) %></td>
|
14
|
+
<td><%=link_to 'Edit', edit_object_url(option) %></td>
|
15
|
+
<td><%=link_to 'Destroy', object_url(option), :confirm => 'Are you sure?', :method => :delete %></td>
|
16
|
+
</tr>
|
17
|
+
<% end %>
|
18
|
+
</table>
|
19
|
+
<br/>
|
20
|
+
|
21
|
+
<%= link_to 'New Option', new_object_url %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<h1>New Option</h1>
|
2
|
+
|
3
|
+
<%= error_messages_for :option %>
|
4
|
+
|
5
|
+
<% form_for(:option, :url => collection_url) do |f| %>
|
6
|
+
<%= render :partial => "form", :locals => { :f => f } %>
|
7
|
+
<p>
|
8
|
+
<%= submit_tag "Create" %>
|
9
|
+
</p>
|
10
|
+
<% end %>
|
11
|
+
<br/>
|
12
|
+
<%= link_to 'Back', collection_url %>
|
data/test/config/database.yml
CHANGED
@@ -5,9 +5,6 @@ development:
|
|
5
5
|
password:
|
6
6
|
socket: /tmp/mysql.sock
|
7
7
|
|
8
|
-
# Warning: The database defined as 'test' will be erased and
|
9
|
-
# re-generated from your development database when you run 'rake'.
|
10
|
-
# Do not set this db to the same as development or production.
|
11
8
|
test:
|
12
9
|
adapter: mysql
|
13
10
|
database: resource_controller_test
|
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.0.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')
|
@@ -43,7 +43,7 @@ Rails::Initializer.run do |config|
|
|
43
43
|
|
44
44
|
# See Rails::Configuration for more options
|
45
45
|
|
46
|
-
config.action_controller.session = { :session_key => "_myapp_session", :secret => "
|
46
|
+
config.action_controller.session = { :session_key => "_myapp_session", :secret => "6c1372e61789239a727cdbc8252eb6da" }
|
47
47
|
end
|
48
48
|
|
49
49
|
require "#{RAILS_ROOT}/../init"
|
data/test/config/routes.rb
CHANGED
@@ -7,6 +7,7 @@ ActionController::Routing::Routes.draw do |map|
|
|
7
7
|
|
8
8
|
map.resources :users do |user|
|
9
9
|
user.resources :photos, :name_prefix => "user_"
|
10
|
+
user.resource :image
|
10
11
|
end
|
11
12
|
|
12
13
|
map.resources :somethings
|
@@ -26,7 +27,13 @@ ActionController::Routing::Routes.draw do |map|
|
|
26
27
|
end
|
27
28
|
|
28
29
|
map.resources :comments
|
29
|
-
|
30
|
+
|
31
|
+
map.resource :account, :has_many => :options
|
32
|
+
|
33
|
+
map.resource :image
|
34
|
+
|
35
|
+
map.resources :options
|
36
|
+
|
30
37
|
# The priority is based upon order of creation: first created -> highest priority.
|
31
38
|
|
32
39
|
# Sample of regular route:
|
data/test/db/schema.rb
CHANGED
@@ -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 => 12) do
|
13
13
|
|
14
14
|
create_table "accounts", :force => true do |t|
|
15
15
|
t.string "name"
|
@@ -21,8 +21,15 @@ ActiveRecord::Schema.define(:version => 11) do
|
|
21
21
|
t.text "body"
|
22
22
|
end
|
23
23
|
|
24
|
+
create_table "images", :force => true do |t|
|
25
|
+
t.integer "user_id"
|
26
|
+
t.datetime "created_at"
|
27
|
+
t.datetime "updated_at"
|
28
|
+
end
|
29
|
+
|
24
30
|
create_table "options", :force => true do |t|
|
25
31
|
t.integer "product_id"
|
32
|
+
t.integer "account_id"
|
26
33
|
t.string "title"
|
27
34
|
end
|
28
35
|
|
@@ -49,11 +56,6 @@ ActiveRecord::Schema.define(:version => 11) do
|
|
49
56
|
t.string "title"
|
50
57
|
end
|
51
58
|
|
52
|
-
create_table "ratings", :force => true do |t|
|
53
|
-
t.integer "comment_id"
|
54
|
-
t.integer "stars"
|
55
|
-
end
|
56
|
-
|
57
59
|
create_table "somethings", :force => true do |t|
|
58
60
|
t.string "title"
|
59
61
|
end
|
@@ -62,4 +64,9 @@ ActiveRecord::Schema.define(:version => 11) do
|
|
62
64
|
t.string "name"
|
63
65
|
end
|
64
66
|
|
67
|
+
create_table "users", :force => true do |t|
|
68
|
+
t.datetime "created_at"
|
69
|
+
t.datetime "updated_at"
|
70
|
+
end
|
71
|
+
|
65
72
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require 'images_controller'
|
3
|
+
|
4
|
+
# Re-raise errors caught by the controller.
|
5
|
+
class ImagesController; def rescue_action(e) raise e end; end
|
6
|
+
|
7
|
+
class ImagesControllerTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@controller = ImagesController.new
|
10
|
+
@request = ActionController::TestRequest.new
|
11
|
+
@response = ActionController::TestResponse.new
|
12
|
+
@image = images :one
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with user as parent" do
|
16
|
+
|
17
|
+
context "on post to :create" do
|
18
|
+
setup do
|
19
|
+
post :create, :user_id => 1, :photo => {}
|
20
|
+
end
|
21
|
+
|
22
|
+
should_redirect_to 'user_image_path(@image.user)'
|
23
|
+
should_assign_to :image
|
24
|
+
should_assign_to :user
|
25
|
+
should "scope image to user" do
|
26
|
+
assert users(:one), assigns(:image).user
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
should "not respond to show" do
|
33
|
+
assert_raise(ActionController::UnknownAction) do
|
34
|
+
get :show
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|