diff options
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/info_request_spec.rb | 34 | ||||
-rw-r--r-- | spec/models/request_mailer_spec.rb | 44 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 18 |
3 files changed, 96 insertions, 0 deletions
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index d0b0e0e32..ba80256ab 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -2,6 +2,40 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe InfoRequest do + describe "guessing a request from an email" do + fixtures :info_requests, :public_bodies, :incoming_messages, :raw_emails + + before do + @im = incoming_messages(:useless_incoming_message) + load_raw_emails_data(raw_emails) + end + + it 'should compute a hash' do + @info_request = InfoRequest.new(:title => "testing", + :public_body => public_bodies(:geraldine_public_body), + :user_id => 1) + @info_request.save! + @info_request.idhash.should_not == nil + end + + it 'should find a request based on an email with an intact id and a broken hash' do + ir = info_requests(:fancy_dog_request) + id = ir.id + @im.mail.to = "request-#{id}-asdfg@example.com" + guessed = InfoRequest.guess_by_incoming_email(@im) + guessed[0].idhash.should == ir.idhash + end + + it 'should find a request based on an email with a broken id and an intact hash' do + ir = info_requests(:fancy_dog_request) + idhash = ir.idhash + @im.mail.to = "request-123ab-#{idhash}@example.com" + guessed = InfoRequest.guess_by_incoming_email(@im) + guessed[0].id.should == ir.id + end + + end + describe "making up the URL title" do before do @info_request = InfoRequest.new diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb index a5f59b9bf..fbe22c220 100644 --- a/spec/models/request_mailer_spec.rb +++ b/spec/models/request_mailer_spec.rb @@ -27,7 +27,49 @@ describe RequestMailer, " when receiving incoming mail" do receive_incoming_mail('incoming-request-plain.email', 'dummy@localhost') ir.incoming_messages.size.should == 1 InfoRequest.holding_pen_request.incoming_messages.size.should == 1 + last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.get_last_event + last_event.params[:rejected_reason].should == "Could not identify the request from the email address" + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.to.should == [ MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') ] + deliveries.clear + end + it "should store mail in holding pen and send to admin when the from email is empty and only authorites can reply" do + ir = info_requests(:fancy_dog_request) + ir.allow_new_responses_from = 'authority_only' + ir.handle_rejected_responses = 'holding_pen' + ir.save! + ir.incoming_messages.size.should == 1 + InfoRequest.holding_pen_request.incoming_messages.size.should == 0 + receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "") + ir.incoming_messages.size.should == 1 + InfoRequest.holding_pen_request.incoming_messages.size.should == 1 + last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.get_last_event + last_event.params[:rejected_reason].should =~ /there is no "From" address/ + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.to.should == [ MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') ] + deliveries.clear + end + + it "should store mail in holding pen and send to admin when the from email is unknown and only authorites can reply" do + ir = info_requests(:fancy_dog_request) + ir.allow_new_responses_from = 'authority_only' + ir.handle_rejected_responses = 'holding_pen' + ir.save! + ir.incoming_messages.size.should == 1 + InfoRequest.holding_pen_request.incoming_messages.size.should == 0 + receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "frob@nowhere.com") + ir.incoming_messages.size.should == 1 + InfoRequest.holding_pen_request.incoming_messages.size.should == 1 + last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.get_last_event + last_event.params[:rejected_reason].should =~ /Only the authority can reply/ + deliveries = ActionMailer::Base.deliveries deliveries.size.should == 1 mail = deliveries[0] @@ -108,6 +150,8 @@ describe RequestMailer, " when receiving incoming mail" do receive_incoming_mail('incoming-request-plain.email', ir.incoming_email) ir.incoming_messages.size.should == 1 InfoRequest.holding_pen_request.incoming_messages.size.should == 1 # arrives in holding pen + last_event = InfoRequest.holding_pen_request.incoming_messages[0].info_request.get_last_event + last_event.params[:rejected_reason].should =~ /allow new responses from nobody/ # should be a message to admin regarding holding pen deliveries = ActionMailer::Base.deliveries diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index c913ce3a8..ee6916ffc 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -15,6 +15,24 @@ describe User, "making up the URL name" do @user.url_name.should == 'user' end end + + +describe User, "showing the name" do + before do + @user = User.new + @user.name = 'Some Name ' + end + + it 'should strip whitespace' do + @user.name.should == 'Some Name' + end + + it 'should show if user has been banned' do + @user.ban_text = "Naughty user" + @user.name.should == 'Some Name (Banned)' + end + +end describe User, " when authenticating" do before do |