1 require File.dirname(__FILE__) + '/../../spec_helper'
3 describe Admin::CustomersController do
4 fixtures :authorities, :functions, :admin_users
7 session[:admin_user] = admin_users(:admin_user_00011)
8 @customer = customers :customer_management
9 @controller.class.skip_before_filter @controller.class.before_filter
10 @controller.class.skip_after_filter @controller.class.after_filter
13 it "should use Admin::CustomersController" do
14 controller.should be_an_instance_of(Admin::CustomersController)
17 describe "GET 'index'" do
18 it "should be successful" do
20 response.should be_success
24 describe "GET 'search'" do
28 it "should be successful" do
30 response.should be_success
34 get 'search', :condition => {:customer_code => "yamada"}
35 response.should be_success
37 assigns[:customers].should be_any do |record|
38 record.id == @customer.id
43 get 'search', :condition => {:prefecture_id => 13}
44 response.should be_success
46 assigns[:customers].should be_any do |record|
47 record.id == @customer.id
52 get 'search', :condition => {:customer_name_kanji => "山田"}
53 response.should be_success
55 assigns[:customers].should be_any do |record|
56 record.id == @customer.id
61 get 'search', :condition => {:customer_name_kanji => "太郎"}
62 response.should be_success
64 assigns[:customers].should be_any do |record|
65 record.id == @customer.id
70 get 'search', :condition => {:sex_male => 1}
71 response.should be_success
73 assigns[:customers].should be_any do |record|
74 record.id == @customer.id
79 get 'search', :condition => {:birth_month => 8}
80 response.should be_success
82 assigns[:customers].should be_any do |record|
83 record.id == @customer.id
88 get 'search', :condition => {:birthday_from => Date.new(1995,8,20), :birthday_to => Date.new(1995,8,20)}
89 response.should be_success
91 assigns[:customers].should be_any do |record|
92 record.id == @customer.id
97 get 'search', :condition => {:email => "yamada@kbmj.com"}
98 response.should be_success
100 assigns[:customers].should be_any do |record|
101 record.id == @customer.id
103 assigns[:customers][0].full_name.should_not be_nil
107 get 'search', :condition => {:tel_no => "0352992102"}
108 response.should be_success
110 assigns[:customers].should be_any do |record|
111 record.id == @customer.id
116 get 'search', :condition => {:occupation_id => [1]}
117 response.should be_success
119 assigns[:customers].should be_any do |record|
120 record.id == @customer.id
126 describe "GET 'edit'" do
127 it "should be successful" do
129 response.should be_success
130 assigns[:customer].should == Customer.find(1)
134 describe "POST 'confirm'" do
135 it "should be successful" do
136 @customer.zipcode02 = "0123"
137 customer = @customer.attributes
138 post 'confirm', :id => @customer.id, :customer => customer, :order_count => 0
139 response.should render_template("admin/customers/confirm.html.erb")
143 describe "POST 'update'" do
144 it "should be successful" do
145 @customer.zipcode02 = "0123"
146 customer = @customer.attributes
147 post 'update', :id => @customer.id, :customer => customer, :order_count => 0
148 response.should redirect_to(:action => :index)
153 describe "POST 'csv_download'" do
154 it "should be successful" do
155 condition = {:customer_id => @customer.id}
156 post 'csv_download', :condition => condition
157 flash[:notice].should be_nil
158 response.should_not render_template("admin/customers/index.html.erb")
159 response.body.should_not be_nil
163 condition = {:customer_id => 34241234231432}
164 post 'csv_download', :condition => condition
165 response.should render_template("admin/customers/index.html.erb")
169 describe "POST 'csv_upload'" do
170 it "should be successful" do
171 last_customer = Customer.find(:last)
172 csv = uploaded_file(File.dirname(__FILE__) + "/../../customer_upload.csv", "text", "customer_upload.csv")
173 post 'csv_upload', :upload_file => csv
174 Customer.find(:last).should_not == last_customer
178 last_customer = Customer.find(:last)
179 post 'csv_upload', :uploaded_file => ""
180 Customer.find(:last).should == last_customer