matsimitsu-risosu-san 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/risosu_san.rb +3 -1
- data/test/risosu_san_test.rb +9 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/risosu_san.rb
CHANGED
@@ -9,6 +9,8 @@ module RisosuSan
|
|
9
9
|
# class PasswordsController < ActionController::Base
|
10
10
|
# find_parent_resource :only => :new, :field => 'slug'
|
11
11
|
# end
|
12
|
+
#
|
13
|
+
# :field setting is optional, if used and record is not found, there is a fallback to ID
|
12
14
|
def find_parent_resource(options = {})
|
13
15
|
if options[:field] then
|
14
16
|
field = options[:field]
|
@@ -64,7 +66,7 @@ module RisosuSan
|
|
64
66
|
# @member # => #<Member id: 24>
|
65
67
|
def find_parent_resource(field=nil)
|
66
68
|
finder_sender = field ? "find_by_#{field}" : 'find'
|
67
|
-
if @parent_resource.nil? && nested? && @parent_resource = parent_resource_params[:class].send(finder_sender, parent_resource_params[:id])
|
69
|
+
if @parent_resource.nil? && nested? && @parent_resource = parent_resource_params[:class].send(finder_sender, parent_resource_params[:id]) || parent_resource_params[:class].send('find', parent_resource_params[:id])
|
68
70
|
instance_variable_set("@#{parent_resource_params[:name]}", @parent_resource)
|
69
71
|
end
|
70
72
|
@parent_resource
|
data/test/risosu_san_test.rb
CHANGED
@@ -90,15 +90,23 @@ describe "RisosuSan" do
|
|
90
90
|
assigns(:member).should == @member
|
91
91
|
end
|
92
92
|
|
93
|
+
it "should also fallback to id when item could not be found by the correct field" do
|
94
|
+
controller.params = { :member_id => @member.id }
|
95
|
+
controller.find_parent_resource('name').should == @member
|
96
|
+
assigns(:member).should == @member
|
97
|
+
end
|
98
|
+
|
93
99
|
it "should return nil if the resource isn't nested" do
|
94
100
|
controller.params = {}
|
95
101
|
controller.find_parent_resource.should.be nil
|
96
102
|
assigns(:parent_resource).should.be nil
|
97
103
|
end
|
98
104
|
|
105
|
+
|
99
106
|
private
|
100
107
|
|
101
108
|
def assigns(name)
|
102
109
|
controller.instance_variable_get("@#{name}")
|
103
110
|
end
|
104
|
-
end
|
111
|
+
end
|
112
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matsimitsu-risosu-san
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eloy Duran
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-
|
13
|
+
date: 2010-02-10 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|