1 # -*- coding: utf-8 -*-
2 require File.dirname(__FILE__) + '/../../spec_helper'
4 describe Admin::ShopsController do
5 fixtures :authorities, :functions, :admin_users , :shops, :retailers, :delivery_traders, :delivery_times
8 session[:admin_user] = admin_users(:load_by_admin_user_test_id_1)
9 @controller.class.skip_before_filter @controller.class.before_filter
10 @controller.class.skip_after_filter @controller.class.after_filter
11 @controller.class.before_filter :master_shop_check, :except => [:delivery_index, :delivery_new, :delivery_edit, :delivery_create, :delivery_update, :destroy, :sort]
14 #Delete this example and add some real ones
15 it "should use Admin::ShopsController" do
16 controller.should be_an_instance_of(Admin::ShopsController)
21 describe "GET 'index'" do
22 fixtures :shops,:systems
23 it "should be successful" do
25 response.should be_success
26 assigns[:shop].should == Shop.find(:first)
29 it "マスターショップ以外はアクセスできない" do
30 session[:admin_user] = admin_users(:admin18_retailer_id_is_another_shop)
32 response.should redirect_to(:controller => "home", :action => "index")
36 describe "POST 'update'" do
37 fixtures :shops,:systems
38 it "should be successful" do
39 shop = shops :load_by_shop_test_id_1
40 system = systems :load_by_system_test_id_1
41 #system = {:tax=>100,:tax_rule=>1,:free_delivery_rule=>5000}
42 id = shops(:load_by_shop_test_id_1).id
43 post 'update', :id => id, :shop => shop.attributes,:system=>system.attributes
44 response.should redirect_to(:action => 'index')
45 result = Shop.find(id)
47 # result.name.should == shop.name
48 # result.prefecture_id.should == shop.prefecture_id
49 # result.address_city.should == shop.address_city
50 # result.address_detail.should == shop.address_detail
51 # result.tel.should == shop.tel
52 system_new = System.find(:first)
53 system_new.should == system
58 describe "GET 'get_address'" do
59 fixtures :zips,:shops,:systems
60 it "get_address ok" do
61 get 'get_address', :first => "000", :second => "0000"
62 address = zips(:zip_test_id_1)
63 data = address.prefecture_name + "/" + address.address_city + "/" + address.address_details + "/" + address.prefecture_id.to_s
64 response.should be_success
65 response.body.should == data
70 describe "GET 'delivery_list'" do
71 fixtures :delivery_traders,:delivery_times,:delivery_fees
72 it "should be successful" do
74 response.should be_success
75 assigns[:delivery_traders].should == DeliveryTrader.find(:all, :conditions => ["retailer_id = ?", session[:admin_user].retailer_id], :order=>"position")
78 it "他店舗では他店舗用の配送業者のみ表示" do
79 session[:admin_user] = admin_users(:admin18_retailer_id_is_another_shop)
81 response.should be_success
82 assigns[:delivery_traders].should == DeliveryTrader.find(:all, :conditions => ["retailer_id = ?", session[:admin_user].retailer_id], :order=>"position")
87 describe "GET 'sort'" do
88 fixtures :delivery_traders,:delivery_times,:delivery_fees
90 it "positionを上げる場合" do
91 DeliveryTrader.find(2).position.should == 2
92 get 'up', :model => "delivery_traders", :id => 2, :return_act=>"delivery_list"
93 DeliveryTrader.find(2).position.should == 1
94 response.should redirect_to(:action => "delivery_list")
95 DeliveryTrader.find(3).position.should == 1
98 it "positionを上げる場合(これ以上あがらない)" do
99 DeliveryTrader.find(1).position.should == 1
100 get 'up', :model => "delivery_traders", :id => 1, :return_act=>"delivery_list"
101 DeliveryTrader.find(1).position.should == 1
102 response.should redirect_to(:action => "delivery_list")
106 it "positionを下げる場合" do
107 DeliveryTrader.find(1).position.should == 1
108 get 'down', :model => "delivery_traders", :id => 1, :return_act=>"delivery_list"
109 DeliveryTrader.find(1).position.should == 2
110 response.should redirect_to(:action => "delivery_list")
111 DeliveryTrader.find(3).position.should == 1
114 it "positionを下げる場合(これ以上下がらない)" do
115 DeliveryTrader.find(2).position.should == 2
116 get 'down', :model => "delivery_traders", :id => 2, :return_act=>"delivery_list"
117 DeliveryTrader.find(2).position.should == 2
118 response.should redirect_to(:action => "delivery_list")
123 describe "GET 'destroy'" do
125 get 'destroy', :model => "delivery_traders", :id => 1,:return_act=>"delivery_list"
126 DeliveryTrader.find(:first, :order=>"id").id.should == 2
127 response.should redirect_to(:action => "delivery_list")
130 get 'destroy', :model => "delivery_traders", :id => 100 ,:return_act=>"delivery_list"
134 describe "GET 'delivery_new'" do
135 it "should be successful" do
137 response.should be_success
142 response.should be_success
144 assigns[:delivery_trader].should_not be_nil
145 assigns[:delivery_time].should_not be_nil
146 assigns[:delivery_fee].should_not be_nil
150 describe "GET 'delivery_edit'" do
151 fixtures :delivery_traders,:delivery_times,:delivery_fees
153 @delivery_trader = delivery_traders :witch
154 @delivery_time = @delivery_trader.delivery_times
155 @delivery_fee = @delivery_trader.delivery_fees
158 get 'delivery_edit', :id=>@delivery_trader.id
159 response.should be_success
160 assigns[:delivery_trader].should == @delivery_trader
161 DeliveryTime::MAX_SIZE.times do |index|
162 assigns[:delivery_time][index].should == @delivery_time[index]
164 DeliveryFee::MAX_SIZE.times do |index|
165 assigns[:delivery_fee][index].should == @delivery_fee[index]
170 describe "GET 'delivery_create'" do
171 fixtures :delivery_traders,:delivery_times,:delivery_fees
173 @delivery_trader = {:name=>"追加",:url=>"http://www.hoge.com", :retailer_id => Retailer::DEFAULT_ID}
175 DeliveryTime::MAX_SIZE.times do |i|
176 @delivery_time["#{i}"]={:name=>"午前中なら#{i}"}
179 DeliveryFee::MAX_SIZE.times do |i|
180 @delivery_fee["#{i}"]={:price=>"#{i}"}
182 @delivery_fee["47"][:prefecture_id]=nil
185 get 'delivery_create', :delivery_trader=>@delivery_trader,:delivery_time=>@delivery_time,:delivery_fee=>@delivery_fee
186 response.should redirect_to(:action=>:delivery_index)
189 it "新規作成(保存して戻る失敗)" do
190 @delivery_trader[:name] = "a" * 51
191 get 'delivery_create', :delivery_trader=>@delivery_trader,:delivery_time=>@delivery_time,:delivery_fee=>@delivery_fee
192 response.should render_template("admin/shops/delivery_new.html.erb")
196 trader_count = DeliveryTrader.count
197 time_count = DeliveryTime.count
198 fee_count = DeliveryFee.count
199 get 'delivery_create', :delivery_trader=>@delivery_trader,:delivery_time=>@delivery_time,:delivery_fee=>@delivery_fee
200 response.should redirect_to(:action => :delivery_index)
201 DeliveryTrader.count.should == trader_count+1
202 DeliveryTime.count.should == time_count+DeliveryTime::MAX_SIZE
203 DeliveryFee.count.should == fee_count+DeliveryFee::MAX_SIZE
204 DeliveryTrader.find(:first,:order=>"id desc",:limit=>1).delivery_times.size.should == DeliveryTime::MAX_SIZE
205 DeliveryTrader.find(:first,:order=>"id desc",:limit=>1).delivery_fees.size.should == DeliveryFee::MAX_SIZE
206 DeliveryTrader.find(:first,:order=>"id desc",:limit=>1).delivery_fees[47].prefecture_id == nil
209 it "retailer_idが無効なものは登録できない" do
210 delivery_trader = {:name=>"追加",:url=>"http://www.hoge.com", :retailer_id => nil}
211 trader_count = DeliveryTrader.count
212 time_count = DeliveryTime.count
213 fee_count = DeliveryFee.count
214 get 'delivery_create', :delivery_trader=>delivery_trader,:delivery_time=>@delivery_time,:delivery_fee=>@delivery_fee
215 response.should render_template("admin/shops/delivery_new.html.erb")
218 it "存在しないretailer_idは登録できない" do
219 retailer_max = Retailer.find(:last).id + 100
220 delivery_trader = @delivery_trader.merge({:name => "fail_trader", :retailer_id => retailer_max})
221 get 'delivery_create', :delivery_trader=>delivery_trader,:delivery_time=>@delivery_time,:delivery_fee=>@delivery_fee
222 response.should render_template("admin/shops/delivery_new.html.erb")
225 it "同じ名前でもretailer_idが異なれば登録できる" do
226 other_shop = delivery_traders(:other_shop)
227 delivery_trader = @delivery_trader.merge({:name => other_shop.name })
228 get 'delivery_create', :delivery_trader=>delivery_trader,:delivery_time=>@delivery_time,:delivery_fee=>@delivery_fee
229 response.should redirect_to(:action=>:delivery_index)
234 describe "GET 'delivery_update'" do
235 fixtures :delivery_traders
237 @delivery_trader = delivery_traders :witch
239 @delivery_trader.url="http://hogehoge.com"
241 DeliveryTime::MAX_SIZE.times do |i|
242 @delivery_time["#{i}"]={:id=>"#{i}",:name=>"午前中なら#{i}",:position=>"#{i+1}",:delivery_trader_id=>"1"}
245 DeliveryFee::MAX_SIZE.times do |i|
246 @delivery_fee["#{i}"]={:id=>"#{i}",:price=>"#{i}",:prefecture_id=>"#{i+1}",:delivery_trader_id=>"1"}
248 @delivery_fee["47"][:prefecture_id]=nil
252 get 'delivery_update', :delivery_trader=>@delivery_trader.attributes,:delivery_time=>@delivery_time,:delivery_fee=>@delivery_fee, :id=>@delivery_trader.id
253 response.should redirect_to(:action => :delivery_index, :id => @delivery_trader.id)
257 @delivery_trader[:name] = "a" * 51
258 get 'delivery_update', :delivery_trader=>@delivery_trader.attributes,:delivery_time=>@delivery_time,:delivery_fee=>@delivery_fee, :id=>@delivery_trader.id
259 response.should render_template("admin/shops/delivery_edit.html.erb")
263 get 'delivery_update', :delivery_trader=>@delivery_trader.attributes,:delivery_time=>@delivery_time,:delivery_fee=>@delivery_fee, :id=>@delivery_trader.id
264 response.should redirect_to(:action => :delivery_index, :id => @delivery_trader.id)
265 delivery_trader = DeliveryTrader.find(@delivery_trader.id)
266 delivery_trader.should == @delivery_trader
268 DeliveryTime::MAX_SIZE.times do |i|
269 delivery_trader.delivery_times[i].name.should == @delivery_time["#{i}"][:name]
271 DeliveryFee::MAX_SIZE.times do |i|
272 delivery_trader.delivery_fees[i].price. == @delivery_fee["#{i}"][:price]
274 delivery_trader.delivery_fees[47].prefecture_id == nil
279 describe "GET 'payment_index'" do
281 it "should be successful" do
283 response.should be_success
284 assigns[:payments].should == Payment.find(:all,:order=>"position")
288 describe "GET 'sort'" do
291 it "positionを上げる場合" do
292 Payment.find(2).position.should == 2
293 get 'up', :model => "payments", :id => 2, :return_act => "payment_list"
294 Payment.find(2).position.should == 1
295 response.should redirect_to(:action => "payment_list")
298 it "positionを上げる場合(これ以上あがらない)" do
299 Payment.find(1).position.should == 1
300 get 'up', :model => "payments", :id => 1, :return_act => "payment_list"
301 Payment.find(1).position.should == 1
302 response.should redirect_to(:action => "payment_list")
306 it "positionを下げる場合" do
307 Payment.find(1).position.should == 1
308 get 'down', :model => "payments", :id => 1, :return_act => "payment_list"
309 Payment.find(1).position.should == 2
310 response.should redirect_to(:action => "payment_list")
313 it "positionを下げる場合(これ以上下がらない)" do
314 old_position= Payment.find(:first,:order=>"position desc")
315 get 'down', :model => "payments", :id => old_position.id, :return_act => "payment_list"
316 Payment.find(:first,:order=>"position desc").position.should == old_position.position
317 response.should redirect_to(:action => "payment_list")
322 describe "GET 'destroy'" do
324 Payment.find_by_id(1).should_not be_nil
325 get 'destroy', :model => "payments", :id => 1, :return_act=>"payment_list"
326 Payment.find_by_id(1).should be_nil
327 Payment.find_by_id(2).should_not be_nil
328 response.should redirect_to(:action => "payment_list")
332 get 'destroy', :model => "payments", :id => 100 ,:return_act=>"payment_list"
336 describe "GET 'payment_new'" do
337 it "should be successful" do
339 response.should be_success
340 assigns[:shop] == Payment.new
344 describe "GET 'payment_create'" do
346 @record = {:name => "追加", :fee => 1}
350 get 'payment_create', :payment => @record
351 response.should redirect_to(:action=>:payment_index)
354 it "新規作成(保存して戻る失敗)" do
356 get 'payment_create', :payment => @record
357 response.should render_template("admin/shops/payment_new.html.erb")
361 payment_count = Payment.count
362 get 'payment_create', :payment => @record
363 response.should redirect_to(:action => :payment_index)
364 Payment.count.should == payment_count+1
368 describe "GET 'payment_edit'" do
371 @payment = payments :cash
374 get 'payment_edit', :id=>@payment.id
375 response.should be_success
376 assigns[:shop] == @payment
380 describe "GET 'payment_update'" do
383 @record = payments :cash
384 @record.lower_limit=0
385 @record.upper_limit=1
389 get 'payment_update', :payment => @record.attributes, :id => @record.id
390 response.should redirect_to(:action => :payment_index)
395 get 'payment_update', :payment => @record.attributes, :id => @record.id
396 response.should render_template("admin/shops/payment_edit.html.erb")
401 get 'payment_update', :record => @record.attributes, :id => @record.id
402 response.should redirect_to(:action => :payment_index)
403 payment = Payment.find(@record.id)
404 payment.should == @record
410 describe "GET 'tradelaw_index'" do
412 it "should be successful" do
414 response.should be_success
415 assigns[:law].should == Law.find(:first)
419 describe "POST 'tradelaw_update'" do
422 @record = laws :shoutorihiki
423 @record.company="販売店更新"
424 @record.manager="運営責任者更新"
425 @record.zipcode01="012"
426 @record.zipcode02="3456"
427 @record.address_city="市区町村更新"
428 @record.address_detail="番地、建物、マンション名更新"
430 @record.tel02 ="0000"
431 @record.tel03 ="1111"
433 @record.fax02 ="1111"
434 @record.fax03 ="2222"
435 @record.email="mail@kbmj.com"
436 @record.url="http://www.kbmj.com/index"
437 @record.prefecture_id ="2"
438 @record.necessary_charge="商品代金以外の必要料金更新"
439 @record.order_method="注文方法更新"
440 @record.payment_method="支払方法更新"
441 @record.payment_time_limit="支払期限更新"
442 @record.delivery_time="引き渡し時期更新"
443 @record.return_exchange="返品・交換について更新"
445 it "should be successful" do
447 post 'tradelaw_update', :shop=>@record.attributes,:id=>@record.id
448 response.should redirect_to(:action => 'tradelaw_index')
449 law = Law.find(@record.id)
450 law.should == @record
456 describe "GET 'mail_index'" do
457 it "should be successful" do
459 response.should be_success
460 assigns[:shop] == MailTemplate.new
464 describe "POST 'mail_update'" do
465 fixtures :mail_templates
467 @record = mail_templates :template1
468 @record.title="タイトル更新"
469 @record.header="ヘッダー更新"
470 @record.footer="フッター更新"
472 it "should be successful" do
473 post 'mail_update', :mail => @record.attributes
474 response.should redirect_to(:action => 'mail_index')
475 mail_template = MailTemplate.find(@record.id)
476 mail_template.should == @record
480 describe "POST 'mail_search'" do
481 fixtures :mail_templates
483 @record = mail_templates :template1
487 post 'mail_search', :id => @record.id
488 assigns[:mail].should == @record
489 response.should render_template("admin/shops/_mail_form")
494 assigns[:mail].id.should be_nil
495 response.should render_template("admin/shops/_mail_form")
500 describe "GET 'seo_index'" do
501 it "should be successful" do
503 response.should be_success
504 assigns[:shop] == Seo.find(:all,:order=>"page_type")
508 describe "POST 'seo_update'" do
512 @record.name=Seo::TYPE_NAMES[@record.page_type]
513 @record.author="author更新"
514 @record.description="description更新"
515 @record.keywords="keywords更新"
517 it "should be successful" do
519 post 'seo_update', :seo=>@record.attributes
520 response.should redirect_to(:action => 'seo_index')
521 seo = Seo.find_by_page_type(@record.page_type)
522 seo.should == @record
528 describe "GET 'kiyaku_index'" do
529 it "should be successful" do
531 response.should be_success
532 assigns[:shops] == Kiyaku.find(:all)
533 assigns[:kiyaku] == Kiyaku.new
537 describe "GET 'kiyaku_index' 編集" do
540 @kiyaku = kiyakus :kiyaku1
543 get 'kiyaku_index', :id=>@kiyaku.id
544 response.should be_success
545 assigns[:shops] == Kiyaku.find(:all)
546 assigns[:kiyaku] == @kiyaku
549 describe "GET 'sort'" do
551 it "positionを上げる場合" do
552 Kiyaku.find(2).position.should == 2
553 get 'up', :model => "kiyakus", :id => 2, :return_act => "kiyaku_index"
554 Kiyaku.find(2).position.should == 1
555 response.should redirect_to(:action => "kiyaku_index")
558 it "positionを上げる場合(これ以上あがらない)" do
559 Kiyaku.find(1).position.should == 1
560 get 'up', :model => "kiyakus", :id => 1, :return_act => "kiyaku_index"
561 Kiyaku.find(1).position.should == 1
562 response.should redirect_to(:action => "kiyaku_index")
566 it "positionを下げる場合" do
567 Kiyaku.find(1).position.should == 1
568 get 'down', :model => "kiyakus", :id => 1, :return_act => "kiyaku_index"
569 Kiyaku.find(1).position.should == 2
570 response.should redirect_to(:action => "kiyaku_index")
573 it "positionを下げる場合(これ以上下がらない)" do
574 Kiyaku.find(3).position.should == 3
575 get 'down', :model => "kiyakus", :id => 3, :return_act => "kiyaku_index"
576 Kiyaku.find(3).position.should == 3
577 response.should redirect_to(:action => "kiyaku_index")
582 describe "GET 'destroy'" do
584 get 'destroy', :model => "kiyakus", :id => 1,:return_act=>"kiyaku_index"
585 Kiyaku.find(:first).id.should == 2
586 response.should redirect_to(:action => "kiyaku_index")
589 get 'destroy', :model => "kiyakus", :id => 100 ,:return_act=>"kiyaku_index"
593 describe "POST 'kiyaku_create'" do
595 @record = {:name=>"追加",:content=>"追加追加"}
599 get 'kiyaku_create', :kiyaku => @record
600 response.should redirect_to(:action => :kiyaku_index)
603 it "新規作成(保存して戻る失敗)" do
605 get 'kiyaku_create', :kiyaku => @record
606 response.should render_template("admin/shops/kiyaku_index.html.erb")
610 kiyaku_count = Kiyaku.count
611 get 'kiyaku_create', :kiyaku => @record
612 response.should redirect_to(:action=>:kiyaku_index)
613 Kiyaku.count.should == kiyaku_count+1
616 describe "POST 'kiyaku_update'" do
619 @record = kiyakus :kiyaku1
620 @record.name="タイトル更新"
621 @record.content="内容更新"
624 it "should be successful" do
625 post 'kiyaku_update', :kiyaku => @record.attributes
626 response.should redirect_to(:action => 'kiyaku_index')
627 kiyaku = Kiyaku.find(@record.id)
628 kiyaku.should == @record
632 describe "GET 'point_index'" do
633 it "should be successful" do
635 response.should be_success
636 assigns[:shop].should == Shop.find(:first)
640 describe "POST 'point_update'" do
642 @shop = {:point_granted_rate => "", :point_at_admission => ""}
643 @id = Shop.find(:first).id
647 post 'point_update', :id => @id, :shop => @shop
648 response.should redirect_to(:action => :point_index)
653 response.should render_template("admin/shops/point_index.html.erb")
657 @shop[:point_granted_rate] = "test"
658 post 'point_update', :id => @id, :shop => @shop
659 response.should render_template("admin/shops/point_index.html.erb")
663 describe "GET 'privacy'" do
665 it "should be successful" do
666 privacy = privacies :one
668 assigns[:privacy].attributes.should == privacy.attributes
672 describe "POST 'privacy_update'" do
674 @privacy = {:content_collect=>"テスト1",:content_collect_mobile=>"テスト2",:content_privacy=>"テスト3",:content_privacy_mobile=>"テスト4"}
678 post 'privacy_update', :privacy => @privacy
679 response.should redirect_to(:action => :privacy)
682 it "POSTではなくGETでアクセス" do
683 get 'privacy_update', :privacy => @privacy
684 flash[:notice].should be_nil
685 response.should redirect_to(:action => :privacy)