Commit d60663d39a6530c6cfce926884582524a96c6d77
1 parent
7b92b4e3
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
oauth_client: fix tests
Showing
1 changed file
with
19 additions
and
23 deletions
Show diff stats
plugins/oauth_client/test/unit/oauth_client_plugin_test.rb
... | ... | @@ -3,13 +3,15 @@ require File.dirname(__FILE__) + '/../test_helper' |
3 | 3 | class OauthClientPluginTest < ActiveSupport::TestCase |
4 | 4 | |
5 | 5 | def setup |
6 | - @plugin = OauthClientPlugin.new | |
6 | + @plugin = OauthClientPlugin.new(self) | |
7 | 7 | @params = {} |
8 | 8 | @plugin.stubs(:context).returns(self) |
9 | 9 | @environment = Environment.default |
10 | + @session = {} | |
11 | + @request = mock | |
10 | 12 | end |
11 | 13 | |
12 | - attr_reader :params, :plugin, :environment | |
14 | + attr_reader :params, :plugin, :environment, :session, :request | |
13 | 15 | |
14 | 16 | should 'has extra contents for login' do |
15 | 17 | assert plugin.login_extra_contents |
... | ... | @@ -19,33 +21,26 @@ class OauthClientPluginTest < ActiveSupport::TestCase |
19 | 21 | assert_equal '', instance_eval(&plugin.signup_extra_contents) |
20 | 22 | end |
21 | 23 | |
22 | - should 'has signup extra contents if there is enabled providers' do | |
23 | - params[:user] = {:oauth_providers => [:provider]} | |
24 | + should 'has signup extra contents if oauth_data exists in session' do | |
25 | + session[:oauth_data] = {:oauth => 'test'} | |
24 | 26 | expects(:render).with(:partial => 'account/oauth_signup').once |
25 | 27 | instance_eval(&plugin.signup_extra_contents) |
26 | 28 | end |
27 | 29 | |
28 | - should 'list enabled providers' do | |
29 | - settings = Noosfero::Plugin::Settings.new(environment, OauthClientPlugin) | |
30 | - providers = {:test => {:enabled => true}, :test2 => {:enabled => false}} | |
31 | - settings.set_setting(:providers, providers) | |
32 | - assert_equal({:test => {:enabled => true}}, plugin.enabled_providers) | |
33 | - end | |
34 | - | |
35 | 30 | should 'define before filter for account controller' do |
36 | 31 | assert plugin.account_controller_filters |
37 | 32 | end |
38 | 33 | |
39 | 34 | should 'raise error if oauth email was changed' do |
40 | - request = mock | |
41 | - stubs(:request).returns(request) | |
42 | 35 | request.expects(:post?).returns(true) |
43 | 36 | |
44 | 37 | oauth_data = mock |
45 | 38 | info = mock |
46 | 39 | oauth_data.stubs(:info).returns(info) |
40 | + oauth_data.stubs(:uid).returns('uid') | |
41 | + oauth_data.stubs(:provider).returns('provider') | |
47 | 42 | info.stubs(:email).returns('test@example.com') |
48 | - stubs(:session).returns({:oauth_data => oauth_data}) | |
43 | + session[:oauth_data] = oauth_data | |
49 | 44 | |
50 | 45 | params[:user] = {:email => 'test2@example.com'} |
51 | 46 | assert_raises RuntimeError do |
... | ... | @@ -54,32 +49,33 @@ class OauthClientPluginTest < ActiveSupport::TestCase |
54 | 49 | end |
55 | 50 | |
56 | 51 | should 'do not raise error if oauth email was not changed' do |
57 | - request = mock | |
58 | - stubs(:request).returns(request) | |
59 | 52 | request.expects(:post?).returns(true) |
60 | 53 | |
61 | 54 | oauth_data = mock |
62 | 55 | info = mock |
63 | 56 | oauth_data.stubs(:info).returns(info) |
57 | + oauth_data.stubs(:uid).returns('uid') | |
58 | + oauth_data.stubs(:provider).returns('provider') | |
64 | 59 | info.stubs(:email).returns('test@example.com') |
65 | - stubs(:session).returns({:oauth_data => oauth_data}) | |
60 | + session[:oauth_data] = oauth_data | |
66 | 61 | |
67 | 62 | params[:user] = {:email => 'test@example.com'} |
68 | 63 | instance_eval(&plugin.account_controller_filters[:block]) |
69 | 64 | end |
70 | 65 | |
71 | 66 | should 'do not raise error if oauth session is not set' do |
72 | - request = mock | |
73 | - stubs(:request).returns(request) | |
74 | - request.expects(:post?).returns(true) | |
75 | - stubs(:session).returns({}) | |
76 | 67 | instance_eval(&plugin.account_controller_filters[:block]) |
77 | 68 | end |
78 | 69 | |
79 | 70 | should 'do not raise error if it is not a post' do |
80 | - request = mock | |
81 | - stubs(:request).returns(request) | |
82 | 71 | request.expects(:post?).returns(false) |
72 | + params[:user] = {:email => 'test2@example.com'} | |
73 | + | |
74 | + oauth_data = mock | |
75 | + oauth_data.stubs(:uid).returns('uid') | |
76 | + oauth_data.stubs(:provider).returns('provider') | |
77 | + | |
78 | + session[:oauth_data] = oauth_data | |
83 | 79 | instance_eval(&plugin.account_controller_filters[:block]) |
84 | 80 | end |
85 | 81 | ... | ... |