|
1 |
| -shared_examples_for 'rails_3_oauth_model' do |
| 1 | +shared_examples_for "rails_3_oauth_model" do |
2 | 2 | # ----------------- PLUGIN CONFIGURATION -----------------------
|
3 | 3 |
|
4 | 4 | let(:external_user) { create_new_external_user :twitter }
|
5 | 5 |
|
6 |
| - describe 'loaded plugin configuration' do |
| 6 | + describe "loaded plugin configuration" do |
7 | 7 | before(:all) do
|
8 | 8 | Authentication.sorcery_adapter.delete_all
|
9 | 9 | User.sorcery_adapter.delete_all
|
10 | 10 |
|
11 | 11 | sorcery_reload!([:external])
|
12 | 12 | sorcery_controller_property_set(:external_providers, [:twitter])
|
13 | 13 | sorcery_model_property_set(:authentications_class, Authentication)
|
14 |
| - sorcery_controller_external_property_set(:twitter, :key, 'eYVNBjBDi33aa9GkA3w') |
15 |
| - sorcery_controller_external_property_set(:twitter, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8') |
16 |
| - sorcery_controller_external_property_set(:twitter, :callback_url, 'http://blabla.com') |
| 14 | + sorcery_controller_external_property_set(:twitter, :key, "eYVNBjBDi33aa9GkA3w") |
| 15 | + sorcery_controller_external_property_set(:twitter, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8") |
| 16 | + sorcery_controller_external_property_set(:twitter, :callback_url, "http://blabla.com") |
17 | 17 | end
|
18 | 18 |
|
19 | 19 | it "responds to 'load_from_provider'" do
|
|
29 | 29 | external_user
|
30 | 30 | expect(User.load_from_provider(:twitter, 980_342)).to be_nil
|
31 | 31 | end
|
| 32 | + |
| 33 | + describe "#add_provider_to_user" do |
| 34 | + let!(:user) { create_new_user } |
| 35 | + |
| 36 | + subject { user.add_provider_to_user(:twitter, 123) } |
| 37 | + |
| 38 | + context "when a provider is successfully added" do |
| 39 | + it "returns an instance of user" do |
| 40 | + user = subject |
| 41 | + expect(user).to be_kind_of(User) |
| 42 | + expect(user.authentications.count).to eq 1 |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + context "when a provider already exists" do |
| 47 | + let(:user) { create_new_external_user :twitter } |
| 48 | + |
| 49 | + it "does not create a new authentication and returns false" do |
| 50 | + expect { subject }.not_to change(Authentication, :count) |
| 51 | + expect(subject).to be false |
| 52 | + end |
| 53 | + end |
| 54 | + end |
32 | 55 | end
|
33 | 56 | end
|
0 commit comments