/
controller_oauth_shared_examples.rb
55 lines (48 loc) · 2.21 KB
/
controller_oauth_shared_examples.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
shared_examples_for "oauth_controller" do
describe "using 'create_from'" do
before(:each) do
stub_all_oauth_requests!
User.delete_all
Authentication.delete_all
end
it "should create a new user" do
sorcery_model_property_set(:authentications_class, Authentication)
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "screen_name"})
lambda do
get :test_create_from_provider, :provider => "twitter"
end.should change(User, :count).by(1)
User.first.username.should == "nbenari"
end
it "should support nested attributes" do
sorcery_model_property_set(:authentications_class, Authentication)
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "status/text"})
lambda do
get :test_create_from_provider, :provider => "twitter"
end.should change(User, :count).by(1)
User.first.username.should == "coming soon to sorcery gem: twitter and facebook authentication support."
end
it "should not crash on missing nested attributes" do
sorcery_model_property_set(:authentications_class, Authentication)
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "status/text", :created_at => "does/not/exist"})
lambda do
get :test_create_from_provider, :provider => "twitter"
end.should change(User, :count).by(1)
User.first.username.should == "coming soon to sorcery gem: twitter and facebook authentication support."
User.first.created_at.should_not be_nil
end
describe "with a block" do
before(:each) do
user = User.new(:username => 'nbenari')
user.save!(:validate => false)
user.authentications.create(:provider => 'github', :uid => '456')
end
it "should not create user" do
sorcery_model_property_set(:authentications_class, Authentication)
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "screen_name"})
lambda do
get :test_create_from_provider_with_block, :provider => "twitter"
end.should_not change(User, :count)
end
end
end
end