aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/info_request_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/info_request_spec.rb')
-rw-r--r--spec/models/info_request_spec.rb31
1 files changed, 30 insertions, 1 deletions
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 9b87f909e..f9ca44657 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -564,6 +564,26 @@ describe InfoRequest do
end
end
+ describe 'when generating json for the api' do
+
+ before do
+ @user = mock_model(User, :json_for_api => { :id => 20,
+ :url_name => 'alaveteli_user',
+ :name => 'Alaveteli User',
+ :ban_text => '',
+ :about_me => 'Hi' })
+ end
+
+ it 'should return full user info for an internal request' do
+ @info_request = InfoRequest.new(:user => @user)
+ @info_request.user_json_for_api.should == { :id => 20,
+ :url_name => 'alaveteli_user',
+ :name => 'Alaveteli User',
+ :ban_text => '',
+ :about_me => 'Hi' }
+ end
+ end
+
describe 'when working out a subject for a followup emails' do
it "should not be confused by an nil subject in the incoming message" do
@@ -575,6 +595,15 @@ describe InfoRequest do
subject.should match(/^Re: Freedom of Information request.*fancy dog/)
end
- end
+ it "should return a hash with the user's name for an external request" do
+ @info_request = InfoRequest.new(:external_url => 'http://www.example.com',
+ :external_user_name => 'External User')
+ @info_request.user_json_for_api.should == {:name => 'External User'}
+ end
+ it 'should return "Anonymous user" for an anonymous external user' do
+ @info_request = InfoRequest.new(:external_url => 'http://www.example.com')
+ @info_request.user_json_for_api.should == {:name => 'Anonymous user'}
+ end
+ end
end