diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/admin_public_body_controller_spec.rb | 5 | ||||
-rw-r--r-- | spec/integration/parameter_stripping_spec.rb | 24 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 63 |
3 files changed, 90 insertions, 2 deletions
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 1b960ccc3..f7336a6c7 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -129,7 +129,8 @@ describe AdminPublicBodyController, "when creating a public body" do :last_edit_comment => 'From test code', :translations_attributes => { 'es' => { :locale => 'es', - :name => 'Los Quango' } + :name => 'Los Quango', + :short_name => 'lq' } } } } end @@ -160,6 +161,8 @@ describe AdminPublicBodyController, "when creating a public body" do I18n.with_locale(:es) do expect(body.name).to eq('Los Quango') + expect(body.url_name).to eq('lq') + expect(body.first_letter).to eq('L') end end diff --git a/spec/integration/parameter_stripping_spec.rb b/spec/integration/parameter_stripping_spec.rb new file mode 100644 index 000000000..7e3c0adc2 --- /dev/null +++ b/spec/integration/parameter_stripping_spec.rb @@ -0,0 +1,24 @@ +# -*- encoding : utf-8 -*- +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe "When handling bad requests" do + + if RUBY_VERSION == '1.9.3' + + it 'should return a 404 for GET requests to a malformed request URL' do + get 'request/228%85' + response.status.should == 404 + end + + it 'should redirect a bad UTF-8 POST to a malformed attachment URL' do + info_request = FactoryGirl.create(:info_request_with_incoming_attachments) + incoming_message = info_request.incoming_messages.first + data = { :excerpt => "something\xA3\xA1" } + post "/en/request/#{info_request.id}/response/#{incoming_message.id}/attach/2/interesting.pdf/trackback", data + response.status.should == 303 + response.should redirect_to "/en/request/#{info_request.url_title}#incoming-#{incoming_message.id}" + end + + end + +end diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index d6abf7b5f..3d14127f4 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -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) |