Skip to content

Commit

Permalink
fix options splitting and merging to not lose some kwargs
Browse files Browse the repository at this point in the history
if we passed certain options after passing global override options (ie. passing an image spacing option before passing a repetition option), the first global override option was lost
  • Loading branch information
agrobbin committed Jun 4, 2014
1 parent 4fcea1f commit b0cd90a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/spritely/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ def [](key)
def options
@options ||= stripped_hash.except(*GLOBAL_OPTIONS).inject({}) do |h, (key, value)|
split_key = key.to_s.split('_')
option = global_options.merge(split_key.pop.to_sym => value)
h.deep_merge!(split_key.join('-') => option)
option = {split_key.pop.to_sym => value}
image = split_key.join('-')
h[image] ||= global_options.dup
h.deep_merge!(image => option)
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/spritely/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

describe Spritely::Options do
let(:hash) { {
'some_new_image_spacing' => Sass::Script::Number.new(789),
'some_new_image_x' => Sass::Script::Number.new(123),
'some_new_image_y' => Sass::Script::Number.new(456),
'some_new_image_spacing' => Sass::Script::Number.new(789),
'another_image_repeat' => Sass::Script::Bool.new(true),
'yet_another_image_repeat' => Sass::Script::Bool.new(false),
'spacing' => Sass::Script::Number.new(901)
'spacing' => Sass::Script::Number.new(901),
} }

subject(:options) { Spritely::Options.new(hash) }

its(:inspect) { should eq("#<Spritely::Options global_options=#{{spacing: 901}} options=#{{'some-new-image' => {spacing: 789, x: 123, y: 456}, 'another-image' => {spacing: 901, repeat: true}, 'yet-another-image' => {spacing: 901, repeat: false}}}>") }
its(:cache_key) { should eq({some_new_image_x: 123, some_new_image_y: 456, some_new_image_spacing: 789, another_image_repeat: true, yet_another_image_repeat: false, spacing: 901}.to_s) }
its(:cache_key) { should eq({some_new_image_spacing: 789, some_new_image_x: 123, some_new_image_y: 456, another_image_repeat: true, yet_another_image_repeat: false, spacing: 901}.to_s) }

its(['some-new-image']) { should eq({spacing: 789, x: 123, y: 456}) }
its(['another-image']) { should eq({spacing: 901, repeat: true}) }
Expand Down

0 comments on commit b0cd90a

Please sign in to comment.