Skip to content

Commit

Permalink
Fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
karsthammer committed Aug 3, 2011
2 parents e954491 + 07bcdbf commit 8226549
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 129 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
@@ -1,3 +1,8 @@
# Version 1.2.2

* Fix a bug in params parsing
* Call .scoped only if it is available

# Version 1.2.1

* Fix a bug with namespaces
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,6 +1,6 @@
source "http://rubygems.org"

gem "rails", "3.0.3"
gem "rails", "3.1.0.rc4"
gem "responders", "~> 0.6.0"
gem "has_scope", "~> 0.5.0"
gem "mocha"
Expand Down
120 changes: 68 additions & 52 deletions Gemfile.lock
@@ -1,80 +1,96 @@
GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
actionmailer (3.0.3)
actionpack (= 3.0.3)
mail (~> 2.2.9)
actionpack (3.0.3)
activemodel (= 3.0.3)
activesupport (= 3.0.3)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.4)
rack (~> 1.2.1)
rack-mount (~> 0.6.13)
rack-test (~> 0.5.6)
tzinfo (~> 0.3.23)
activemodel (3.0.3)
activesupport (= 3.0.3)
builder (~> 2.1.2)
i18n (~> 0.4)
activerecord (3.0.3)
activemodel (= 3.0.3)
activesupport (= 3.0.3)
arel (~> 2.0.2)
tzinfo (~> 0.3.23)
activeresource (3.0.3)
activemodel (= 3.0.3)
activesupport (= 3.0.3)
activesupport (3.0.3)
arel (2.0.6)
builder (2.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
actionmailer (3.1.0.rc4)
actionpack (= 3.1.0.rc4)
mail (~> 2.3.0)
actionpack (3.1.0.rc4)
activemodel (= 3.1.0.rc4)
activesupport (= 3.1.0.rc4)
builder (~> 3.0.0)
erubis (~> 2.7.0)
i18n (~> 0.6)
rack (~> 1.3.0)
rack-cache (~> 1.0.1)
rack-mount (~> 0.8.1)
rack-test (~> 0.6.0)
sprockets (~> 2.0.0.beta.10)
tzinfo (~> 0.3.27)
activemodel (3.1.0.rc4)
activesupport (= 3.1.0.rc4)
bcrypt-ruby (~> 2.1.4)
builder (~> 3.0.0)
i18n (~> 0.6)
activerecord (3.1.0.rc4)
activemodel (= 3.1.0.rc4)
activesupport (= 3.1.0.rc4)
arel (~> 2.1.1)
tzinfo (~> 0.3.27)
activeresource (3.1.0.rc4)
activemodel (= 3.1.0.rc4)
activesupport (= 3.1.0.rc4)
activesupport (3.1.0.rc4)
multi_json (~> 1.0)
arel (2.1.1)
bcrypt-ruby (2.1.4)
builder (3.0.0)
erubis (2.7.0)
has_scope (0.5.0)
i18n (0.5.0)
mail (2.2.14)
activesupport (>= 2.3.6)
hike (1.1.0)
i18n (0.6.0)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
mocha (0.9.8)
rake
multi_json (1.0.3)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack (1.3.0)
rack-cache (1.0.2)
rack (>= 0.4)
rack-mount (0.8.1)
rack (>= 1.0.0)
rack-test (0.5.7)
rack-ssl (1.3.2)
rack
rack-test (0.6.0)
rack (>= 1.0)
rails (3.0.3)
actionmailer (= 3.0.3)
actionpack (= 3.0.3)
activerecord (= 3.0.3)
activeresource (= 3.0.3)
activesupport (= 3.0.3)
rails (3.1.0.rc4)
actionmailer (= 3.1.0.rc4)
actionpack (= 3.1.0.rc4)
activerecord (= 3.1.0.rc4)
activeresource (= 3.1.0.rc4)
activesupport (= 3.1.0.rc4)
bundler (~> 1.0)
railties (= 3.0.3)
railties (3.0.3)
actionpack (= 3.0.3)
activesupport (= 3.0.3)
railties (= 3.1.0.rc4)
railties (3.1.0.rc4)
actionpack (= 3.1.0.rc4)
activesupport (= 3.1.0.rc4)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
thor (~> 0.14.4)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.8.7)
responders (0.6.2)
test-unit (2.2.0)
rdoc (3.6.1)
responders (0.6.4)
sprockets (2.0.0.beta.10)
hike (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
test-unit (2.3.0)
thor (0.14.6)
tilt (1.3.2)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.24)
tzinfo (0.3.28)

PLATFORMS
ruby

DEPENDENCIES
has_scope (~> 0.5.0)
mocha
rails (= 3.0.3)
rails (= 3.1.0.rc4)
responders (~> 0.6.0)
test-unit
22 changes: 11 additions & 11 deletions README.rdoc
Expand Up @@ -8,32 +8,30 @@ Plus, making your controllers follow a pattern, it helps you to write better
code by following fat models and skinny controllers convention. There are
two screencasts available besides this README:

http://railscasts.com/episodes/230-inherited-resources
http://akitaonrails.com/2009/09/01/screencast-real-thin-restful-controllers-with-inherited-resources
* http://railscasts.com/episodes/230-inherited-resources
* http://akitaonrails.com/2009/09/01/screencast-real-thin-restful-controllers-with-inherited-resources

== Installation

=== Rails 3

Inherited Resources master branch is now supports Rails 3 and is NOT backward compatible.
You can let bundler install Inherited Resources by adding this line to your application's Gemfile:

You can let bundler to install Inherited Resources by adding this line to your application's Gemfile:

gem 'inherited_resources', '~> 1.2.1'
gem 'inherited_resources'

And then execute:

bundle install

Or install it yourself as:

gem install inherited_resources --version=1.2.1
gem install inherited_resources

=== Rails 2.3.x

If you want to use the Rails 2.3.x version, you should install:

sudo gem install inherited_resources --version=1.0.6
gem install inherited_resources --version=1.0.6

Or checkout from the v1.0 branch:

Expand Down Expand Up @@ -516,6 +514,8 @@ check this Wiki page:

https://github.com/josevalim/inherited_resources/wiki/Views-Inheritance

Notice that Rails 3.1 ships with view inheritance built-in.

== Some DSL

For those DSL lovers, InheritedResources won't leave you alone. You can overwrite
Expand All @@ -536,9 +536,9 @@ And then you can rewrite the last example as:

== Bugs and Feedback

If you discover any bugs or want to drop a line, join us in the mailing list:
If you discover any bugs, please describe it in the issues tracker, including Rails and Inherited Resources versions.

http://groups.google.com/group/inherited_resources
Questions are better handled on StackOverflow.

Copyright (c) 2009 José Valim http://blog.plataformatec.com.br
Copyright (c) 2011 José Valim http://blog.plataformatec.com.br
See the attached MIT License.
@@ -1,6 +1,3 @@
require 'inherited_resources/blank_slate'
require 'inherited_resources/responder'

module InheritedResources
# = Base
#
Expand All @@ -21,7 +18,7 @@ def self.inherit_resources(base)
extend InheritedResources::UrlHelpers

# Add at least :html mime type
respond_to :html
respond_to :html if self.mimes_for_respond_to.empty?
self.responder = InheritedResources::Responder

helper_method :resource, :collection, :resource_class, :association_chain,
Expand All @@ -33,7 +30,8 @@ def self.inherit_resources(base)
:parent_url, :parent_path,
:smart_resource_url, :smart_collection_url

self.class_attribute :resource_class, :parents_symbols, :resources_configuration, :instance_writer => false
self.class_attribute :resource_class unless self.respond_to? :resource_class
self.class_attribute :parents_symbols, :resources_configuration, :instance_writer => false

protected :resource_class, :parents_symbols, :resources_configuration,
:resource_class?, :parents_symbols?, :resources_configuration?
Expand All @@ -42,4 +40,4 @@ def self.inherit_resources(base)

inherit_resources(self)
end
end
end
6 changes: 4 additions & 2 deletions lib/inherited_resources.rb
@@ -1,10 +1,12 @@
require 'rails/engine'
require 'responders'
require 'inherited_resources/blank_slate'
require 'inherited_resources/responder'

module InheritedResources
ACTIONS = [ :index, :show, :new, :edit, :create, :update, :destroy ] unless self.const_defined?(:ACTIONS)

autoload :Actions, 'inherited_resources/actions'
autoload :Base, 'inherited_resources/base'
autoload :BaseHelpers, 'inherited_resources/base_helpers'
autoload :ShallowHelpers, 'inherited_resources/shallow_helpers'
autoload :BelongsToHelpers, 'inherited_resources/belongs_to_helpers'
Expand All @@ -20,7 +22,7 @@ def self.flash_keys=(array)
Responders::FlashResponder.flash_keys = array
end

class Railtie < ::Rails::Railtie
class Railtie < ::Rails::Engine
config.inherited_resources = InheritedResources
if config.respond_to?(:app_generators)
config.app_generators.scaffold_controller = :inherited_resources_controller
Expand Down
18 changes: 15 additions & 3 deletions lib/inherited_resources/base_helpers.rb
Expand Up @@ -49,7 +49,7 @@ def resource
# instance variable.
#
def build_resource
get_resource_ivar || set_resource_ivar(end_of_association_chain.send(method_for_build, resource_params))
get_resource_ivar || set_resource_ivar(end_of_association_chain.send(method_for_build, *resource_params))
end

# Responsible for saving the resource on :create method. Overwriting this
Expand All @@ -75,7 +75,7 @@ def create_resource(object)
# end
#
def update_resource(object, attributes)
object.update_attributes(attributes)
object.update_attributes(*attributes)
end

# Handle the :destroy method for the resource. Overwrite it to call your
Expand Down Expand Up @@ -300,7 +300,19 @@ def smart_collection_url

# extract attributes from params
def resource_params
params[resource_request_name] || params[resource_instance_name] || {}
rparams = [params[resource_request_name] || params[resource_instance_name] || {}]
rparams << as_role if role_given?
rparams
end

# checking if role given
def role_given?
self.resources_configuration[:self][:role].present?
end

# getting role for mass-asignment
def as_role
{ :as => self.resources_configuration[:self][:role] }
end
end
end
Expand Down
21 changes: 18 additions & 3 deletions lib/inherited_resources/class_methods.rb
Expand Up @@ -255,6 +255,12 @@ def custom_actions(options)
end
end

# Defines the role to use when creating or updating resource.
# Makes sense when using rails 3.1 mass assignment conventions
def with_role(role)
self.resources_configuration[:self][:role] = role.try(:to_sym)
end

private

def acts_as_singleton! #:nodoc:
Expand All @@ -279,15 +285,24 @@ def acts_as_shallow! #:nodoc:
# Initialize resources class accessors and set their default values.
#
def initialize_resources_class_accessors! #:nodoc:
# First priority is the namespaced modek, e.g. User::Group
self.resource_class = begin
# First priority is the namespaced model, e.g. User::Group
self.resource_class ||= begin
namespaced_class = self.name.sub(/Controller/, '').singularize
namespaced_class.constantize
rescue NameError
nil
end

# Second priority the camelcased c, i.e. UserGroup
# Second priority is the top namespace model, e.g. EngineName::Article for EngineName::Admin::ArticlesController
self.resource_class ||= begin
namespaced_classes = self.name.sub(/Controller/, '').split('::')
namespaced_class = [namespaced_classes.first, namespaced_classes.last].join('::').singularize
namespaced_class.constantize
rescue NameError
nil
end

# Third priority the camelcased c, i.e. UserGroup
self.resource_class ||= begin
camelcased_class = self.name.sub(/Controller/, '').gsub('::', '').singularize
camelcased_class.constantize
Expand Down
2 changes: 1 addition & 1 deletion lib/inherited_resources/version.rb
@@ -1,3 +1,3 @@
module InheritedResources
VERSION = '1.2.1'.freeze
VERSION = '1.2.2'.freeze
end
11 changes: 10 additions & 1 deletion test/aliases_test.rb
Expand Up @@ -126,7 +126,16 @@ def test_block_is_called_when_student_is_destroyed

def test_options_are_used_in_respond_with
@request.accept = "application/xml"
Student.stubs(:new).returns(mock_student(:save => true, :to_xml => "XML"))
mock_student = mock_student(:save => true, :to_xml => "XML")
Student.stubs(:new).returns(mock_student)

# Bug in mocha does not accept strings on respond_to
mock_student.singleton_class.class_eval do
def respond_to?(method, *)
method == "to_xml" || super
end
end

post :create
assert_equal "http://test.host/", @response.location
end
Expand Down

0 comments on commit 8226549

Please sign in to comment.