OSDN Git Service

メールマガジン処理をcronで動かせるように修正
[elecoma/elecoma.git] / spec / controllers / admin / customers_controller_spec.rb
1 require File.dirname(__FILE__) + '/../../spec_helper'
2
3 describe Admin::CustomersController do
4   fixtures :authorities, :functions, :admin_users
5   fixtures :customers
6   before(:each) do
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
11   end
12
13   it "should use Admin::CustomersController" do
14     controller.should be_an_instance_of(Admin::CustomersController)
15   end
16   
17   describe "GET 'index'" do
18     it "should be successful" do
19       get 'index'
20       response.should be_success
21     end
22   end
23   
24   describe "GET 'search'" do
25     before do
26     end
27     
28     it "should be successful" do
29       get 'search'
30       response.should be_success
31     end
32     
33     it "顧客コード" do
34       get 'search', :condition => {:customer_code => "yamada"}
35       response.should be_success
36       # 結果の中に含まれているか見る
37       assigns[:customers].should be_any do |record|
38         record.id == @customer.id
39       end
40     end
41     
42     it "都道府県" do
43       get 'search', :condition => {:prefecture_id => 13}
44       response.should be_success
45       # 結果の中に含まれているか見る
46       assigns[:customers].should be_any do |record|
47         record.id == @customer.id
48       end
49     end
50     
51     it "顧客名(姓)" do
52       get 'search', :condition => {:customer_name_kanji => "山田"}
53       response.should be_success
54       # 結果の中に含まれているか見る
55       assigns[:customers].should be_any do |record|
56         record.id == @customer.id
57       end
58     end
59     
60     it "顧客名(名)" do
61       get 'search', :condition => {:customer_name_kanji => "太郎"}
62       response.should be_success
63       # 結果の中に含まれているか見る
64       assigns[:customers].should be_any do |record|
65         record.id == @customer.id
66       end
67     end
68
69     it "性別" do
70       get 'search', :condition => {:sex_male => 1}
71       response.should be_success
72       # 結果の中に含まれているか見る
73       assigns[:customers].should be_any do |record|
74         record.id == @customer.id
75       end
76     end
77
78     it "誕生月" do
79       get 'search', :condition => {:birth_month => 8}
80       response.should be_success
81       # 結果の中に含まれているか見る
82       assigns[:customers].should be_any do |record|
83         record.id == @customer.id
84       end
85     end
86
87     it "誕生日" do
88       get 'search', :condition => {:birthday_from => Date.new(1995,8,20), :birthday_to => Date.new(1995,8,20)}
89       response.should be_success
90       # 結果の中に含まれているか見る
91       assigns[:customers].should be_any do |record|
92         record.id == @customer.id
93       end
94     end
95
96     it "メールアドレス" do
97       get 'search', :condition => {:email => "yamada@kbmj.com"}
98       response.should be_success
99       # 結果の中に含まれているか見る
100       assigns[:customers].should be_any do |record|
101         record.id == @customer.id
102       end
103       assigns[:customers][0].full_name.should_not be_nil
104     end
105
106     it "電話番号" do
107       get 'search', :condition => {:tel_no => "0352992102"}
108       response.should be_success
109       # 結果の中に含まれているか見る
110       assigns[:customers].should be_any do |record|
111         record.id == @customer.id
112       end
113     end
114
115     it "職業" do
116       get 'search', :condition => {:occupation_id => [1]}
117       response.should be_success
118       # 結果の中に含まれているか見る
119       assigns[:customers].should be_any do |record|
120         record.id == @customer.id
121       end
122     end
123
124   end
125   
126   describe "GET 'edit'" do
127     it "should be successful" do
128       get 'edit', {:id=>1}
129       response.should be_success
130       assigns[:customer].should == Customer.find(1)
131     end
132   end
133  
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")
140     end
141   end
142
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)
149     end
150   end
151
152
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
160     end
161
162     it "件数なしのパターン" do
163       condition = {:customer_id => 34241234231432}
164       post 'csv_download', :condition => condition
165       response.should render_template("admin/customers/index.html.erb")
166     end
167   end
168
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
175     end
176
177     it "ファイルを与えてない場合" do
178       last_customer = Customer.find(:last)
179       post 'csv_upload', :uploaded_file => ""
180       Customer.find(:last).should == last_customer
181     end
182   end
183
184 end
185
186
187