diff --git a/spec/models/authorisation_spec.rb b/spec/models/authorisation_spec.rb index e6b4fd02..218ed98c 100644 --- a/spec/models/authorisation_spec.rb +++ b/spec/models/authorisation_spec.rb @@ -17,7 +17,7 @@ after(:each) { authorisation.run_callbacks(:initialize) } it "runs setup" do - authorisation.should_receive(:setup) + authorisation.should_receive(:setup) end end end @@ -27,14 +27,69 @@ end describe "#profile" do - pending + context 'when provider is not google_oauth2' do + it 'returns nil' do + authorisation.profile.should be_nil + end + end + context 'when provider is google_oauth2' do + it 'returns profile' do + authorisation.provider = "google_oauth2" + authorisation.profile.should == $google_plus.person + end + end end describe "#mention" do - pending + url = "http://www.example.com/" + + context 'when provider is google_oauth2' do + it 'returns true' do + authorisation.provider = "google_oauth2" + authorisation.mention(url).should be_true + end + end + + context 'when provider is not google_oauth2' do + it 'returns nil' do + authorisation.provider = "linkedin_oauth" + authorisation.mention(url).should be_nil + end + end end - describe "self.find_or_create_from_auth_hash" do - pending + describe ".find_or_create_from_auth_hash" do + let(:auth_hash) { + { 'provider' => "photographre", + 'user_id' => 1, + 'uid' => '1', + 'info' => {:key => 'Rob is cool'}, + 'credentials' => {:key => 'true'}, + 'extra' => {:key => 'is secret'} + } + } + + context 'when there is a persistent authorisation' do + it 'it updates and returns auth' do + auth = Authorisation.find_or_create_from_auth_hash(auth_hash) + auth.update_attributes(auth_hash) + auth.provider.should == "photographre" + auth.uid.should == "1" + auth.info.should == {:key => 'Rob is cool'} + auth.credentials.should == {:key => 'true'} + auth.extra.should == {:key => 'is secret'} + end + end + + context 'when there is no persistent authorisation' do + it 'it finds or creates, and returns auth' do + auth2 = Authorisation.find_or_create_from_auth_hash(auth_hash) + auth2.provider.should == "photographre" + auth2.uid.should == "1" + auth2.info.should be_nil + auth2.credentials.should be_nil + auth2.extra.should be_nil + end + end end end