Skip to content

Commit

Permalink
Namespacing updates
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Boertien <chris.boertien@bz-labs.com>
  • Loading branch information
Cluster444 authored and radar committed Oct 30, 2012
1 parent 8701aa4 commit 6fdcdda
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -25,4 +25,4 @@ end
task :test_app do
ENV['LIB_NAME'] = 'spree_volume_pricing'
Rake::Task['common:test_app'].invoke
end
end
19 changes: 10 additions & 9 deletions app/controllers/spree/admin/variants_controller_decorator.rb
@@ -1,25 +1,26 @@
Spree::Admin::VariantsController.class_eval do
# this loads the variant for the master variant volume price editing
update.before :before_update

respond_override :update => {:html => {
:success => lambda { redirect_to(@variant.is_master ? volume_prices_admin_product_variant_url(@variant.product, @variant) : collection_url) },
:failure => lambda { redirect_to(@variant.is_master ? volume_prices_admin_product_variant_url(@variant.product, @variant) : collection_url) } } }

def load_resource_instance
parent

if new_actions.include?(params[:action].to_sym)
build_resource
elsif params[:id]
Spree::Variant.find(params[:id])
Variant.find(params[:id])
end
end

def volume_prices
@product = @variant.product
@variant.volume_prices.build
end

def location_after_save
if @product.master.id == @variant.id and params[:variant].has_key? :volume_prices_attributes
return volume_prices_admin_product_variant_url(@product, @variant)
end

super
protected
def before_update
params[:variant][:volume_prices_attributes] ||= {}
end
end
25 changes: 6 additions & 19 deletions spec/controllers/spree/admin/variants_controller_spec.rb
Expand Up @@ -7,26 +7,13 @@
user.stub :has_role? => true
end

describe "PUT #update" do
it "creates a volume price" do
variant = Factory :variant
context "#update" do
it "should fire the before filter" do
variant = Factory(:variant)

lambda do
put :update,
:product_id => variant.product.permalink,
:id => variant.id,
:variant => {
"volume_prices_attributes" => {
"1335830259720" => {
"name"=>"5-10",
"range"=>"5..10",
"amount"=>"90",
"position"=>"1",
"_destroy"=>"false"
}
}
}
end.should change(variant.volume_prices, :count).by(1)
controller.should_receive(:before_update)

put :update, {:product_id=>variant.product.permalink, :id => variant.id,:variant => variant.attributes}
end
end
end

0 comments on commit 6fdcdda

Please sign in to comment.