OSDN Git Service

10ba3b16d6ec76f783db10281f5d676d238c72c4
[elecoma/elecoma.git] / spec / controllers / inquiries_controller_spec.rb
1 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
3 describe InquiriesController do
4   fixtures :inquiries
5
6
7   before do
8     @controller.class.skip_before_filter :start_transaction
9     @controller.class.skip_after_filter :end_transaction
10   end
11
12   #Delete this example and add some real ones
13   it "should use InquiriesController" do
14     controller.should be_an_instance_of(InquiriesController)
15   end
16   
17   describe "GET 'new'" do
18     it "should be successful" do
19       get 'new'
20       assigns[:inquiry].kind.should == Inquiry::GOODS
21       response.should be_success
22     end
23
24     it "should be successful(mobileでdocomoの場合)" do
25       request.user_agent = "DoCoMo/2.0 SH903i(c100;TB;W24H16)"
26       get 'new'
27       assigns[:inquiry].email.should == "@docomo.ne.jp"
28       response.should be_success
29     end
30
31     it "should be successful(mobileでauの場合)" do
32       request.user_agent = "KDDI-SH36 UP.Browser/6.2.0.5"
33       get 'new'
34       assigns[:inquiry].email.should == "@ezweb.ne.jp"
35       assigns[:inquiry].kind.should == Inquiry::GOODS
36       response.should be_success
37     end
38
39     it "should be successful(mobileでsoftbankの場合)" do
40       request.user_agent = "SoftBank/1.0/910T/TJ001/SN123456789012345 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
41       get 'new'
42       assigns[:inquiry].email.should be_nil
43       response.should be_success
44     end
45
46   end
47
48   describe "GET 'confirm'" do
49     it "should be successful" do
50       inquiry = inquiries(:inquiry_test_id_1)
51       get 'confirm', :inquiry => inquiry.attributes
52       response.should be_success
53     end
54
55     it "should be successful(mobileのsoftbankの場合)" do
56       inquiry = inquiries(:inquiry_test_id_1).attributes
57       inquiry["email"] = "test@softbank.ne.jp"
58       request.user_agent = "SoftBank/1.0/910T/TJ001/SN123456789012345 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
59       get 'confirm', :inquiry => inquiry
60       assigns[:inquiry].email.should == "test@softbank.ne.jp"
61       response.should be_success
62     end
63   end
64
65   it "newに戻る場合(validateに引っかかる)" do
66     inquiry = inquiries(:inquiry_test_id_1)
67     inquiry.name = ""
68     get 'confirm', :inquiry => inquiry.attributes
69     response.should render_template("inquiries/new.html.erb")
70   end
71
72   describe "GET 'complete'" do
73     it "should be successful" do
74     inquiry = inquiries(:inquiry_test_id_1)
75       get 'complete', :inquiry => inquiry.attributes
76       response.should be_success
77     end
78   end
79
80   it "newに戻る場合(validateに引っかかる)" do
81     inquiry = inquiries(:inquiry_test_id_1)
82     inquiry.name = ""
83     get 'complete', :inquiry => inquiry.attributes
84     response.should render_template("inquiries/new.html.erb")
85   end
86
87   it "newに戻る場合(validateに引っかかる)(mobile)" do
88     inquiry = inquiries(:inquiry_test_id_1)
89     inquiry.name = ""
90     get 'complete', :inquiry => inquiry.attributes
91     response.should render_template("inquiries/new.html.erb")
92   end
93
94   it "お問い合わせが完了する場合" do
95     Notifier.stub!(:deliver_pc_inquiry).and_return(nil)
96     Notifier.stub!(:deliver_received_inquiry).and_return(nil)
97     old_date_num = Inquiry.count
98     inquiry = inquiries(:inquiry_test_id_1)
99     get 'complete', :inquiry => inquiry.attributes
100     Inquiry.count.should == old_date_num + 1
101   end
102
103   it "お問い合わせが完了する場合(mobile)" do
104     request.user_agent = "DoCoMo/2.0 SH903i(c100;TB;W24H16)"
105     Notifier.stub!(:deliver_mobile_inquiry).and_return(nil)
106     Notifier.stub!(:deliver_received_inquiry).and_return(nil)
107     old_date_num = Inquiry.count
108     inquiry = inquiries(:inquiry_test_id_1)
109     get 'complete', :inquiry => inquiry.attributes
110     Inquiry.count.should == old_date_num + 1
111   end
112
113   describe "GET 'show'" do
114
115     it "携帯からはshowページが表示" do
116       request.user_agent = "DoCoMo/2.0 SH903i(c100;TB;W24H16)"
117       get 'show'
118       response.should be_success
119       response.should render_template("inquiries/show_mobile.html.erb")
120       assigns[:shop].should_not be_nil
121     end
122   
123     it "PCからはnewページが表示" do
124       get 'show'
125       response.should be_success
126       response.should render_template("inquiries/show.html.erb")
127       assigns[:shop].should_not be_nil
128     end
129   end
130 end