Skip to content

Commit

Permalink
add default_option_type_name and default_unit
Browse files Browse the repository at this point in the history
  • Loading branch information
sbounmy committed Apr 14, 2013
1 parent 605c2c3 commit 87e32af
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app/models/spree/size_chart.rb
Expand Up @@ -76,6 +76,16 @@ def hash_size_values
def option_type_with_unit
"#{option_type.try(:presentation)} (#{unit})"
end

def default_or_selected_option_type
option_type || Spree::OptionType.where(["lower(name) = ?", default_option_type_name.downcase]).first
end

def default_or_selected_unit
unit || default_unit
end

delegate :default_option_type_name, :default_unit, :to => SpreeSizeChart
end

end
4 changes: 2 additions & 2 deletions app/views/spree/admin/size_charts/edit.html.erb
Expand Up @@ -11,7 +11,7 @@
<%= f.field_container :option_type_id do %>
<%= f.label :option_type_id, t(:option_type_id) %>
<%= f.select :option_type_id, Spree::OptionType.select("id, name").map {|opt| [opt.name, opt.id] }, { :include_blank => true } %>
<%= f.collection_select :option_type_id, Spree::OptionType.all, :id, :name, :selected => @size_chart.default_or_selected_option_type.try(:id) %>
<% end %>
<%= f.field_container :prototype_id do %>
Expand All @@ -21,7 +21,7 @@
<%= f.field_container :unit do %>
<%= f.label :unit %>
<%= f.select :unit, Spree::SizeChart::UNITS, :include_blank => true %>
<%= f.select :unit, Spree::SizeChart::UNITS, :selected => @size_chart.default_or_selected_unit, :include_blank => true %>
<% end %>
<%= f.field_container :size_types do %>
Expand Down
4 changes: 4 additions & 0 deletions lib/spree_size_chart/engine.rb
@@ -1,4 +1,8 @@
module SpreeSizeChart
mattr_accessor :default_option_type_name, :default_unit
@@default_option_type_name = 'size'
@@default_unit = 'cm'

class Engine < Rails::Engine
engine_name 'spree_size_chart'

Expand Down
10 changes: 10 additions & 0 deletions spec/requests/spree_size_chart_spec.rb
Expand Up @@ -140,4 +140,14 @@ def fill_size_chart
end
end

scenario 'default option type name' do
SpreeSizeChart.default_option_type_name = 'color'
@color = FactoryGirl.create(:option_type, :name => "color", :presentation => 'Color')

visit spree.edit_admin_product_path(@product)
click_link "Size Chart"
page.should have_content('Edit')
find_field('size_chart_option_type_id').value.to_i.should == @color.id
SpreeSizeChart.default_option_type_name = 'size'
end
end

0 comments on commit 87e32af

Please sign in to comment.