diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/admin_user_controller_spec.rb | 23 | ||||
-rw-r--r-- | spec/controllers/info_request_batch_controller_spec.rb | 53 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 269 | ||||
-rw-r--r-- | spec/controllers/track_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/controllers/user_controller_spec.rb | 95 | ||||
-rw-r--r-- | spec/factories.rb | 6 | ||||
-rw-r--r-- | spec/mailers/info_request_batch_mailer.rb | 35 | ||||
-rw-r--r-- | spec/models/info_request_batch_spec.rb | 150 | ||||
-rw-r--r-- | spec/models/info_request_spec.rb | 19 | ||||
-rw-r--r-- | spec/models/outgoing_message_spec.rb | 14 | ||||
-rw-r--r-- | spec/models/track_thing_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 31 |
12 files changed, 661 insertions, 38 deletions
diff --git a/spec/controllers/admin_user_controller_spec.rb b/spec/controllers/admin_user_controller_spec.rb index a6e5a0d7e..99894a414 100644 --- a/spec/controllers/admin_user_controller_spec.rb +++ b/spec/controllers/admin_user_controller_spec.rb @@ -15,13 +15,32 @@ describe AdminUserController, "when administering users" do it "shows a user" do get :show, :id => users(:bob_smith_user) end - + it "logs in as another user" do get :login_as, :id => users(:bob_smith_user).id post_redirect = PostRedirect.get_last_post_redirect response.should redirect_to(:controller => 'user', :action => 'confirm', :email_token => post_redirect.email_token) end - + # See also "allows an admin to log in as another user" in spec/integration/admin_spec.rb end +describe AdminUserController, "when updating a user" do + + it "saves a change to 'can_make_batch_requests'" do + user = FactoryGirl.create(:user) + user.can_make_batch_requests?.should be_false + post :update, {:id => user.id, :admin_user => {:can_make_batch_requests => '1', + :name => user.name, + :email => user.email, + :admin_level => user.admin_level, + :ban_text => user.ban_text, + :about_me => user.about_me, + :no_limit => user.no_limit}} + flash[:notice].should == 'User successfully updated.' + response.should be_redirect + user = User.find(user.id) + user.can_make_batch_requests?.should be_true + end + +end diff --git a/spec/controllers/info_request_batch_controller_spec.rb b/spec/controllers/info_request_batch_controller_spec.rb new file mode 100644 index 000000000..d08f02e10 --- /dev/null +++ b/spec/controllers/info_request_batch_controller_spec.rb @@ -0,0 +1,53 @@ +# coding: utf-8 +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe InfoRequestBatchController, "when showing a request" do + + before do + @first_public_body = FactoryGirl.create(:public_body) + @second_public_body = FactoryGirl.create(:public_body) + @info_request_batch = FactoryGirl.create(:info_request_batch, :title => 'Matched title', + :body => 'Matched body', + :public_bodies => [@first_public_body, + @second_public_body]) + @first_request = FactoryGirl.create(:info_request, :info_request_batch => @info_request_batch, + :public_body => @first_public_body) + @second_request = FactoryGirl.create(:info_request, :info_request_batch => @info_request_batch, + :public_body => @second_public_body) + @default_params = {:id => @info_request_batch.id} + end + + def make_request(params=@default_params) + get :show, params + end + + it 'should be successful' do + make_request + response.should be_success + end + + it 'should assign an info_request_batch to the view' do + make_request + assigns[:info_request_batch].should == @info_request_batch + end + + context 'when the batch has not been sent' do + + it 'should assign public_bodies to the view' do + make_request + assigns[:public_bodies].should == [@first_public_body, @second_public_body] + end + end + + context 'when the batch has been sent' do + + it 'should assign info_requests to the view' do + @info_request_batch.sent_at = Time.now + @info_request_batch.save! + make_request + assigns[:info_requests].sort.should == [@first_request, @second_request] + end + + end + +end diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 23f19f389..1e7df4536 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -811,7 +811,7 @@ describe RequestController, "when handling prominence" do expect_hidden('request/hidden_correspondence') end - it 'should download attachments for an admin user', :focus => true do + it 'should download attachments for an admin user' do session[:user_id] = FactoryGirl.create(:admin_user).id get :get_attachment, :incoming_message_id => @incoming_message.id, :id => @info_request.id, @@ -873,7 +873,7 @@ describe RequestController, "when handling prominence" do response.should be_success end - it 'should download attachments for an admin user', :focus => true do + it 'should download attachments for an admin user' do session[:user_id] = FactoryGirl.create(:admin_user).id get :get_attachment, :incoming_message_id => @incoming_message.id, :id => @info_request.id, @@ -2423,3 +2423,268 @@ describe RequestController, "when caching fragments" do end +describe RequestController, "#new_batch" do + + context "when batch requests is enabled" do + + before do + AlaveteliConfiguration.stub!(:allow_batch_requests).and_return(true) + end + + context "when the current user can make batch requests" do + + before do + @user = FactoryGirl.create(:user, :can_make_batch_requests => true) + @public_body = FactoryGirl.create(:public_body) + @other_public_body = FactoryGirl.create(:public_body) + @public_body_ids = [@public_body.id, @other_public_body.id] + @default_post_params = { :info_request => { :title => "What does it all mean?", + :tag_string => "" }, + :public_body_ids => @public_body_ids, + :outgoing_message => { :body => "This is a silly letter." }, + :submitted_new_request => 1, + :preview => 1 } + end + + it 'should be successful' do + get :new_batch, {:public_body_ids => @public_body_ids}, {:user_id => @user.id} + response.should be_success + end + + it 'should render the "new" template' do + get :new_batch, {:public_body_ids => @public_body_ids}, {:user_id => @user.id} + response.should render_template('request/new') + end + + it 'should redirect to "select_authorities" if no public_body_ids param is passed' do + get :new_batch, {}, {:user_id => @user.id} + response.should redirect_to select_authorities_path + end + + it "should render 'preview' when given a good title and body" do + post :new_batch, @default_post_params, { :user_id => @user.id } + response.should render_template('preview') + end + + it "should give an error and render 'new' template when a summary isn't given" do + @default_post_params[:info_request].delete(:title) + post :new_batch, @default_post_params, { :user_id => @user.id } + assigns[:info_request].errors[:title].should == ['Please enter a summary of your request'] + response.should render_template('new') + end + + it "should allow re-editing of a request" do + params = @default_post_params.merge(:preview => 0, :reedit => 1) + post :new_batch, params, { :user_id => @user.id } + response.should render_template('new') + end + + context "on success" do + + def make_request + @params = @default_post_params.merge(:preview => 0) + post :new_batch, @params, { :user_id => @user.id } + end + + it 'should create an info request batch and redirect to the new batch on success' do + make_request + new_info_request_batch = assigns[:info_request_batch] + new_info_request_batch.should_not be_nil + response.should redirect_to(info_request_batch_path(new_info_request_batch)) + end + + it 'should prevent double submission of a batch request' do + make_request + post :new_batch, @params, { :user_id => @user.id } + response.should render_template('new') + assigns[:existing_batch].should_not be_nil + end + + it 'should display a success notice' do + make_request + notice_text = "<p>Your Freedom of Information requests will be <strong>sent</strong> shortly!" + flash[:notice].should match notice_text + end + + end + + context "when the user is banned" do + + before do + @user.ban_text = "bad behaviour" + @user.save! + end + + it 'should show the "banned" template' do + post :new_batch, @default_post_params, { :user_id => @user.id } + response.should render_template('user/banned') + assigns[:details].should == 'bad behaviour' + end + + end + + end + + context "when the current user can't make batch requests" do + + render_views + + before do + @user = FactoryGirl.create(:user) + end + + it 'should return a 403 with an appropriate message' do + get :new_batch, {}, {:user_id => @user.id} + response.code.should == '403' + response.body.should match("Users cannot usually make batch requests to multiple authorities at once") + end + + end + + context 'when there is no logged-in user' do + + it 'should return a redirect to the login page' do + get :new_batch + post_redirect = PostRedirect.get_last_post_redirect + response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token) + end + end + + + end + + context "when batch requests is not enabled" do + + it 'should return a 404' do + Rails.application.config.stub!(:consider_all_requests_local).and_return(false) + get :new_batch + response.code.should == '404' + end + + end + +end + +describe RequestController, "#select_authorities" do + + context "when batch requests is enabled" do + + before do + get_fixtures_xapian_index + load_raw_emails_data + AlaveteliConfiguration.stub!(:allow_batch_requests).and_return(true) + end + + context "when the current user can make batch requests" do + + before do + @user = FactoryGirl.create(:user, :can_make_batch_requests => true) + end + + context 'when asked for HTML' do + + it 'should be successful' do + get :select_authorities, {}, {:user_id => @user.id} + response.should be_success + end + + it 'should render the "select_authorities" template' do + get :select_authorities, {}, {:user_id => @user.id} + response.should render_template('request/select_authorities') + end + + it 'should assign a list of search results to the view if passed a query' do + get :select_authorities, {:public_body_query => "Quango"}, {:user_id => @user.id} + assigns[:search_bodies].results.size.should == 1 + assigns[:search_bodies].results[0][:model].name.should == public_bodies(:geraldine_public_body).name + end + + it 'should assign a list of public bodies to the view if passed a list of ids' do + get :select_authorities, {:public_body_ids => [public_bodies(:humpadink_public_body).id]}, + {:user_id => @user.id} + assigns[:public_bodies].size.should == 1 + assigns[:public_bodies][0].name.should == public_bodies(:humpadink_public_body).name + end + + it 'should subtract a list of public bodies to remove from the list of bodies assigned to + the view' do + get :select_authorities, {:public_body_ids => [public_bodies(:humpadink_public_body).id, + public_bodies(:geraldine_public_body).id], + :remove_public_body_ids => [public_bodies(:geraldine_public_body).id]}, + {:user_id => @user.id} + assigns[:public_bodies].size.should == 1 + assigns[:public_bodies][0].name.should == public_bodies(:humpadink_public_body).name + end + + end + + context 'when asked for JSON', :focus => true do + + it 'should be successful' do + get :select_authorities, {:public_body_query => "Quan", :format => 'json'}, {:user_id => @user.id} + response.should be_success + end + + it 'should return a list of public body names and ids' do + get :select_authorities, {:public_body_query => "Quan", :format => 'json'}, + {:user_id => @user.id} + + JSON(response.body).should == [{ 'id' => public_bodies(:geraldine_public_body).id, + 'name' => public_bodies(:geraldine_public_body).name }] + end + + it 'should return an empty list if no search is passed' do + get :select_authorities, {:format => 'json' },{:user_id => @user.id} + JSON(response.body).should == [] + end + + it 'should return an empty list if there are no bodies' do + get :select_authorities, {:public_body_query => 'fknkskalnr', :format => 'json' }, + {:user_id => @user.id} + JSON(response.body).should == [] + end + + end + + end + + context "when the current user can't make batch requests" do + + render_views + + before do + @user = FactoryGirl.create(:user) + end + + it 'should return a 403 with an appropriate message' do + get :select_authorities, {}, {:user_id => @user.id} + response.code.should == '403' + response.body.should match("Users cannot usually make batch requests to multiple authorities at once") + end + + end + + context 'when there is no logged-in user' do + + it 'should return a redirect to the login page' do + get :select_authorities + post_redirect = PostRedirect.get_last_post_redirect + response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token) + end + end + + + end + + context "when batch requests is not enabled" do + + it 'should return a 404' do + Rails.application.config.stub!(:consider_all_requests_local).and_return(false) + get :select_authorities + response.code.should == '404' + end + + end + +end + diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 57d084f6b..40865d2b9 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -10,7 +10,7 @@ describe TrackController, "when making a new track on a request" do :tracking_user_id= => nil) TrackThing.stub!(:create_track_for_request).and_return(@track_thing) TrackThing.stub!(:create_track_for_search_query).and_return(@track_thing) - TrackThing.stub!(:find_by_existing_track).and_return(nil) + TrackThing.stub!(:find_existing).and_return(nil) InfoRequest.stub!(:find_by_url_title!) do |url_title| if url_title == "myrequest" @ir diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 0033309a5..cf361d898 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -30,55 +30,90 @@ describe UserController, "when redirecting a show request to a canonical url" do end describe UserController, "when showing a user" do - render_views + before(:each) do - load_raw_emails_data - get_fixtures_xapian_index + @user = FactoryGirl.create(:user) end it "should be successful" do - get :show, :url_name => "bob_smith" + get :show, :url_name => @user.url_name response.should be_success end it "should render with 'show' template" do - get :show, :url_name => "bob_smith" + get :show, :url_name => @user.url_name response.should render_template('show') end - it "should distinguish between 'my profile' and 'my requests' for logged in users" do - session[:user_id] = users(:bob_smith_user).id - get :show, :url_name => "bob_smith", :view => 'requests' - response.body.should_not include("Change your password") - response.body.should match(/Your [0-9]+ Freedom of Information requests/) - get :show, :url_name => "bob_smith", :view => 'profile' - response.body.should include("Change your password") - response.body.should_not match(/Your [0-9]+ Freedom of Information requests/) + it "should assign the user" do + get :show, :url_name => @user.url_name + assigns[:display_user].should == @user end - it "should assign the user" do - get :show, :url_name => "bob_smith" - assigns[:display_user].should == users(:bob_smith_user) + context "when viewing the user's own profile" do + + render_views + + def make_request + get :show, {:url_name => @user.url_name, :view => 'profile'}, {:user_id => @user.id} + end + + it 'should not show requests, or batch requests, but should show account options' do + make_request + response.body.should_not match(/Freedom of Information requests made by you/) + assigns[:show_batches].should be_false + response.body.should include("Change your password") + end + end - it "should search the user's contributions" do - get :show, :url_name => "bob_smith" - assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all( - :conditions => "user_id = #{users(:bob_smith_user).id}") + context "when viewing a user's own requests" do + + render_views + + def make_request + get :show, {:url_name => @user.url_name, :view => 'requests'}, {:user_id => @user.id} + end + + it 'should show requests, batch requests, but no account options' do + make_request + response.body.should match(/Freedom of Information requests made by you/) + assigns[:show_batches].should be_true + response.body.should_not include("Change your password") + end - get :show, :url_name => "bob_smith", :user_query => "money" - assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ [ - info_requests(:naughty_chicken_request), - info_requests(:another_boring_request), - ] end - it "should not show unconfirmed users" do - begin - get :show, :url_name => "unconfirmed_user" - rescue => e +end + +describe UserController, "when showing a user" do + + context 'when using fixture data' do + + before do + load_raw_emails_data + get_fixtures_xapian_index end - e.should be_an_instance_of(ActiveRecord::RecordNotFound) + + it "should search the user's contributions" do + get :show, :url_name => "bob_smith" + assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all( + :conditions => "user_id = #{users(:bob_smith_user).id}") + + get :show, :url_name => "bob_smith", :user_query => "money" + assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ [ + info_requests(:naughty_chicken_request), + info_requests(:another_boring_request), + ] + end + + it "should not show unconfirmed users" do + begin + get :show, :url_name => "unconfirmed_user" + rescue => e + end + e.should be_an_instance_of(ActiveRecord::RecordNotFound) + end end end diff --git a/spec/factories.rb b/spec/factories.rb index 8b724ae37..8efc53033 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -123,6 +123,7 @@ FactoryGirl.define do salt "-6116981980.392287733335677" hashed_password '6b7cd45a5f35fd83febc0452a799530398bfb6e8' # jonespassword email_confirmed true + ban_text "" factory :admin_user do name 'Admin User' admin_level 'super' @@ -156,4 +157,9 @@ FactoryGirl.define do public_body end end + factory :info_request_batch do + title "Example title" + user + body "Some text" + end end diff --git a/spec/mailers/info_request_batch_mailer.rb b/spec/mailers/info_request_batch_mailer.rb new file mode 100644 index 000000000..19791e163 --- /dev/null +++ b/spec/mailers/info_request_batch_mailer.rb @@ -0,0 +1,35 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe InfoRequestBatchMailer do + + describe 'when sending batch sent notification' do + + before do + @user = FactoryGirl.create(:user) + @info_request_batch = FactoryGirl.create(:info_request_batch) + @public_body = FactoryGirl.create(:public_body) + @unrequestable = [@public_body] + @mail = InfoRequestBatchMailer.batch_sent(@info_request_batch, @unrequestable, @user) + end + + it 'renders the subject' do + @mail.subject.should == 'Your batch request "Example title" has been sent' + end + + it 'renders the receiver email' do + @mail.to.should == [@user.email] + end + + it 'renders the sender email' do + @mail.from.should == ['postmaster@localhost'] + end + + it 'assigns @unrequestable' do + @mail.body.encoded.should match(@public_body.name) + end + + it 'assigns @url' do + @mail.body.encoded.should match("http://test.host/en/c/") + end + end +end diff --git a/spec/models/info_request_batch_spec.rb b/spec/models/info_request_batch_spec.rb new file mode 100644 index 000000000..53158ebe2 --- /dev/null +++ b/spec/models/info_request_batch_spec.rb @@ -0,0 +1,150 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe InfoRequestBatch, "when validating" do + + before do + @info_request_batch = FactoryGirl.build(:info_request_batch) + end + + it 'should require a user' do + @info_request_batch.user = nil + @info_request_batch.valid?.should be_false + @info_request_batch.errors.full_messages.should == ["User can't be blank"] + end + + it 'should require a title' do + @info_request_batch.title = nil + @info_request_batch.valid?.should be_false + @info_request_batch.errors.full_messages.should == ["Title can't be blank"] + end + + it 'should require a body' do + @info_request_batch.body = nil + @info_request_batch.valid?.should be_false + @info_request_batch.errors.full_messages.should == ["Body can't be blank"] + end + +end + +describe InfoRequestBatch, "when finding an existing batch" do + + before do + @first_body = FactoryGirl.create(:public_body) + @second_body = FactoryGirl.create(:public_body) + @info_request_batch = FactoryGirl.create(:info_request_batch, :title => 'Matched title', + :body => 'Matched body', + :public_bodies => [@first_body, + @second_body]) + end + + it 'should return a batch with the same user, title and body sent to one of the same public bodies' do + InfoRequestBatch.find_existing(@info_request_batch.user, + @info_request_batch.title, + @info_request_batch.body, + [@first_body]).should_not be_nil + end + + it 'should not return a batch with the same title and body sent to another public body' do + InfoRequestBatch.find_existing(@info_request_batch.user, + @info_request_batch.title, + @info_request_batch.body, + [FactoryGirl.create(:public_body)]).should be_nil + end + + it 'should not return a batch sent the same public bodies with a different title and body' do + InfoRequestBatch.find_existing(@info_request_batch.user, + 'Other title', + 'Other body', + [@first_body]).should be_nil + end + + it 'should not return a batch sent to one of the same public bodies with the same title and body by + a different user' do + InfoRequestBatch.find_existing(FactoryGirl.create(:user), + @info_request_batch.title, + @info_request_batch.body, + [@first_body]).should be_nil + end +end + +describe InfoRequestBatch, "when creating a batch", :focus => true do + + before do + @title = 'A test title' + @body = "Dear [Authority name],\nA message\nYours faithfully,\nRequester" + @first_public_body = FactoryGirl.create(:public_body) + @second_public_body = FactoryGirl.create(:public_body) + @user = FactoryGirl.create(:user) + @info_request_batch = InfoRequestBatch.create!({:title => @title, + :body => @body, + :public_bodies => [@first_public_body, + @second_public_body], + :user => @user}) + end + + it 'should substitute authority name for the placeholder in each request' do + unrequestable = @info_request_batch.create_batch! + [@first_public_body, @second_public_body].each do |public_body| + request = @info_request_batch.info_requests.detect do |info_request| + info_request.public_body == public_body + end + expected = "Dear #{public_body.name},\nA message\nYours faithfully,\nRequester" + request.outgoing_messages.first.body.should == expected + end + end + + it 'should send requests to requestable public bodies, and return a list of unrequestable ones' do + @first_public_body.stub(:is_requestable?).and_return(false) + unrequestable = @info_request_batch.create_batch! + unrequestable.should == [@first_public_body] + @info_request_batch.info_requests.size.should == 1 + request = @info_request_batch.info_requests.first + request.outgoing_messages.first.status.should == 'sent' + end + + it 'should set the sent_at value of the info request batch' do + @info_request_batch.create_batch! + @info_request_batch.sent_at.should_not be_nil + end + +end + +describe InfoRequestBatch, "when sending batches" do + + before do + @title = 'A test title' + @body = "Dear [Authority name],\nA message\nYours faithfully,\nRequester" + @first_public_body = FactoryGirl.create(:public_body) + @second_public_body = FactoryGirl.create(:public_body) + @user = FactoryGirl.create(:user) + @info_request_batch = InfoRequestBatch.create!({:title => @title, + :body => @body, + :public_bodies => [@first_public_body, + @second_public_body], + :user => @user}) + @sent_batch = InfoRequestBatch.create!({:title => @title, + :body => @body, + :public_bodies => [@first_public_body, + @second_public_body], + :user => @user, + :sent_at => Time.now}) + end + + it 'should send requests and notifications for only unsent batch requests' do + InfoRequestBatch.send_batches + ActionMailer::Base.deliveries.size.should == 3 + first_email = ActionMailer::Base.deliveries.first + first_email.to.should == [@first_public_body.request_email] + first_email.subject.should == 'Freedom of Information request - A test title' + + second_email = ActionMailer::Base.deliveries.second + second_email.to.should == [@second_public_body.request_email] + second_email.subject.should == 'Freedom of Information request - A test title' + + third_email = ActionMailer::Base.deliveries.third + third_email.to.should == [@user.email] + third_email.subject.should == 'Your batch request "A test title" has been sent' + end + +end + diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index ade75e2cc..9766f928f 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -46,6 +46,19 @@ describe InfoRequest do info_request.valid? info_request.errors[:title].should_not be_empty end + + it 'should require a public body id by default' do + info_request = InfoRequest.new + info_request.valid? + info_request.errors[:public_body_id].should_not be_empty + end + + it 'should not require a public body id if it is a batch request template' do + info_request = InfoRequest.new + info_request.is_batch_request_template = true + info_request.valid? + info_request.errors[:public_body_id].should be_empty + end end describe 'when generating a user name slug' do @@ -600,6 +613,12 @@ describe InfoRequest do @info_request.apply_censor_rules_to_text!(@text) end + it 'should not raise an error if the request is a batch request template' do + @info_request.stub!(:public_body).and_return(nil) + @info_request.is_batch_request_template = true + lambda{ @info_request.apply_censor_rules_to_text!(@text) }.should_not raise_error + end + end context 'when applying censor rules to binary files' do diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb index bb270ca16..a3e2d1c68 100644 --- a/spec/models/outgoing_message_spec.rb +++ b/spec/models/outgoing_message_spec.rb @@ -57,7 +57,8 @@ describe OutgoingMessage, " when making an outgoing message" do info_request = mock_model(InfoRequest, :public_body => public_body, :url_title => 'a_test_title', :title => 'A test title', - :apply_censor_rules_to_text! => nil) + :apply_censor_rules_to_text! => nil, + :is_batch_request_template? => false) outgoing_message = OutgoingMessage.new({ :status => 'ready', :message_type => 'followup', @@ -68,6 +69,15 @@ describe OutgoingMessage, " when making an outgoing message" do outgoing_message.body.should include(expected_text) end + context "when associated with a batch template request" do + + it 'should produce a salutation with a placeholder' do + @om.info_request.is_batch_request_template = true + @om.get_salutation.should == 'Dear [Authority name],' + end + end + + describe 'when asked if a user can view it' do before do @@ -166,7 +176,7 @@ describe OutgoingMessage, " when censoring data" do end end -describe OutgoingMessage, "when validating the format of the message body", :focus => true do +describe OutgoingMessage, "when validating the format of the message body" do it 'should handle a salutation with a bracket in it' do outgoing_message = FactoryGirl.build(:initial_request) diff --git a/spec/models/track_thing_spec.rb b/spec/models/track_thing_spec.rb index 86d3c0cda..1c582564b 100644 --- a/spec/models/track_thing_spec.rb +++ b/spec/models/track_thing_spec.rb @@ -39,7 +39,7 @@ describe TrackThing, "when tracking changes" do it "will find existing tracks which are the same" do track_thing = TrackThing.create_track_for_search_query('fancy dog') - found_track = TrackThing.find_by_existing_track(users(:silly_name_user), track_thing) + found_track = TrackThing.find_existing(users(:silly_name_user), track_thing) found_track.should == @track_thing end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index cbbf4b5ce..b6f48dad3 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -337,3 +337,34 @@ describe User, "when emails have bounced" do user.email_bounce_message.should == "The reason we think the email bounced (e.g. a bounce message)" end end + +describe User, "when calculating if a user has exceeded the request limit" do + + before do + @info_request = FactoryGirl.create(:info_request) + @user = @info_request.user + end + + it 'should return false if no request limit is set' do + AlaveteliConfiguration.stub!(:max_requests_per_user_per_day).and_return nil + @user.exceeded_limit?.should be_false + end + + it 'should return false if the user has not submitted more than the limit' do + AlaveteliConfiguration.stub!(:max_requests_per_user_per_day).and_return(2) + @user.exceeded_limit?.should be_false + end + + it 'should return true if the user has submitted more than the limit' do + AlaveteliConfiguration.stub!(:max_requests_per_user_per_day).and_return(0) + @user.exceeded_limit?.should be_true + end + + it 'should return false if the user is allowed to make batch requests' do + @user.can_make_batch_requests = true + AlaveteliConfiguration.stub!(:max_requests_per_user_per_day).and_return(0) + @user.exceeded_limit?.should be_false + end + + +end |