reflex 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +24 -0
- data/LICENSE +20 -0
- data/README.rdoc +193 -0
- data/Rakefile +146 -0
- data/VERSION +1 -0
- data/cucumber.yml +7 -0
- data/features/connect_to_provider.feature +18 -0
- data/features/social_authentication.feature +50 -0
- data/features/step_definitions/reflex_steps.rb +93 -0
- data/features/step_definitions/web_steps.rb +192 -0
- data/features/support/env.rb +57 -0
- data/features/support/mocha.rb +16 -0
- data/features/support/mock_controller/oauth_authorize.html.erb +15 -0
- data/features/support/mocks.rb +21 -0
- data/features/support/paths.rb +39 -0
- data/features/support/rails_root/.gitignore +8 -0
- data/features/support/rails_root/Rakefile +10 -0
- data/features/support/rails_root/app/controllers/application_controller.rb +20 -0
- data/features/support/rails_root/app/controllers/user_sessions_controller.rb +24 -0
- data/features/support/rails_root/app/controllers/users_controller.rb +46 -0
- data/features/support/rails_root/app/helpers/application_helper.rb +3 -0
- data/features/support/rails_root/app/helpers/user_sessions_helper.rb +2 -0
- data/features/support/rails_root/app/helpers/users_helper.rb +2 -0
- data/features/support/rails_root/app/models/user.rb +7 -0
- data/features/support/rails_root/app/models/user_session.rb +2 -0
- data/features/support/rails_root/app/views/layouts/application.html.erb +23 -0
- data/features/support/rails_root/app/views/user_sessions/new.html.erb +23 -0
- data/features/support/rails_root/app/views/users/_form.html.erb +31 -0
- data/features/support/rails_root/app/views/users/_user.html.erb +1 -0
- data/features/support/rails_root/app/views/users/edit.html.erb +2 -0
- data/features/support/rails_root/app/views/users/index.html.erb +8 -0
- data/features/support/rails_root/app/views/users/new.html.erb +2 -0
- data/features/support/rails_root/app/views/users/show.html.erb +20 -0
- data/features/support/rails_root/config/boot.rb +110 -0
- data/features/support/rails_root/config/database.yml +9 -0
- data/features/support/rails_root/config/environment.rb +22 -0
- data/features/support/rails_root/config/environments/development.rb +0 -0
- data/features/support/rails_root/config/environments/test.rb +0 -0
- data/features/support/rails_root/config/initializers/backtrace_silencers.rb +7 -0
- data/features/support/rails_root/config/initializers/inflections.rb +10 -0
- data/features/support/rails_root/config/initializers/mime_types.rb +5 -0
- data/features/support/rails_root/config/initializers/new_rails_defaults.rb +21 -0
- data/features/support/rails_root/config/initializers/session_store.rb +15 -0
- data/features/support/rails_root/config/routes.rb +9 -0
- data/features/support/rails_root/db/migrate/001_create_users.rb +16 -0
- data/features/support/rails_root/db/migrate/002_create_reflex_connections.rb +17 -0
- data/features/support/rails_root/db/schema.rb +35 -0
- data/features/support/rails_root/vendor/plugins/reflex/rails/init.rb +1 -0
- data/features/traditional_registration_and_authentication.feature +39 -0
- data/init.rb +5 -0
- data/lib/reflex/authlogic/account.rb +55 -0
- data/lib/reflex/authlogic/acts_as_authentic.rb +19 -0
- data/lib/reflex/authlogic/authentication_process.rb +40 -0
- data/lib/reflex/authlogic/callback_filter.rb +26 -0
- data/lib/reflex/authlogic/connectable.rb +87 -0
- data/lib/reflex/authlogic/connection.rb +18 -0
- data/lib/reflex/authlogic/session.rb +84 -0
- data/lib/reflex/base.rb +37 -0
- data/lib/reflex/configuration.rb +38 -0
- data/lib/reflex/oauth_server.rb +47 -0
- data/lib/reflex/system.rb +25 -0
- data/lib/reflex.rb +14 -0
- data/rails/init.rb +22 -0
- data/rails_generators/reflex_connection_migration/reflex_connection_migration_generator.rb +12 -0
- data/rails_generators/reflex_connection_migration/templates/create_reflex_connections.rb +17 -0
- data/reflex.gemspec +164 -0
- data/spec/fakeweb/OAuthServer.getProviders +5 -0
- data/spec/fakeweb/OAuthServer.sessionGetProfile +5 -0
- data/spec/fakeweb/OAuthServer.tokenAccess +4 -0
- data/spec/fakeweb/OAuthServer.tokenRequest +5 -0
- data/spec/fakeweb/OAuthServer.tokenSetUserId +5 -0
- data/spec/fakeweb/OAuthServer.userGetProfile +5 -0
- data/spec/fakeweb/OAuthServer.userGetProviders +4 -0
- data/spec/fakeweb/OAuthServer.userRemoveProvider +5 -0
- data/spec/fakeweb/System.listMethods +5 -0
- data/spec/fakeweb/System.methodDescription +5 -0
- data/spec/fakeweb/System.methodSignature +5 -0
- data/spec/reflex/authlogic/connection_spec.rb +22 -0
- data/spec/reflex/base_spec.rb +29 -0
- data/spec/reflex/configuration_spec.rb +71 -0
- data/spec/reflex/oauth_server_spec.rb +219 -0
- data/spec/reflex/system_spec.rb +83 -0
- data/spec/reflex_spec.rb +5 -0
- data/spec/schema.rb +15 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +66 -0
- metadata +294 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..') + '/spec_helper')
|
2
|
+
|
3
|
+
describe Reflex::Configuration do
|
4
|
+
include ReflexSpecHelper
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@configuration = Reflex::Configuration.instance
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "Singleton" do
|
11
|
+
it "should not allow instantiation" do
|
12
|
+
lambda { Reflex::Configuration.new }.should raise_error(NoMethodError)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have 1 global instance" do
|
16
|
+
Reflex::Configuration.instance.should == @configuration
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "Reflex#configure" do
|
21
|
+
before(:each) do
|
22
|
+
Reflex.configure(:key => "key", :secret => "secret", :endpoint => "http://social.react.com/XmlRpc_v2/")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have a key" do
|
26
|
+
@configuration.key.should == "key"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have a secret" do
|
30
|
+
@configuration.secret.should == "secret"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have an endpoint" do
|
34
|
+
@configuration.endpoint.should == "http://social.react.com/XmlRpc_v2/"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have a hostname" do
|
38
|
+
@configuration.hostname.should == "social.react.com"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should have a path" do
|
42
|
+
@configuration.path.should == "/XmlRpc_v2/"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should have a port" do
|
46
|
+
@configuration.port.should == 80
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "endpoint changes" do
|
50
|
+
before(:each) do
|
51
|
+
Reflex.configure(:endpoint => "http://www.example.com:8080/API/")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should have a changed URL" do
|
55
|
+
@configuration.endpoint.should == "http://www.example.com:8080/API/"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should have a changed hostname" do
|
59
|
+
@configuration.hostname.should == "www.example.com"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should have a changed path" do
|
63
|
+
@configuration.path.should == "/API/"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should have a changed port" do
|
67
|
+
@configuration.port.should == 8080
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,219 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..') + '/spec_helper')
|
2
|
+
require 'fakeweb'
|
3
|
+
|
4
|
+
describe Reflex::OAuthServer do
|
5
|
+
include ReflexSpecHelper
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
Reflex.configure(:endpoint => 'http://social.react.com/XmlRpc_v2/')
|
9
|
+
FakeWeb.allow_net_connect = false
|
10
|
+
FakeWeb.clean_registry
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'get_providers' do
|
14
|
+
it 'should call OAuthServer.getProviders securely' do
|
15
|
+
Reflex::OAuthServer.expects(:call!).with('OAuthServer.getProviders')
|
16
|
+
Reflex::OAuthServer.get_providers
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'response' do
|
20
|
+
before(:each) do
|
21
|
+
FakeWeb.register_uri(:post, 'http://social.react.com/XmlRpc_v2/', :response => fake_response('OAuthServer.getProviders'))
|
22
|
+
@response = Reflex::OAuthServer.get_providers
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should be an array' do
|
26
|
+
@response.should be_an_instance_of(Array)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should include "Twitter"' do
|
30
|
+
@response.should include('Twitter')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'token_request' do
|
36
|
+
before(:each) do
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should call OAuthServer.tokenRequest securely' do
|
40
|
+
Reflex::OAuthServer.expects(:call!).with('OAuthServer.tokenRequest', 'Twitter')
|
41
|
+
Reflex::OAuthServer.token_request('Twitter')
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'response' do
|
45
|
+
before(:each) do
|
46
|
+
FakeWeb.register_uri(:post, 'http://social.react.com/XmlRpc_v2/', :response => fake_response('OAuthServer.tokenRequest'))
|
47
|
+
@response = Reflex::OAuthServer.token_request('Twitter')
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should be a hash' do
|
51
|
+
@response.should be_an_instance_of(Hash)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should include a redirectUrl' do
|
55
|
+
@response['redirectUrl'].should =~ /twitter\.com\/oauth/
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should include a reactOAuthSession' do
|
59
|
+
@response['reactOAuthSession'].should == 'FILTERED'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'token_access' do
|
65
|
+
it 'should call OAuthServer.tokenAccess securely' do
|
66
|
+
Reflex::OAuthServer.expects(:call!).with('OAuthServer.tokenAccess', { 'oauth_token' => 'FILTERED', 'oauth_verifier' => 'FILTERED', 'ReactOAuthSession' => 'FILTERED' })
|
67
|
+
Reflex::OAuthServer.token_access({ 'oauth_token' => 'FILTERED', 'oauth_verifier' => 'FILTERED', 'ReactOAuthSession' => 'FILTERED' })
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'response' do
|
71
|
+
before(:each) do
|
72
|
+
FakeWeb.register_uri(:post, 'http://social.react.com/XmlRpc_v2/', :response => fake_response('OAuthServer.tokenAccess'))
|
73
|
+
@response = Reflex::OAuthServer.token_access({ 'oauth_token' => 'FILTERED', 'oauth_verifier' => 'FILTERED', 'ReactOAuthSession' => 'FILTERED' })
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should be a hash' do
|
77
|
+
@response.should be_an_instance_of(Hash)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should include the connected provider' do
|
81
|
+
@response['connectedWithProvider'].should == 'Twitter'
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should include the application user ID' do
|
85
|
+
@response['applicationUserId'].should == '1'
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should include the react OAuth Session' do
|
89
|
+
@response['reactOAuthSession'].should == 'FILTERED'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'token_set_user_id' do
|
95
|
+
it 'should call OAuthServer.tokenSetUserId securely' do
|
96
|
+
Reflex::OAuthServer.expects(:call!).with('OAuthServer.tokenSetUserId', 1, 'FILTERED')
|
97
|
+
Reflex::OAuthServer.token_set_user_id(1, 'FILTERED')
|
98
|
+
end
|
99
|
+
|
100
|
+
describe 'response' do
|
101
|
+
before(:each) do
|
102
|
+
FakeWeb.register_uri(:post, 'http://social.react.com/XmlRpc_v2/', :response => fake_response('OAuthServer.tokenSetUserId'))
|
103
|
+
@response = Reflex::OAuthServer.token_set_user_id(1, 'FILTERED')
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should be a hash' do
|
107
|
+
@response.should be_an_instance_of(Hash)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should include the application user ID' do
|
111
|
+
@response['applicationUserId'].should == '1'
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should include the connected provider' do
|
115
|
+
@response['connectedWithProvider'].should == 'Twitter'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'user_get_providers' do
|
121
|
+
it 'should call OAuthServer.user_get_providers securely' do
|
122
|
+
Reflex::OAuthServer.expects(:call!).with('OAuthServer.userGetProviders', 1)
|
123
|
+
Reflex::OAuthServer.user_get_providers(1)
|
124
|
+
end
|
125
|
+
|
126
|
+
describe 'response' do
|
127
|
+
before(:each) do
|
128
|
+
FakeWeb.register_uri(:post, 'http://social.react.com/XmlRpc_v2/', :response => fake_response('OAuthServer.userGetProviders'))
|
129
|
+
@response = Reflex::OAuthServer.user_get_providers(1)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should be a hash' do
|
133
|
+
@response.should be_an_instance_of(Hash)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should include the connected providers' do
|
137
|
+
@response['connectedWithProviders'].should == ['Facebook', 'Twitter']
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe 'user_remove_provider' do
|
143
|
+
it 'should call OAuthServer.user_remove_provider securely' do
|
144
|
+
Reflex::OAuthServer.expects(:call!).with('OAuthServer.userRemoveProvider', 1, 'Twitter')
|
145
|
+
Reflex::OAuthServer.user_remove_provider(1, 'Twitter')
|
146
|
+
end
|
147
|
+
|
148
|
+
describe 'response' do
|
149
|
+
before(:each) do
|
150
|
+
FakeWeb.register_uri(:post, 'http://social.react.com/XmlRpc_v2/', :response => fake_response('OAuthServer.userRemoveProvider'))
|
151
|
+
@response = Reflex::OAuthServer.user_remove_provider(1, 'Twitter')
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should be true' do
|
155
|
+
@response.should be_true
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe 'user_get_profile' do
|
161
|
+
it 'should call OAuthServer.userGetProfile securely' do
|
162
|
+
Reflex::OAuthServer.expects(:call!).with('OAuthServer.userGetProfile', 1, 'Twitter')
|
163
|
+
Reflex::OAuthServer.user_get_profile(1, 'Twitter')
|
164
|
+
end
|
165
|
+
|
166
|
+
describe 'response' do
|
167
|
+
before(:each) do
|
168
|
+
FakeWeb.register_uri(:post, 'http://social.react.com/XmlRpc_v2/', :response => fake_response('OAuthServer.userGetProfile'))
|
169
|
+
@response = Reflex::OAuthServer.user_get_profile(1, 'Twitter')
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should be a hash' do
|
173
|
+
@response.should be_an_instance_of(Hash)
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should include the real name' do
|
177
|
+
@response['real_name'].should == 'Barney Stinson'
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'should include the user name' do
|
181
|
+
@response['user_name'].should == 'barney'
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should include a profile picture' do
|
185
|
+
@response['profile_picture'].should == 'http://awesome.com/barney.jpg'
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe 'session_get_profile' do
|
191
|
+
it 'should call OAuthServer.sessionGetProfile securely' do
|
192
|
+
Reflex::OAuthServer.expects(:call!).with('OAuthServer.sessionGetProfile', 'FILTERED')
|
193
|
+
Reflex::OAuthServer.session_get_profile('FILTERED')
|
194
|
+
end
|
195
|
+
|
196
|
+
describe 'response' do
|
197
|
+
before(:each) do
|
198
|
+
FakeWeb.register_uri(:post, 'http://social.react.com/XmlRpc_v2/', :response => fake_response('OAuthServer.sessionGetProfile'))
|
199
|
+
@response = Reflex::OAuthServer.session_get_profile('FILTERED')
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'should be a hash' do
|
203
|
+
@response.should be_an_instance_of(Hash)
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'should include the real name' do
|
207
|
+
@response['real_name'].should == 'Barney Stinson'
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'should include the user name' do
|
211
|
+
@response['user_name'].should == 'barney'
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'should include a profile picture' do
|
215
|
+
@response['profile_picture'].should == 'http://awesome.com/barney.jpg'
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..') + '/spec_helper')
|
2
|
+
require 'fakeweb'
|
3
|
+
|
4
|
+
describe Reflex::System do
|
5
|
+
include ReflexSpecHelper
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
Reflex.configure(:endpoint => "http://social.react.com/XmlRpc_v2/")
|
9
|
+
FakeWeb.allow_net_connect = false
|
10
|
+
FakeWeb.clean_registry
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "list_methods" do
|
14
|
+
before(:each) do
|
15
|
+
FakeWeb.register_uri(:post, "http://social.react.com/XmlRpc_v2/", :response => fake_response("System.listMethods"))
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should call System.listMethods" do
|
19
|
+
Reflex::System.expects(:call).with("System.listMethods")
|
20
|
+
Reflex::System.list_methods
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return an array of methods" do
|
24
|
+
Reflex::System.list_methods.should be_an_instance_of(Array)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should include System.listMethods" do
|
28
|
+
Reflex::System.list_methods.should include("System.listMethods")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "method_signature" do
|
33
|
+
before(:each) do
|
34
|
+
FakeWeb.register_uri(:post, "http://social.react.com/XmlRpc_v2/", :response => fake_response("System.methodSignature"))
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should call System.methodSignature" do
|
38
|
+
Reflex::System.expects(:call).with("System.methodSignature", "System.methodSignature")
|
39
|
+
Reflex::System.method_signature("System.methodSignature")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return an array of arguments" do
|
43
|
+
Reflex::System.method_signature("System.methodSignature").should be_an_instance_of(Array)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return a signature with 1 parameter" do
|
47
|
+
Reflex::System.method_signature("System.methodSignature").should == ["string"]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "method_description" do
|
52
|
+
before(:each) do
|
53
|
+
FakeWeb.register_uri(:post, "http://social.react.com/XmlRpc_v2/", :response => fake_response("System.methodDescription"))
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should call System.methodDescription" do
|
57
|
+
Reflex::System.expects(:call).with("System.methodDescription", "System.methodDescription")
|
58
|
+
Reflex::System.method_description("System.methodDescription")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return return a hash" do
|
62
|
+
Reflex::System.method_description("System.methodDescription").should be_an_instance_of(Hash)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return a method description" do
|
66
|
+
Reflex::System.method_description("System.methodDescription")['method']['description'].should == "Our extended version of System.methodSignature, with named parameters and descriptions."
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return parameter descriptions" do
|
70
|
+
Reflex::System.method_description("System.methodDescription")['parameters']['method']['type'].should == "string"
|
71
|
+
Reflex::System.method_description("System.methodDescription")['parameters']['method']['description'].should == "Method to get the description for"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "method_help" do
|
76
|
+
it "should call System.methodHelp" do
|
77
|
+
Reflex::System.expects(:call).with("System.methodHelp", "System.methodHelp")
|
78
|
+
Reflex::System.method_help("System.methodHelp")
|
79
|
+
end
|
80
|
+
|
81
|
+
# Rest of method_help seems broken
|
82
|
+
end
|
83
|
+
end
|
data/spec/reflex_spec.rb
ADDED
data/spec/schema.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
ActiveRecord::Schema.define :version => 0 do
|
2
|
+
create_table :reflex_connections do |t|
|
3
|
+
t.string :provider, :null => false
|
4
|
+
t.string :authorizable_type, :null => false
|
5
|
+
t.integer :authorizable_id, :null => false
|
6
|
+
t.string :uuid, :null => false
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
create_table :authorizables do |t|
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
add_index :reflex_connections, [:authorizable_type, :authorizable_id]
|
15
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'rubygems' unless RUBY_VERSION >= "1.9"
|
5
|
+
require 'authlogic'
|
6
|
+
require 'reflex'
|
7
|
+
require 'spec'
|
8
|
+
require 'spec/autorun'
|
9
|
+
require 'mocha'
|
10
|
+
require 'fakeweb'
|
11
|
+
require 'mime/types'
|
12
|
+
|
13
|
+
TEST_DATABASE_FILE = File.join(File.dirname(__FILE__), '..', 'test.sqlite3')
|
14
|
+
File.unlink(TEST_DATABASE_FILE) if File.exist?(TEST_DATABASE_FILE)
|
15
|
+
ActiveRecord::Base.establish_connection("adapter" => "sqlite3", "database" => TEST_DATABASE_FILE)
|
16
|
+
ActiveRecord::Base.silence do
|
17
|
+
ActiveRecord::Migration.verbose = false
|
18
|
+
load File.join(File.dirname(__FILE__), 'schema.rb')
|
19
|
+
end
|
20
|
+
|
21
|
+
class Authorizable < ActiveRecord::Base
|
22
|
+
end
|
23
|
+
|
24
|
+
Spec::Runner.configure do |config|
|
25
|
+
config.mock_with :mocha
|
26
|
+
end
|
27
|
+
|
28
|
+
module ReflexSpecHelper
|
29
|
+
def self.included(base)
|
30
|
+
config_file = File.join(File.dirname(__FILE__), 'reflex.yml')
|
31
|
+
|
32
|
+
if File.exists?(config_file)
|
33
|
+
settings = YAML.load(File.open(config_file))
|
34
|
+
configuration = settings.inject({}) do |options, (key, value)|
|
35
|
+
options[(key.to_sym rescue key) || key] = value
|
36
|
+
options
|
37
|
+
end
|
38
|
+
|
39
|
+
Reflex.configure(configuration)
|
40
|
+
else
|
41
|
+
puts "** [Reflex] #{config_file} does not exist, skipping Reflex configuration"
|
42
|
+
end
|
43
|
+
|
44
|
+
::XMLRPC::Client.class_eval do
|
45
|
+
def call2(method, *args)
|
46
|
+
puts "XMLRPC Request: #{method}(#{args.map(&:inspect).join(", ")})" if defined?($debug_response) && $debug_response
|
47
|
+
request = create().methodCall(method, *args)
|
48
|
+
data = do_rpc(request, false)
|
49
|
+
puts "XMLRPC Response:\n#{data}\n" if defined?($debug_response) && $debug_response
|
50
|
+
parser().parseMethodResponse(data)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def debug_response(&block)
|
56
|
+
FakeWeb.allow_net_connect = true
|
57
|
+
$debug_response = true
|
58
|
+
yield
|
59
|
+
$debug_response = false
|
60
|
+
FakeWeb.allow_net_connect = false
|
61
|
+
end
|
62
|
+
|
63
|
+
def fake_response(filename, options = {})
|
64
|
+
File.join(File.dirname(__FILE__), "fakeweb", filename)
|
65
|
+
end
|
66
|
+
end
|