diff options
author | Gareth Rees <gareth@mysociety.org> | 2015-06-03 17:36:38 +0100 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2015-06-15 16:11:12 +0100 |
commit | dbb0562bb1d1334188629c93252f5d45e6a8d6f8 (patch) | |
tree | d61f11b55401c77a6c2c20e1c4c80eff1d5b6dfb /spec/models | |
parent | ebe263d4791ef5e8efaac505f9d7df24c5538a3a (diff) |
Prevent PublicBody#set_api_key call if unrequired
Don't call the method unless we need to. Adds #set_api_key! to set a new
API key even if there's an existing one.
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/public_body_spec.rb | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index ca94c59a8..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 |