aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/public_body_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/public_body_spec.rb')
-rw-r--r--spec/models/public_body_spec.rb92
1 files changed, 90 insertions, 2 deletions
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 7b55efda1..3d14127f4 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -1,4 +1,4 @@
-# encoding: UTF-8
+# -*- encoding : utf-8 -*-
# == Schema Information
#
# Table name: public_bodies
@@ -102,8 +102,44 @@ describe PublicBody do
end
end
end
-end
+ describe :set_api_key do
+
+ it 'generates and sets an API key' do
+ SecureRandom.stub(:base64).and_return('APIKEY')
+ body = PublicBody.new
+ body.set_api_key
+ expect(body.api_key).to eq('APIKEY')
+ end
+
+ it 'does not overwrite an existing API key' do
+ SecureRandom.stub(:base64).and_return('APIKEY')
+ body = PublicBody.new(:api_key => 'EXISTING')
+ body.set_api_key
+ expect(body.api_key).to eq('EXISTING')
+ end
+
+ end
+
+ describe :set_api_key! do
+
+ it 'generates and sets an API key' do
+ SecureRandom.stub(:base64).and_return('APIKEY')
+ body = PublicBody.new
+ body.set_api_key!
+ expect(body.api_key).to eq('APIKEY')
+ end
+
+ it 'overwrites an existing API key' do
+ SecureRandom.stub(:base64).and_return('APIKEY')
+ body = PublicBody.new(:api_key => 'EXISTING')
+ body.set_api_key!
+ expect(body.api_key).to eq('APIKEY')
+ end
+
+ end
+
+end
describe PublicBody, " using tags" do
before do
@@ -282,6 +318,31 @@ describe PublicBody, " when saving" do
pb.first_letter.should == 'Å'
end
+ it 'should save the first letter of a translation' do
+ existing = FactoryGirl.create(:public_body, :first_letter => 'T', :name => 'Test body')
+ I18n.with_locale(:es) { existing.update_attributes :name => 'Prueba body' }
+ PublicBody::Translation.
+ where(:public_body_id => existing.id, :locale => :es).
+ pluck('first_letter').first.should == 'P'
+ end
+
+ it 'should save the first letter of a translation, even when it is the same as the
+ first letter in the default locale' do
+ existing = FactoryGirl.create(:public_body, :first_letter => 'T', :name => 'Test body')
+ I18n.with_locale(:es) { existing.update_attributes :name => existing.name }
+ PublicBody::Translation.
+ where(:public_body_id => existing.id, :locale => :es).
+ pluck('first_letter').first.should == 'T'
+ end
+
+ it 'should create a url_name for a translation' do
+ existing = FactoryGirl.create(:public_body, :first_letter => 'T', :short_name => 'Test body')
+ I18n.with_locale(:es) do
+ existing.update_attributes :short_name => 'Prueba', :name => 'Prueba body'
+ existing.url_name.should == 'prueba'
+ end
+ end
+
it "should not save if the url_name is already taken" do
existing = FactoryGirl.create(:public_body)
pb = PublicBody.new(existing.attributes)
@@ -1237,6 +1298,33 @@ describe PublicBody do
end
+ describe :request_email do
+ context "when the email is set" do
+ subject(:public_body) { FactoryGirl.create(:public_body, :request_email => "request@example.com") }
+
+ it "should return the set email address" do
+ expect(public_body.request_email).to eq("request@example.com")
+ end
+
+ it "should return a different email address when overridden in configuration" do
+ AlaveteliConfiguration.stub!(:override_all_public_body_request_emails).and_return("tester@example.com")
+ expect(public_body.request_email).to eq("tester@example.com")
+ end
+ end
+
+ context "when no email is set" do
+ subject(:public_body) { FactoryGirl.create(:public_body, :request_email => "") }
+
+ it "should return a blank email address" do
+ expect(public_body.request_email).to be_blank
+ end
+
+ it "should still return a blank email address when overridden in configuration" do
+ AlaveteliConfiguration.stub!(:override_all_public_body_request_emails).and_return("tester@example.com")
+ expect(public_body.request_email).to be_blank
+ end
+ end
+ end
end
describe PublicBody::Translation do