OSDN Git Service

fix test
[pettanr/pettanr.git] / spec / controller_helper.rb
1 module ControllerMacros
2   def list_should_return_filer_or_json action, params = {}
3     # html\8c`\8e®: 
4     # \83X\83e\81[\83^\83X\83R\81[\83h200 OK\82ð\95Ô\82·
5     # filer\83e\83\93\83v\83\8c\81[\83g\82ð\95`\89æ\82·\82é
6     get action, params
7     response.should be_success 
8     response.should render_template("templates/r/filer/filer")
9     # json\8c`\8e®
10     # \83X\83e\81[\83^\83X\83R\81[\83h200 OK\82ð\95Ô\82·
11     # json\83f\81[\83^\82ð\95Ô\82·
12     get action, params.merge(:format => :json)
13     response.should be_success 
14     lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
15   end
16   
17   def announce_sign_in_at_get action, params = {}
18     # html\8c`\8e®: \83X\83e\81[\83^\83X\83R\81[\83h302 Found\82ð\95Ô\82·
19     get action, params
20     response.status.should eq 302
21     response.should redirect_to '/users/sign_in'
22     # json\8c`\8e®: \83X\83e\81[\83^\83X\83R\81[\83h401 Unauthorized\82ð\95Ô\82·
23     get action, params.merge(:format => :json)
24     response.status.should eq 401
25     response.message.should match(/Unauthorized/)
26   end
27   
28   def return_ok_at_get action, params = {}
29     # html\8c`\8e®: \83X\83e\81[\83^\83X\83R\81[\83h200 OK\82ð\95Ô\82·
30     get action, params
31     response.should be_success 
32     # json\8c`\8e®: \83X\83e\81[\83^\83X\83R\81[\83h200 OK\82ð\95Ô\82·
33     get action, params.merge(:format => :json)
34     response.should be_success 
35   end
36   
37 end
38