king_placeholder 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -111,7 +111,10 @@ module KingPlaceholder
111
111
  object = obj.send(object_name)
112
112
  # Its a collection => invoice.items and access is done by ary index:
113
113
  # first item => [items.1.name]
114
- if object.is_a?(Array) && ary_index = field_names.first[/\A\d*\z/]
114
+ if object.nil?
115
+ # empty relation
116
+ @result.gsub!(@placeholder, '')
117
+ elsif object.is_a?(Array) && ary_index = field_names.first[/\A\d*\z/]
115
118
  field_names.delete_at(0) # remove entry from field_names ary
116
119
  # replace with empty string if the index does not exist or obj is empty
117
120
  @result.gsub!(@placeholder, '') unless object = object[ary_index.to_i-1]
@@ -1,3 +1,3 @@
1
1
  module KingPlaceholder
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -132,13 +132,13 @@ describe 'Placeholder substitution' do
132
132
 
133
133
  context 'with empty fields' do
134
134
 
135
- it 'should expand valid but empty placeholder group with empty string' do
135
+ it 'should parse valid but empty placeholder group with empty string' do
136
136
  master = Master.new
137
137
  master.details = []
138
138
  master.expand_placeholders('[details][int_field][/details]').should == ''
139
139
  end
140
140
 
141
- it 'should expand single item group with empty string' do
141
+ it 'should parse single item group with empty string' do
142
142
  @master.expand_placeholders('[details.10.int_field]').should == ''
143
143
  end
144
144
 
@@ -146,6 +146,11 @@ describe 'Placeholder substitution' do
146
146
  @master.string_field = nil
147
147
  @detail1.expand_placeholders('[master.string_field]').should == ''
148
148
  end
149
+
150
+ it 'should parse empty related object with empty string' do
151
+ @detail1.master = nil
152
+ @detail1.expand_placeholders('[master.string_field]').should == ''
153
+ end
149
154
  end
150
155
 
151
156
  context 'with collection' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: king_placeholder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -173,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
173
  version: '0'
174
174
  segments:
175
175
  - 0
176
- hash: -1913045486927404314
176
+ hash: -1074118578263294842
177
177
  required_rubygems_version: !ruby/object:Gem::Requirement
178
178
  none: false
179
179
  requirements:
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  version: '0'
183
183
  segments:
184
184
  - 0
185
- hash: -1913045486927404314
185
+ hash: -1074118578263294842
186
186
  requirements: []
187
187
  rubyforge_project:
188
188
  rubygems_version: 1.8.24