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,13 +3,15 @@ require File.dirname(__FILE__) + '/../test_helper' | ||
3 | class OauthClientPluginTest < ActiveSupport::TestCase | 3 | class OauthClientPluginTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | - @plugin = OauthClientPlugin.new | 6 | + @plugin = OauthClientPlugin.new(self) |
7 | @params = {} | 7 | @params = {} |
8 | @plugin.stubs(:context).returns(self) | 8 | @plugin.stubs(:context).returns(self) |
9 | @environment = Environment.default | 9 | @environment = Environment.default |
10 | + @session = {} | ||
11 | + @request = mock | ||
10 | end | 12 | end |
11 | 13 | ||
12 | - attr_reader :params, :plugin, :environment | 14 | + attr_reader :params, :plugin, :environment, :session, :request |
13 | 15 | ||
14 | should 'has extra contents for login' do | 16 | should 'has extra contents for login' do |
15 | assert plugin.login_extra_contents | 17 | assert plugin.login_extra_contents |
@@ -19,33 +21,26 @@ class OauthClientPluginTest < ActiveSupport::TestCase | @@ -19,33 +21,26 @@ class OauthClientPluginTest < ActiveSupport::TestCase | ||
19 | assert_equal '', instance_eval(&plugin.signup_extra_contents) | 21 | assert_equal '', instance_eval(&plugin.signup_extra_contents) |
20 | end | 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 | expects(:render).with(:partial => 'account/oauth_signup').once | 26 | expects(:render).with(:partial => 'account/oauth_signup').once |
25 | instance_eval(&plugin.signup_extra_contents) | 27 | instance_eval(&plugin.signup_extra_contents) |
26 | end | 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 | should 'define before filter for account controller' do | 30 | should 'define before filter for account controller' do |
36 | assert plugin.account_controller_filters | 31 | assert plugin.account_controller_filters |
37 | end | 32 | end |
38 | 33 | ||
39 | should 'raise error if oauth email was changed' do | 34 | should 'raise error if oauth email was changed' do |
40 | - request = mock | ||
41 | - stubs(:request).returns(request) | ||
42 | request.expects(:post?).returns(true) | 35 | request.expects(:post?).returns(true) |
43 | 36 | ||
44 | oauth_data = mock | 37 | oauth_data = mock |
45 | info = mock | 38 | info = mock |
46 | oauth_data.stubs(:info).returns(info) | 39 | oauth_data.stubs(:info).returns(info) |
40 | + oauth_data.stubs(:uid).returns('uid') | ||
41 | + oauth_data.stubs(:provider).returns('provider') | ||
47 | info.stubs(:email).returns('test@example.com') | 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 | params[:user] = {:email => 'test2@example.com'} | 45 | params[:user] = {:email => 'test2@example.com'} |
51 | assert_raises RuntimeError do | 46 | assert_raises RuntimeError do |
@@ -54,32 +49,33 @@ class OauthClientPluginTest < ActiveSupport::TestCase | @@ -54,32 +49,33 @@ class OauthClientPluginTest < ActiveSupport::TestCase | ||
54 | end | 49 | end |
55 | 50 | ||
56 | should 'do not raise error if oauth email was not changed' do | 51 | should 'do not raise error if oauth email was not changed' do |
57 | - request = mock | ||
58 | - stubs(:request).returns(request) | ||
59 | request.expects(:post?).returns(true) | 52 | request.expects(:post?).returns(true) |
60 | 53 | ||
61 | oauth_data = mock | 54 | oauth_data = mock |
62 | info = mock | 55 | info = mock |
63 | oauth_data.stubs(:info).returns(info) | 56 | oauth_data.stubs(:info).returns(info) |
57 | + oauth_data.stubs(:uid).returns('uid') | ||
58 | + oauth_data.stubs(:provider).returns('provider') | ||
64 | info.stubs(:email).returns('test@example.com') | 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 | params[:user] = {:email => 'test@example.com'} | 62 | params[:user] = {:email => 'test@example.com'} |
68 | instance_eval(&plugin.account_controller_filters[:block]) | 63 | instance_eval(&plugin.account_controller_filters[:block]) |
69 | end | 64 | end |
70 | 65 | ||
71 | should 'do not raise error if oauth session is not set' do | 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 | instance_eval(&plugin.account_controller_filters[:block]) | 67 | instance_eval(&plugin.account_controller_filters[:block]) |
77 | end | 68 | end |
78 | 69 | ||
79 | should 'do not raise error if it is not a post' do | 70 | should 'do not raise error if it is not a post' do |
80 | - request = mock | ||
81 | - stubs(:request).returns(request) | ||
82 | request.expects(:post?).returns(false) | 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 | instance_eval(&plugin.account_controller_filters[:block]) | 79 | instance_eval(&plugin.account_controller_filters[:block]) |
84 | end | 80 | end |
85 | 81 |