diff options
Diffstat (limited to 'spec/controllers')
17 files changed, 886 insertions, 307 deletions
diff --git a/spec/controllers/admin_censor_rule_controller_spec.rb b/spec/controllers/admin_censor_rule_controller_spec.rb index 4df56a92b..68eaecd6a 100644 --- a/spec/controllers/admin_censor_rule_controller_spec.rb +++ b/spec/controllers/admin_censor_rule_controller_spec.rb @@ -5,76 +5,68 @@ describe AdminCensorRuleController do describe 'GET new' do - it 'returns a successful response' do - get :new - expect(response).to be_success - end + context 'request_id param' do - it 'initializes a new censor rule' do - get :new - expect(assigns[:censor_rule]).to be_new_record - end + before do + @info_request = FactoryGirl.create(:info_request) + get :new, :request_id => @info_request.id, :name_prefix => 'request_' + end - it 'renders the correct template' do - get :new - expect(response).to render_template('new') - end + it 'returns a successful response' do + expect(response).to be_success + end - it 'sets the URL for the form to POST to' do - get :new - expect(assigns[:form_url]).to eq(admin_rule_create_path) - end + it 'initializes a new censor rule' do + expect(assigns[:censor_rule]).to be_new_record + end - context 'info_request_id param' do + it 'renders the correct template' do + expect(response).to render_template('new') + end - it 'finds an info request if the info_request_id param is supplied' do - info_request = FactoryGirl.create(:info_request) - get :new, :info_request_id => info_request.id - expect(assigns[:info_request]).to eq(info_request) + it 'finds an info request if the request_id param is supplied' do + expect(assigns[:info_request]).to eq(@info_request) end it 'associates the info request with the new censor rule' do - info_request = FactoryGirl.create(:info_request) - get :new, :info_request_id => info_request.id - expect(assigns[:censor_rule].info_request).to eq(info_request) + expect(assigns[:censor_rule].info_request).to eq(@info_request) end it 'sets the URL for the form to POST to' do - info_request = FactoryGirl.create(:info_request) - get :new, :info_request_id => info_request.id - expect(assigns[:form_url]).to eq(admin_info_request_censor_rules_path(info_request)) - end - - it 'does not find an info request if no info_request_id param is supplied' do - get :new - expect(assigns[:info_request]).to be_nil + expect(assigns[:form_url]).to eq(admin_request_censor_rules_path(@info_request)) end end context 'user_id param' do + before do + @user = FactoryGirl.create(:user) + get :new, :user_id => @user.id, :name_prefix => 'user_' + end + + it 'returns a successful response' do + expect(response).to be_success + end + + it 'initializes a new censor rule' do + expect(assigns[:censor_rule]).to be_new_record + end + + it 'renders the correct template' do + expect(response).to render_template('new') + end + it 'finds a user if the user_id param is supplied' do - user = FactoryGirl.create(:user) - get :new, :user_id => user.id - expect(assigns[:censor_user]).to eq(user) + expect(assigns[:censor_user]).to eq(@user) end it 'associates the user with the new censor rule' do - user = FactoryGirl.create(:user) - get :new, :user_id => user.id - expect(assigns[:censor_rule].user).to eq(user) + expect(assigns[:censor_rule].user).to eq(@user) end it 'sets the URL for the form to POST to' do - user = FactoryGirl.create(:user) - get :new, :user_id => user.id - expect(assigns[:form_url]).to eq(admin_user_censor_rules_path(user)) - end - - it 'does not find a user if no user_id param is supplied' do - get :new - expect(assigns[:censor_user]).to be_nil + expect(assigns[:form_url]).to eq(admin_user_censor_rules_path(@user)) end end @@ -83,256 +75,292 @@ describe AdminCensorRuleController do describe 'POST create' do - before(:each) do - @censor_rule_params = FactoryGirl.build(:global_censor_rule).serializable_hash - # last_edit_editor gets set in the controller - @censor_rule_params.delete(:last_edit_editor) - end - - it 'sets the last_edit_editor to the current admin' do - post :create, :censor_rule => @censor_rule_params - expect(assigns[:censor_rule].last_edit_editor).to eq('*unknown*') - end + context 'request_id param' do - it 'sets the URL for the form to POST to' do - post :create, :censor_rule => @censor_rule_params - expect(assigns[:form_url]).to eq(admin_rule_create_path) - end + before(:each) do + @censor_rule_params = FactoryGirl.build(:info_request_censor_rule).serializable_hash + # last_edit_editor gets set in the controller + @censor_rule_params.delete(:last_edit_editor) + @info_request = FactoryGirl.create(:info_request) + post :create, :request_id => @info_request.id, + :censor_rule => @censor_rule_params, + :name_prefix => 'request_' + end - context 'info_request_id param' do + it 'sets the last_edit_editor to the current admin' do + expect(assigns[:censor_rule].last_edit_editor).to eq('*unknown*') + end - it 'finds an info request if the info_request_id param is supplied' do - info_request = FactoryGirl.create(:info_request) - post :create, :info_request_id => info_request.id, - :censor_rule => @censor_rule_params - expect(assigns[:info_request]).to eq(info_request) + it 'finds an info request if the request_id param is supplied' do + expect(assigns[:info_request]).to eq(@info_request) end it 'associates the info request with the new censor rule' do - info_request = FactoryGirl.create(:info_request) - post :create, :info_request_id => info_request.id, - :censor_rule => @censor_rule_params - expect(assigns[:censor_rule].info_request).to eq(info_request) + expect(assigns[:censor_rule].info_request).to eq(@info_request) end it 'sets the URL for the form to POST to' do - info_request = FactoryGirl.create(:info_request) - post :create, :info_request_id => info_request.id, - :censor_rule => @censor_rule_params - expect(assigns[:form_url]).to eq(admin_info_request_censor_rules_path(info_request)) + expect(assigns[:form_url]).to eq(admin_request_censor_rules_path(@info_request)) end - it 'does not find an info request if no info_request_id param is supplied' do - post :create, :censor_rule => @censor_rule_params - expect(assigns[:info_request]).to be_nil - end + context 'successfully saving the censor rule' do - end + it 'persists the censor rule' do + post :create, :censor_rule => @censor_rule_params, + :request_id => @info_request.id, + :name_prefix => 'request_' + expect(assigns[:censor_rule]).to be_persisted + end - context 'user_id param' do + it 'confirms the censor rule is created' do + post :create, :censor_rule => @censor_rule_params, + :request_id => @info_request.id, + :name_prefix => 'request_' + msg = 'CensorRule was successfully created.' + expect(flash[:notice]).to eq(msg) + end - it 'finds a user if the user_id param is supplied' do - user = FactoryGirl.create(:user) - post :create, :user_id => user.id, - :censor_rule => @censor_rule_params - expect(assigns[:censor_user]).to eq(user) - end + it 'purges the cache for the info request' do + @controller.should_receive(:expire_for_request). + with(@info_request) - it 'associates the user with the new censor rule' do - user = FactoryGirl.create(:user) - post :create, :user_id => user.id, - :censor_rule => @censor_rule_params - expect(assigns[:censor_rule].user).to eq(user) - end + post :create, :censor_rule => @censor_rule_params, + :request_id => @info_request.id, + :name_prefix => 'request_' + end - it 'sets the URL for the form to POST to' do - user = FactoryGirl.create(:user) - post :create, :user_id => user.id, - :censor_rule => @censor_rule_params - expect(assigns[:form_url]).to eq(admin_user_censor_rules_path(user)) + it 'redirects to the associated info request' do + post :create, :censor_rule => @censor_rule_params, + :request_id => @info_request.id, + :name_prefix => 'request_' + expect(response).to redirect_to( + admin_request_path(assigns[:censor_rule].info_request) + ) + end end - it 'does not find a user if no user_id param is supplied' do - post :create, :censor_rule => @censor_rule_params - expect(assigns[:censor_user]).to be_nil - end + context 'unsuccessfully saving the censor rule' do + + before(:each) do + CensorRule.any_instance.stub(:save).and_return(false) + end + + it 'does not persist the censor rule' do + post :create, :censor_rule => @censor_rule_params, + :request_id => @info_request.id, + :name_prefix => 'request_' + expect(assigns[:censor_rule]).to be_new_record + end + it 'renders the form' do + post :create, :censor_rule => @censor_rule_params, + :request_id => @info_request.id, + :name_prefix => 'request_' + expect(response).to render_template('new') + end + + end end - context 'successfully saving the censor rule' do + context 'user_id param' do before(:each) do - CensorRule.any_instance.stub(:save).and_return(true) + @censor_rule_params = FactoryGirl.build(:user_censor_rule).serializable_hash + # last_edit_editor gets set in the controller + @censor_rule_params.delete(:last_edit_editor) + @user = FactoryGirl.create(:user) + post :create, :user_id => @user.id, + :censor_rule => @censor_rule_params, + :name_prefix => 'user_' end - it 'persists the censor rule' do - pending("This raises an internal error in most cases") - post :create, :censor_rule => @censor_rule_params - expect(assigns[:censor_rule]).to be_persisted + it 'sets the last_edit_editor to the current admin' do + expect(assigns[:censor_rule].last_edit_editor).to eq('*unknown*') end - it 'confirms the censor rule is created' do - pending("This raises an internal error in most cases") - post :create, :censor_rule => @censor_rule_params - msg = 'CensorRule was successfully created.' - expect(flash[:notice]).to eq(msg) + it 'finds a user if the user_id param is supplied' do + expect(assigns[:censor_user]).to eq(@user) end - it 'raises an error after creating the rule' do - expect { - post :create, :censor_rule => @censor_rule_params - }.to raise_error 'internal error' + it 'associates the user with the new censor rule' do + expect(assigns[:censor_rule].user).to eq(@user) end - context 'a CensorRule with an associated InfoRequest' do + it 'sets the URL for the form to POST to' do + expect(assigns[:form_url]).to eq(admin_user_censor_rules_path(@user)) + end - before(:each) do - @censor_rule_params = FactoryGirl.build(:info_request_censor_rule).serializable_hash - # last_edit_editor gets set in the controller - @censor_rule_params.delete(:last_edit_editor) - end + context 'successfully saving the censor rule' do - it 'purges the cache for the info request' do + it 'purges the cache for the info request' do censor_rule = CensorRule.new(@censor_rule_params) - @controller.should_receive(:expire_for_request). - with(censor_rule.info_request) + @controller.should_receive(:expire_requests_for_user). + with(@user) - post :create, :censor_rule => @censor_rule_params + post :create, :censor_rule => @censor_rule_params, + :user_id => @user.id, + :name_prefix => 'user_' end it 'redirects to the associated info request' do - post :create, :censor_rule => @censor_rule_params + post :create, :censor_rule => @censor_rule_params, + :user_id => @user.id, + :name_prefix => 'user_' expect(response).to redirect_to( - admin_request_show_path(assigns[:censor_rule].info_request) + admin_user_path(assigns[:censor_rule].user) ) end end - context 'a CensorRule with an associated User' do + context 'unsuccessfully saving the censor rule' do before(:each) do - @censor_rule_params = FactoryGirl.build(:user_censor_rule).serializable_hash - # last_edit_editor gets set in the controller - @censor_rule_params.delete(:last_edit_editor) + CensorRule.any_instance.stub(:save).and_return(false) end - it 'purges the cache for the info request' do - censor_rule = CensorRule.new(@censor_rule_params) - @controller.should_receive(:expire_requests_for_user). - with(censor_rule.user) - - post :create, :censor_rule => @censor_rule_params + it 'does not persist the censor rule' do + post :create, :censor_rule => @censor_rule_params, + :user_id => @user.id, + :name_prefix => 'user_' + expect(assigns[:censor_rule]).to be_new_record end - it 'redirects to the associated info request' do - post :create, :censor_rule => @censor_rule_params - expect(response).to redirect_to( - admin_user_show_path(assigns[:censor_rule].user) - ) + it 'renders the form' do + post :create, :censor_rule => @censor_rule_params, + :user_id => @user.id, + :name_prefix => 'user_' + expect(response).to render_template('new') end end end - context 'unsuccessfully saving the censor rule' do + end + + describe 'GET edit' do + + context 'a CensorRule with an associated InfoRequest' do before(:each) do - CensorRule.any_instance.stub(:save).and_return(false) + @censor_rule = FactoryGirl.create(:info_request_censor_rule) end - it 'does not persist the censor rule' do - post :create, :censor_rule => @censor_rule_params - expect(assigns[:censor_rule]).to be_new_record + it 'returns a successful response' do + get :edit, :id => @censor_rule.id + expect(response).to be_success end - it 'renders the form' do - post :create, :censor_rule => @censor_rule_params - expect(response).to render_template('new') + it 'renders the correct template' do + get :edit, :id => @censor_rule.id + expect(response).to render_template('edit') + end + + it 'finds the correct censor rule to edit' do + get :edit, :id => @censor_rule.id + expect(assigns[:censor_rule]).to eq(@censor_rule) end end - end + context 'a CensorRule with an associated User' do - describe 'GET edit' do + before(:each) do + @censor_rule = FactoryGirl.create(:user_censor_rule) + end - before(:each) do - @censor_rule = FactoryGirl.create(:global_censor_rule) - end + it 'returns a successful response' do + get :edit, :id => @censor_rule.id + expect(response).to be_success + end - it 'returns a successful response' do - get :edit, :id => @censor_rule.id - expect(response).to be_success - end + it 'renders the correct template' do + get :edit, :id => @censor_rule.id + expect(response).to render_template('edit') + end + + it 'finds the correct censor rule to edit' do + get :edit, :id => @censor_rule.id + expect(assigns[:censor_rule]).to eq(@censor_rule) + end - it 'renders the correct template' do - get :edit, :id => @censor_rule.id - expect(response).to render_template('edit') end - it 'finds the correct censor rule to edit' do - get :edit, :id => @censor_rule.id - expect(assigns[:censor_rule]).to eq(@censor_rule) + context 'when editing a global rule' do + + before(:each) do + @censor_rule = FactoryGirl.create(:global_censor_rule) + end + + it 'shows an error notice' do + get :edit, :id => @censor_rule.id + flash[:notice].should == 'Only user and request censor rules can be edited' + end + + it 'redirects to the admin index' do + get :edit, :id => @censor_rule.id + expect(response).to redirect_to(admin_general_index_path) + end + end end describe 'PUT update' do - before(:each) do - @censor_rule = FactoryGirl.create(:global_censor_rule) - end + context 'a global CensorRule' do - it 'finds the correct censor rule to edit' do - put :update, :id => @censor_rule.id, - :censor_rule => { :text => 'different text' } + before(:each) do + @censor_rule = FactoryGirl.create(:global_censor_rule) + end - expect(assigns[:censor_rule]).to eq(@censor_rule) - end + it 'shows an error notice' do + get :edit, :id => @censor_rule.id + flash[:notice].should == 'Only user and request censor rules can be edited' + end - it 'sets the last_edit_editor to the current admin' do - put :update, :id => @censor_rule.id, - :censor_rule => { :text => 'different text' } + it 'redirects to the admin index' do + get :edit, :id => @censor_rule.id + expect(response).to redirect_to(admin_general_index_path) + end - expect(assigns[:censor_rule].last_edit_editor).to eq('*unknown*') end - context 'successfully saving the censor rule' do + context 'a CensorRule with an associated InfoRequest' do before(:each) do - CensorRule.any_instance.stub(:save).and_return(true) + @censor_rule = FactoryGirl.create(:info_request_censor_rule) end - it 'updates the censor rule' do - pending("This raises an internal error in most cases") + it 'finds the correct censor rule to edit' do put :update, :id => @censor_rule.id, :censor_rule => { :text => 'different text' } - @censor_rule.reload - expect(@censor_rule.text).to eq('different text') + + expect(assigns[:censor_rule]).to eq(@censor_rule) end - it 'confirms the censor rule is updated' do - pending("This raises an internal error in most cases") + it 'sets the last_edit_editor to the current admin' do put :update, :id => @censor_rule.id, :censor_rule => { :text => 'different text' } - msg = 'CensorRule was successfully updated.' - expect(flash[:notice]).to eq(msg) + expect(assigns[:censor_rule].last_edit_editor).to eq('*unknown*') end - it 'raises an error after updating the rule' do - expect { + context 'successfully saving the censor rule' do + + it 'updates the censor rule' do put :update, :id => @censor_rule.id, :censor_rule => { :text => 'different text' } - }.to raise_error 'internal error' - end - - context 'a CensorRule with an associated InfoRequest' do + @censor_rule.reload + expect(@censor_rule.text).to eq('different text') + end - before(:each) do - @censor_rule = FactoryGirl.create(:info_request_censor_rule) + it 'confirms the censor rule is updated' do + put :update, :id => @censor_rule.id, + :censor_rule => { :text => 'different text' } + msg = 'CensorRule was successfully updated.' + expect(flash[:notice]).to eq(msg) end it 'purges the cache for the info request' do @@ -348,87 +376,137 @@ describe AdminCensorRuleController do :censor_rule => { :text => 'different text' } expect(response).to redirect_to( - admin_request_show_path(assigns[:censor_rule].info_request) + admin_request_path(assigns[:censor_rule].info_request) ) end end - context 'a CensorRule with an associated User' do + context 'unsuccessfully saving the censor rule' do before(:each) do - @censor_rule = FactoryGirl.create(:user_censor_rule) + CensorRule.any_instance.stub(:save).and_return(false) end - it 'purges the cache for the info request' do - @controller.should_receive(:expire_requests_for_user). - with(@censor_rule.user) - + it 'does not update the censor rule' do put :update, :id => @censor_rule.id, :censor_rule => { :text => 'different text' } + @censor_rule.reload + expect(@censor_rule.text).to eq('some text to redact') end - it 'redirects to the associated info request' do + it 'renders the form' do put :update, :id => @censor_rule.id, :censor_rule => { :text => 'different text' } - expect(response).to redirect_to( - admin_user_show_path(assigns[:censor_rule].user) - ) + expect(response).to render_template('edit') end - end + end + end - context 'unsuccessfully saving the censor rule' do + context 'a CensorRule with an associated User' do before(:each) do - CensorRule.any_instance.stub(:save).and_return(false) + @censor_rule = FactoryGirl.create(:user_censor_rule) end - it 'does not update the censor rule' do + it 'finds the correct censor rule to edit' do put :update, :id => @censor_rule.id, :censor_rule => { :text => 'different text' } - @censor_rule.reload - expect(@censor_rule.text).to eq('some text to redact') + + expect(assigns[:censor_rule]).to eq(@censor_rule) end - it 'renders the form' do + it 'sets the last_edit_editor to the current admin' do put :update, :id => @censor_rule.id, :censor_rule => { :text => 'different text' } - expect(response).to render_template('edit') + expect(assigns[:censor_rule].last_edit_editor).to eq('*unknown*') + + end + + + context 'successfully saving the censor rule' do + + it 'updates the censor rule' do + put :update, :id => @censor_rule.id, + :censor_rule => { :text => 'different text' } + @censor_rule.reload + expect(@censor_rule.text).to eq('different text') + end + + it 'confirms the censor rule is updated' do + put :update, :id => @censor_rule.id, + :censor_rule => { :text => 'different text' } + msg = 'CensorRule was successfully updated.' + expect(flash[:notice]).to eq(msg) + end + + it 'purges the cache for the info request' do + @controller.should_receive(:expire_requests_for_user). + with(@censor_rule.user) + + put :update, :id => @censor_rule.id, + :censor_rule => { :text => 'different text' } + end + + it 'redirects to the associated info request' do + put :update, :id => @censor_rule.id, + :censor_rule => { :text => 'different text' } + + expect(response).to redirect_to( + admin_user_path(assigns[:censor_rule].user) + ) + end end + context 'unsuccessfully saving the censor rule' do + + before(:each) do + CensorRule.any_instance.stub(:save).and_return(false) + end + + it 'does not update the censor rule' do + put :update, :id => @censor_rule.id, + :censor_rule => { :text => 'different text' } + @censor_rule.reload + expect(@censor_rule.text).to eq('some text to redact') + end + + it 'renders the form' do + put :update, :id => @censor_rule.id, + :censor_rule => { :text => 'different text' } + + expect(response).to render_template('edit') + end + + end + end end describe 'DELETE destroy' do - before(:each) do - @censor_rule = FactoryGirl.create(:global_censor_rule) - end + context 'a global CensorRule' do - it 'finds the correct censor rule to destroy' do - pending("This raises an internal error in most cases") - # TODO: Replace :censor_rule_id with :id - delete :destroy, :censor_rule_id => @censor_rule.id - expect(assigns[:censor_rule]).to eq(@censor_rule) - end + before(:each) do + @censor_rule = FactoryGirl.create(:global_censor_rule) + end - it 'raises an error after destroying the rule' do - expect { - delete :destroy, :censor_rule_id => @censor_rule.id - }.to raise_error 'internal error' - end + it 'shows an error notice' do + get :edit, :id => @censor_rule.id + flash[:notice].should == 'Only user and request censor rules can be edited' + end + + it 'redirects to the admin index' do + get :edit, :id => @censor_rule.id + expect(response).to redirect_to(admin_general_index_path) + end - it 'confirms the censor rule is destroyed in all cases' do - pending("This actually raises an internal error anyway") - delete :destroy, :censor_rule_id => @censor_rule.id - msg = 'CensorRule was successfully destroyed.' - expect(flash[:notice]).to eq(msg) end context 'a CensorRule with an associated InfoRequest' do @@ -437,14 +515,25 @@ describe AdminCensorRuleController do @censor_rule = FactoryGirl.create(:info_request_censor_rule) end + it 'finds the correct censor rule to destroy' do + delete :destroy, :id => @censor_rule.id + expect(assigns[:censor_rule]).to eq(@censor_rule) + end + + it 'confirms the censor rule is destroyed in all cases' do + delete :destroy, :id => @censor_rule.id + msg = 'CensorRule was successfully destroyed.' + expect(flash[:notice]).to eq(msg) + end + it 'purges the cache for the info request' do @controller.should_receive(:expire_for_request).with(@censor_rule.info_request) - delete :destroy, :censor_rule_id => @censor_rule.id + delete :destroy, :id => @censor_rule.id end it 'redirects to the associated info request' do - delete :destroy, :censor_rule_id => @censor_rule.id - expect(response).to redirect_to(admin_request_show_path(@censor_rule.info_request)) + delete :destroy, :id => @censor_rule.id + expect(response).to redirect_to(admin_request_path(@censor_rule.info_request)) end end @@ -455,14 +544,25 @@ describe AdminCensorRuleController do @censor_rule = FactoryGirl.create(:user_censor_rule) end + it 'finds the correct censor rule to destroy' do + delete :destroy, :id => @censor_rule.id + expect(assigns[:censor_rule]).to eq(@censor_rule) + end + + it 'confirms the censor rule is destroyed in all cases' do + delete :destroy, :id => @censor_rule.id + msg = 'CensorRule was successfully destroyed.' + expect(flash[:notice]).to eq(msg) + end + it 'purges the cache for the user' do @controller.should_receive(:expire_requests_for_user).with(@censor_rule.user) - delete :destroy, :censor_rule_id => @censor_rule.id + delete :destroy, :id => @censor_rule.id end it 'redirects to the associated info request' do - delete :destroy, :censor_rule_id => @censor_rule.id - expect(response).to redirect_to(admin_user_show_path(@censor_rule.user)) + delete :destroy, :id => @censor_rule.id + expect(response).to redirect_to(admin_user_path(@censor_rule.user)) end end @@ -474,17 +574,17 @@ end describe AdminCensorRuleController, "when making censor rules from the admin interface" do render_views before { basic_auth_login @request } - + it "should create a censor rule and purge the corresponding request from varnish" do - ir = info_requests(:fancy_dog_request) - post :create, :censor_rule => { + ir = info_requests(:fancy_dog_request) + post :create, :request_id => ir.id, + :name_prefix => 'request_', + :censor_rule => { :text => "meat", :replacement => "tofu", - :last_edit_comment => "none", - :info_request_id => ir + :last_edit_comment => "none" } PurgeRequest.all().first.model_id.should == ir.id end - end diff --git a/spec/controllers/admin_comment_controller_spec.rb b/spec/controllers/admin_comment_controller_spec.rb new file mode 100644 index 000000000..f87231e3b --- /dev/null +++ b/spec/controllers/admin_comment_controller_spec.rb @@ -0,0 +1,66 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe AdminCommentController do + + describe :edit do + + before do + @comment = FactoryGirl.create(:comment) + get :edit, :id => @comment.id + end + + it 'renders the edit template' do + expect(response).to render_template('edit') + end + + it 'gets the comment' do + assigns[:comment].should == @comment + end + + end + + describe :update do + + context 'on valid data submission' do + + before do + @comment = FactoryGirl.create(:comment) + atts = FactoryGirl.attributes_for(:comment, :body => 'I am new') + put :update, :id => @comment.id, :comment => atts + end + + it 'gets the comment' do + assigns[:comment].should == @comment + end + + it 'updates the comment' do + Comment.find(@comment.id).body.should == 'I am new' + end + + it 'logs the update event' do + most_recent_event = Comment.find(@comment.id).info_request_events.last + most_recent_event.event_type.should == 'edit_comment' + most_recent_event.comment_id.should == @comment.id + end + + it 'shows a success notice' do + flash[:notice].should == "Comment successfully updated." + end + + it 'redirects to the request page' do + response.should redirect_to(admin_request_path(@comment.info_request)) + end + end + + context 'on invalid data submission' do + + it 'renders the edit template' do + @comment = FactoryGirl.create(:comment) + put :update, :id => @comment.id, :comment => {:body => ''} + response.should render_template('edit') + end + + end + end + +end diff --git a/spec/controllers/admin_holiday_imports_controller_spec.rb b/spec/controllers/admin_holiday_imports_controller_spec.rb new file mode 100644 index 000000000..dd23a022f --- /dev/null +++ b/spec/controllers/admin_holiday_imports_controller_spec.rb @@ -0,0 +1,73 @@ +require 'spec_helper' + +describe AdminHolidayImportsController do + + describe :new do + + it 'renders the new template' do + get :new + expect(response).to render_template('new') + end + + it 'creates an import' do + get :new + assigns[:holiday_import].should be_instance_of(HolidayImport) + end + + describe 'if the import is valid' do + + it 'populates the import' do + mock_import = mock(HolidayImport, :valid? => true, + :populate => nil) + HolidayImport.stub!(:new).and_return(mock_import) + mock_import.should_receive(:populate) + get :new + end + + end + + end + + describe :create do + + it 'creates an import' do + post :create + assigns[:holiday_import].should be_instance_of(HolidayImport) + end + + describe 'if the import can be saved' do + + before do + mock_import = mock(HolidayImport, :save => true) + HolidayImport.stub!(:new).and_return(mock_import) + post :create + end + + it 'should show a success notice' do + flash[:notice].should == 'Holidays successfully imported' + end + + it 'should redirect to the index' do + response.should redirect_to(admin_holidays_path) + end + + end + + describe 'if the import cannot be saved' do + + before do + mock_import = mock(HolidayImport, :save => false) + HolidayImport.stub!(:new).and_return(mock_import) + post :create + end + + it 'should render the new template' do + expect(response).to render_template('new') + end + + end + + end + + +end diff --git a/spec/controllers/admin_holidays_controller_spec.rb b/spec/controllers/admin_holidays_controller_spec.rb new file mode 100644 index 000000000..21cb51d29 --- /dev/null +++ b/spec/controllers/admin_holidays_controller_spec.rb @@ -0,0 +1,192 @@ +require 'spec_helper' + +describe AdminHolidaysController do + + describe :index do + + before do + @holiday_one = FactoryGirl.create(:holiday, :day => Date.new(2010, 1, 1)) + @holiday_two = FactoryGirl.create(:holiday, :day => Date.new(2011, 2, 2)) + @holiday_three = FactoryGirl.create(:holiday, :day => Date.new(2011, 3, 3)) + end + + it 'gets a hash of holidays keyed by year' do + get :index + assigns(:holidays_by_year)[2010].should include(@holiday_one) + assigns(:holidays_by_year)[2011].should include(@holiday_two) + assigns(:holidays_by_year)[2011].should include(@holiday_three) + end + + it 'gets a list of years with holidays' do + get :index + assigns(:years).should include(2010) + assigns(:years).should include(2011) + end + + it 'renders the index template' do + get :index + expect(response).to render_template('index') + end + + end + + describe :new do + + + describe 'when not using ajax' do + + it 'renders the new template' do + get :new + expect(response).to render_template('new') + end + + end + + describe 'when using ajax' do + + it 'renders the new form partial' do + xhr :get, :new + expect(response).to render_template('new_form') + end + end + + it 'creates a new holiday' do + get :new + assigns[:holiday].should be_instance_of(Holiday) + end + + end + + describe :create do + + before do + @holiday_params = { :description => "New Year's Day", + 'day(1i)' => '2010', + 'day(2i)' => '1', + 'day(3i)' => '1' } + post :create, :holiday => @holiday_params + end + + it 'creates a new holiday' do + assigns(:holiday).description.should == @holiday_params[:description] + assigns(:holiday).day.should == Date.new(2010, 1, 1) + assigns(:holiday).should be_persisted + end + + it 'shows the admin a success message' do + flash[:notice].should == 'Holiday successfully created.' + end + + it 'redirects to the index' do + response.should redirect_to admin_holidays_path + end + + context 'when there are errors' do + + before do + Holiday.any_instance.stub(:save).and_return(false) + post :create, :holiday => @holiday_params + end + + it 'renders the new template' do + expect(response).to render_template('new') + end + end + + end + + describe :edit do + + before do + @holiday = FactoryGirl.create(:holiday) + end + + describe 'when not using ajax' do + + it 'renders the edit template' do + get :edit, :id => @holiday.id + expect(response).to render_template('edit') + end + + end + + describe 'when using ajax' do + + it 'renders the edit form partial' do + xhr :get, :edit, :id => @holiday.id + expect(response).to render_template('edit_form') + end + + end + + it 'gets the holiday in the id param' do + get :edit, :id => @holiday.id + assigns[:holiday].should == @holiday + end + + end + + describe :update do + + before do + @holiday = FactoryGirl.create(:holiday, :day => Date.new(2010, 1, 1), + :description => "Test Holiday") + put :update, :id => @holiday.id, :holiday => { :description => 'New Test Holiday' } + end + + it 'gets the holiday in the id param' do + assigns[:holiday].should == @holiday + end + + it 'updates the holiday' do + holiday = Holiday.find(@holiday.id).description.should == 'New Test Holiday' + end + + it 'shows the admin a success message' do + flash[:notice].should == 'Holiday successfully updated.' + end + + it 'redirects to the index' do + response.should redirect_to admin_holidays_path + end + + context 'when there are errors' do + + before do + Holiday.any_instance.stub(:update_attributes).and_return(false) + put :update, :id => @holiday.id, :holiday => { :description => 'New Test Holiday' } + end + + it 'renders the edit template' do + expect(response).to render_template('edit') + end + end + + end + + describe :destroy do + + before(:each) do + @holiday = FactoryGirl.create(:holiday) + delete :destroy, :id => @holiday.id + end + + it 'finds the holiday to destroy' do + assigns(:holiday).should == @holiday + end + + it 'destroys the holiday' do + assigns(:holiday).should be_destroyed + end + + it 'tells the admin the holiday has been destroyed' do + msg = "Holiday successfully destroyed" + flash[:notice].should == msg + end + + it 'redirects to the index action' do + expect(response).to redirect_to(admin_holidays_path) + end + end + + end diff --git a/spec/controllers/admin_incoming_message_controller_spec.rb b/spec/controllers/admin_incoming_message_controller_spec.rb index 21c744e5b..24a526ca4 100644 --- a/spec/controllers/admin_incoming_message_controller_spec.rb +++ b/spec/controllers/admin_incoming_message_controller_spec.rb @@ -17,19 +17,19 @@ describe AdminIncomingMessageController, "when administering incoming messages" it "destroys the raw email file" do raw_email = @im.raw_email.filepath assert_equal File.exists?(raw_email), true - post :destroy, :incoming_message_id => @im.id + post :destroy, :id => @im.id assert_equal File.exists?(raw_email), false end it 'asks the incoming message to fully destroy itself' do IncomingMessage.stub!(:find).and_return(@im) @im.should_receive(:fully_destroy) - post :destroy, :incoming_message_id => @im.id + post :destroy, :id => @im.id end it 'expires the file cache for the associated info_request' do @controller.should_receive(:expire_for_request).with(@im.info_request) - post :destroy, :incoming_message_id => @im.id + post :destroy, :id => @im.id end end @@ -46,7 +46,7 @@ describe AdminIncomingMessageController, "when administering incoming messages" destination_info_request = info_requests(:naughty_chicken_request) incoming_message = incoming_messages(:useless_incoming_message) @controller.should_receive(:expire_for_request).with(current_info_request) - post :redeliver, :redeliver_incoming_message_id => incoming_message.id, + post :redeliver, :id => incoming_message.id, :url_title => destination_info_request.url_title end @@ -56,7 +56,7 @@ describe AdminIncomingMessageController, "when administering incoming messages" current_info_request = info_requests(:fancy_dog_request) destination_info_request = info_requests(:naughty_chicken_request) incoming_message = incoming_messages(:useless_incoming_message) - post :redeliver, :redeliver_incoming_message_id => incoming_message.id, + post :redeliver, :id => incoming_message.id, :url_title => destination_info_request.url_title end @@ -130,7 +130,7 @@ describe AdminIncomingMessageController, "when administering incoming messages" it 'should redirect to the admin info request view' do make_request - response.should redirect_to admin_request_show_url(@incoming.info_request) + response.should redirect_to admin_request_url(@incoming.info_request) end it 'should show a message that the incoming message has been updated' do diff --git a/spec/controllers/admin_info_request_event_controller_spec.rb b/spec/controllers/admin_info_request_event_controller_spec.rb new file mode 100644 index 000000000..23300a0b8 --- /dev/null +++ b/spec/controllers/admin_info_request_event_controller_spec.rb @@ -0,0 +1,41 @@ +# coding: utf-8 +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe AdminInfoRequestEventController do + + describe :update do + + describe 'when handling valid data' do + + before do + @info_request_event = FactoryGirl.create(:info_request_event) + put :update, :id => @info_request_event + end + + it 'gets the info request event' do + assigns[:info_request_event].should == @info_request_event + end + + it 'sets the described and calculated states on the event' do + event = InfoRequestEvent.find(@info_request_event.id) + event.described_state.should == 'waiting_clarification' + event.calculated_state.should == 'waiting_clarification' + end + + it 'shows a success notice' do + flash[:notice].should == 'Old response marked as having been a clarification' + end + + it 'redirects to the request admin page' do + response.should redirect_to(admin_request_url(@info_request_event.info_request)) + end + end + + it 'raises an exception if the event is not a response' do + @info_request_event = FactoryGirl.create(:sent_event) + lambda{ put :update, :id => @info_request_event }.should raise_error + end + + end + +end diff --git a/spec/controllers/admin_outgoing_message_controller_spec.rb b/spec/controllers/admin_outgoing_message_controller_spec.rb index 0dde53b86..a46a077da 100644 --- a/spec/controllers/admin_outgoing_message_controller_spec.rb +++ b/spec/controllers/admin_outgoing_message_controller_spec.rb @@ -79,7 +79,7 @@ describe AdminOutgoingMessageController do it 'should redirect to the admin info request view' do make_request - response.should redirect_to admin_request_show_url(@info_request) + response.should redirect_to admin_request_url(@info_request) end it 'should show a message that the incoming message has been updated' do diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index f176150da..3ab58317a 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -402,7 +402,7 @@ describe AdminPublicBodyController, "when destroying a public body" do it "destroys a public body" do n = PublicBody.count post :destroy, { :id => public_bodies(:forlorn_public_body).id } - response.should redirect_to(:controller=>'admin_public_body', :action=>'list') + response.should redirect_to admin_bodies_path PublicBody.count.should == n - 1 end @@ -416,7 +416,7 @@ describe AdminPublicBodyController, "when assigning public body tags" do n = PublicBody.joins(:translations).where([condition, "en"]).count post :mass_tag_add, { :new_tag => "department", :table_name => "substring" } request.flash[:notice].should == "Added tag to table of bodies." - response.should redirect_to(:action=>'list') + response.should redirect_to admin_bodies_path PublicBody.find_by_tag("department").count.should == n end end diff --git a/spec/controllers/admin_raw_email_controller_spec.rb b/spec/controllers/admin_raw_email_controller_spec.rb new file mode 100644 index 000000000..77c57c38b --- /dev/null +++ b/spec/controllers/admin_raw_email_controller_spec.rb @@ -0,0 +1,30 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe AdminRawEmailController do + + describe :show do + + before do + @raw_email = FactoryGirl.create(:incoming_message).raw_email + end + + describe 'html version' do + + it 'renders the show template' do + get :show, :id => @raw_email.id + end + + end + + describe 'text version' do + + it 'sends the email as an RFC-822 attachment' do + get :show, :id => @raw_email.id, :format => 'txt' + response.content_type.should == 'message/rfc822' + response.body.should == @raw_email.data + end + end + + end + +end diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index 7c5253f49..4eb463963 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -57,12 +57,12 @@ describe AdminRequestController, "when administering requests" do it 'expires the file cache for that request' do info_request = info_requests(:badger_request) @controller.should_receive(:expire_for_request).with(info_request) - get :fully_destroy, { :id => info_request } + get :destroy, { :id => info_request } end it 'uses a different flash message to avoid trying to fetch a non existent user record' do info_request = info_requests(:external_request) - post :fully_destroy, { :id => info_request.id } + post :destroy, { :id => info_request.id } request.flash[:notice].should include('external') end @@ -77,34 +77,6 @@ describe AdminRequestController, "when administering the holding pen" do load_raw_emails_data end - it "shows a rejection reason for an incoming message from an invalid address" do - ir = info_requests(:fancy_dog_request) - ir.allow_new_responses_from = 'authority_only' - ir.handle_rejected_responses = 'holding_pen' - ir.save! - receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "frob@nowhere.com") - get :show_raw_email, :id => InfoRequest.holding_pen_request.get_last_public_response.raw_email.id - response.should contain "Only the authority can reply to this request" - end - - it "guesses a misdirected request" do - ir = info_requests(:fancy_dog_request) - ir.handle_rejected_responses = 'holding_pen' - ir.allow_new_responses_from = 'authority_only' - ir.save! - mail_to = "request-#{ir.id}-asdfg@example.com" - receive_incoming_mail('incoming-request-plain.email', mail_to) - interesting_email = InfoRequest.holding_pen_request.get_last_public_response.raw_email.id - # now we add another message to the queue, which we're not interested in - receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "") - InfoRequest.holding_pen_request.incoming_messages.length.should == 2 - get :show_raw_email, :id => interesting_email - response.should contain "Could not identify the request" - assigns[:info_requests][0].should == ir - end - - - it "shows a suitable default 'your email has been hidden' message" do ir = info_requests(:fancy_dog_request) get :show, :id => ir.id @@ -119,7 +91,7 @@ describe AdminRequestController, "when administering the holding pen" do it "hides requests and sends a notification email that it has done so" do ir = info_requests(:fancy_dog_request) - post :hide_request, :id => ir.id, :explanation => "Foo", :reason => "vexatious" + post :hide, :id => ir.id, :explanation => "Foo", :reason => "vexatious" ir.reload ir.prominence.should == "requester_only" ir.described_state.should == "vexatious" @@ -132,7 +104,7 @@ describe AdminRequestController, "when administering the holding pen" do it 'expires the file cache for the request' do ir = info_requests(:fancy_dog_request) @controller.should_receive(:expire_for_request).with(ir) - post :hide_request, :id => ir.id, :explanation => "Foo", :reason => "vexatious" + post :hide, :id => ir.id, :explanation => "Foo", :reason => "vexatious" end describe 'when hiding an external request' do @@ -153,7 +125,7 @@ describe AdminRequestController, "when administering the holding pen" do end def make_request(params=@default_params) - post :hide_request, params + post :hide, params end it 'should redirect the the admin page for the request' do diff --git a/spec/controllers/admin_track_controller_spec.rb b/spec/controllers/admin_track_controller_spec.rb index f2de6c0d3..d29db4966 100644 --- a/spec/controllers/admin_track_controller_spec.rb +++ b/spec/controllers/admin_track_controller_spec.rb @@ -1,9 +1,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminTrackController, "when administering tracks" do - render_views - - it "shows the list page" do - get :list + + it "shows the index page" do + get :index end end diff --git a/spec/controllers/admin_user_controller_spec.rb b/spec/controllers/admin_user_controller_spec.rb index 8b89506f9..e979355cf 100644 --- a/spec/controllers/admin_user_controller_spec.rb +++ b/spec/controllers/admin_user_controller_spec.rb @@ -2,13 +2,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminUserController, "when administering users" do render_views - - it "shows the index/list page" do + + it "shows the index page" do get :index end it "searches for 'bob'" do - get :list, :query => "bob" + get :index, :query => "bob" assigns[:admin_users].should == [ users(:bob_smith_user) ] end @@ -51,7 +51,7 @@ describe AdminUserController do before(:each) do @user = FactoryGirl.create(:user) - request.env["HTTP_REFERER"] = admin_user_show_path(@user) + request.env["HTTP_REFERER"] = admin_user_path(@user) end it 'redirects to the page the admin was previously on' do @@ -61,7 +61,7 @@ describe AdminUserController do :comment_ids => comment.id, :hide_selected => 'hidden' } - response.should redirect_to(admin_user_show_path(@user)) + response.should redirect_to(admin_user_path(@user)) end it 'sets the given comments visibility to hidden' do diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 8652d9b17..128a42556 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -138,6 +138,35 @@ describe GeneralController, "when showing the frontpage" do end + describe 'when handling logged-in users' do + + before do + @user = FactoryGirl.create(:user) + session[:user_id] = @user.id + end + + it 'should set a time to live on a non "remember me" session' do + get :frontpage + response.body.should match @user.name + session[:ttl].should be_within(1).of(Time.now) + end + + it 'should not set a time to live on a "remember me" session' do + session[:remember_me] = true + get :frontpage + response.body.should match @user.name + session[:ttl].should be_nil + end + + it 'should end a logged-in session whose ttl has expired' do + session[:ttl] = Time.now - 4.hours + get :frontpage + response.should redirect_to signin_path + session[:user_id].should be_nil + end + + end + end diff --git a/spec/controllers/public_body_change_requests_controller_spec.rb b/spec/controllers/public_body_change_requests_controller_spec.rb index 8fe7befeb..4053b2f40 100644 --- a/spec/controllers/public_body_change_requests_controller_spec.rb +++ b/spec/controllers/public_body_change_requests_controller_spec.rb @@ -28,6 +28,7 @@ describe PublicBodyChangeRequestsController, "creating a change request" do it "should send an email to the site contact address" do post :create, {:public_body_change_request => @change_request_params} + change_request_id = assigns[:change_request].id deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] @@ -37,8 +38,8 @@ describe PublicBodyChangeRequestsController, "creating a change request" do mail.body.should include('new_body@example.com') mail.body.should include('New Body') mail.body.should include("Please") - mail.body.should include('http://test.host/admin/body/new?change_request_id=') - mail.body.should include('http://test.host/admin/change_request/edit/') + mail.body.should include("http://test.host/admin/bodies/new?change_request_id=#{change_request_id}") + mail.body.should include("http://test.host/admin/change_requests/#{change_request_id}/edit") end it 'should show a notice' do @@ -83,6 +84,7 @@ describe PublicBodyChangeRequestsController, "creating a change request" do it 'should send an email to the site contact address' do post :create, {:public_body_change_request => @change_request_params} + change_request_id = assigns[:change_request].id deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] @@ -92,8 +94,8 @@ describe PublicBodyChangeRequestsController, "creating a change request" do mail.body.should include('new_body@example.com') mail.body.should include(@public_body.name) mail.body.should include("Please") - mail.body.should include("http://test.host/admin/body/edit/#{@public_body.id}?change_request_id=") - mail.body.should include('http://test.host/admin/change_request/edit/') + mail.body.should include("http://test.host/admin/bodies/#{@public_body.id}/edit?change_request_id=#{change_request_id}") + mail.body.should include("http://test.host/admin/change_requests/#{change_request_id}/edit") end it 'should show a notice' do diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 840b4bb28..130631ef6 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -70,6 +70,18 @@ describe PublicBodyController, "when showing a body" do get :show, :url_name => "dFh", :view => 'all' response.should redirect_to(:controller => 'public_body', :action => 'show', :url_name => "dfh") end + + it 'keeps the search_params flash' do + # Make two get requests to simulate the flash getting swept after the + # first response. + search_params = { 'query' => 'Quango' } + get :show, { :url_name => 'dfh', :view => 'all' }, + nil, + { :search_params => search_params } + get :show, :url_name => 'dfh', :view => 'all' + expect(flash[:search_params]).to eq(search_params) + end + end describe PublicBodyController, "when listing bodies" do @@ -479,4 +491,15 @@ describe PublicBodyController, "when doing type ahead searches" do response.should render_template('public_body/_search_ahead') assigns[:xapian_requests].should be_nil end + + it 'remembers the search params' do + search_params = { + 'query' => 'Quango', + 'page' => '1', + 'bodies' => '1' + } + get :search_typeahead, search_params + expect(flash[:search_params]).to eq(search_params) + end + end diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 26e46a966..02237b29d 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -956,6 +956,20 @@ describe RequestController, "when searching for an authority" do }.should_not raise_error(StandardError) end end + + it "remembers the search params" do + session[:user_id] = @user.id + search_params = { + 'query' => 'Quango', + 'page' => '1', + 'bodies' => '1' + } + + get :select_authority, search_params + + expect(flash[:search_params]).to eq(search_params) + end + end describe RequestController, "when creating a new request" do @@ -1073,6 +1087,16 @@ describe RequestController, "when creating a new request" do response.redirect_url.should =~ /request\/why_is_your_quango_called_gerald\/new$/ end + it "sets the request_sent flash to true if successful" do + session[:user_id] = @user.id + post :new, :info_request => { :public_body_id => @body.id, + :title => "Why is your quango called Geraldine?", :tag_string => "" }, + :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." }, + :submitted_new_request => 1, :preview => 0 + + expect(flash[:request_sent]).to be_true + end + it "should give an error if the same request is submitted twice" do session[:user_id] = @user.id @@ -2392,6 +2416,23 @@ describe RequestController, "when doing type ahead searches" do get :search_typeahead, :q => "dog -chicken" assigns[:xapian_requests].results.size.should == 1 end + + it 'can filter search results by public body' do + get :search_typeahead, :q => 'boring', :requested_from => 'dfh' + expect(assigns[:query]).to eq('requested_from:dfh boring') + end + + it 'defaults to 25 results per page' do + get :search_typeahead, :q => 'boring' + expect(assigns[:per_page]).to eq(25) + end + + it 'can limit the number of searches returned' do + get :search_typeahead, :q => 'boring', :per_page => '1' + expect(assigns[:per_page]).to eq(1) + expect(assigns[:xapian_requests].results.size).to eq(1) + end + end describe RequestController, "when showing similar requests" do @@ -2442,7 +2483,7 @@ describe RequestController, "when caching fragments" do :info_request_id => 132, :id => 44, :get_attachments_for_display => nil, - :html_mask_stuff! => nil, + :apply_masks! => nil, :user_can_view? => true, :all_can_view? => true) attachment = FactoryGirl.build(:body_text, :filename => long_name) @@ -2537,10 +2578,9 @@ describe RequestController, "#new_batch" do assigns[:existing_batch].should_not be_nil end - it 'should display a success notice' do + it 'sets the batch_sent flash to true' do make_request - notice_text = "<p>Your Freedom of Information requests will be <strong>sent</strong> shortly!" - flash[:notice].should match notice_text + expect(flash[:batch_sent]).to be_true end end @@ -2655,7 +2695,7 @@ describe RequestController, "#select_authorities" do end - context 'when asked for JSON', :focus => true do + context 'when asked for JSON' do it 'should be successful' do get :select_authorities, {:public_body_query => "Quan", :format => 'json'}, {:user_id => @user.id} diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 14731f090..621dbaaac 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -12,6 +12,14 @@ describe ServicesController, "when returning a message for people in other count @old_locale = FastGettext.locale() end + it 'keeps the flash' do + # Make two get requests to simulate the flash getting swept after the + # first response. + get :other_country_message, nil, nil, :some_flash_key => 'abc' + get :other_country_message + expect(flash[:some_flash_key]).to eq('abc') + end + it "should show no alaveteli message when in the deployed country" do config = MySociety::Config.load_default() config['ISO_COUNTRY_CODE'] = "DE" @@ -60,21 +68,25 @@ describe ServicesController, "when returning a message for people in other count response.should be_success response.body.should == 'Hello! We have an <a href="/help/alaveteli?country_name=Deutschland">important message</a> for visitors outside Deutschland' end + it "should default to no message if the country_from_ip domain doesn't exist" do AlaveteliConfiguration.stub!(:gaze_url).and_return('http://12123sdf14qsd.com') get :other_country_message response.should be_success response.body.should == '' end + it "should default to no message if the country_from_ip service doesn't exist" do AlaveteliConfiguration.stub!(:gaze_url).and_return('http://www.google.com') get :other_country_message response.should be_success response.body.should == '' end - it "should default to no message if the country_from_ip service returns an error" do + + it "should default to no message and log the error with url if the country_from_ip service returns an error" do FakeWeb.register_uri(:get, %r|500.com|, :body => "Error", :status => ["500", "Error"]) AlaveteliConfiguration.stub!(:gaze_url).and_return('http://500.com') + Rails.logger.should_receive(:warn).with /500\.com.*500 Error/ get :other_country_message response.should be_success response.body.should == '' |