facemock 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+
3
+ describe Facemock::FbGraph::Application::User do
4
+ let(:table_name) { "users" }
5
+
6
+ let(:db_name) { ".test" }
7
+ let(:adapter) { "sqlite3" }
8
+ let(:db_directory) { File.expand_path("../../../../db", __FILE__) }
9
+ let(:db_filepath) { File.join(db_directory, "#{db_name}.#{adapter}") }
10
+ let(:options) { { identifier: 100000000000001,
11
+ name: "test user",
12
+ email: "test@example.com",
13
+ password: "testpass",
14
+ installed: true,
15
+ access_token: "test_token",
16
+ permissions: "email, read_stream" } }
17
+
18
+ before do
19
+ stub_const("Facemock::Config::Database::DEFAULT_DB_NAME", db_name)
20
+ Facemock::Config.database
21
+ end
22
+ after { Facemock::Config.database.drop }
23
+
24
+ it 'should have a rigth class' do
25
+ expect(Facemock::FbGraph::Application::User::Right).to be_truthy
26
+ expect(Facemock::FbGraph::Application::User::Right.ancestors).to include ActiveRecord::Base
27
+ end
28
+
29
+ describe '.table_name' do
30
+ subject { Facemock::FbGraph::Application::User.table_name }
31
+ it { is_expected.to eq table_name }
32
+ end
33
+
34
+ describe '#new' do
35
+ context 'without options' do
36
+ subject { lambda { Facemock::FbGraph::Application::User.new } }
37
+ it { is_expected.not_to raise_error }
38
+
39
+ it 'should be initialized attribute' do
40
+ user = Facemock::FbGraph::Application::User.new
41
+
42
+ expect(user.identifier).to be_kind_of Integer
43
+ expect(user.name).to be_kind_of String
44
+ expect(user.email).to be_kind_of String
45
+ expect(user.password).to be_kind_of String
46
+ expect(user.access_token).to be_kind_of String
47
+ expect(user.permissions).to be_kind_of Array
48
+
49
+ expect(user.identifier).to be >= 100000000000000
50
+ expect(user.name).not_to be_empty
51
+ expect(user.password).not_to be_empty
52
+ expect(user.installed).to be false
53
+ expect(user.access_token).not_to be_empty
54
+ expect(user.permissions).to be_empty
55
+ end
56
+ end
57
+
58
+ context 'with all options' do
59
+ it 'should be initialized attribute by options' do
60
+ user = Facemock::FbGraph::Application::User.new(options)
61
+ options.each do |attribute, value|
62
+ if attribute.eql? :permissions
63
+ expect(user.send(attribute)).to include :email
64
+ expect(user.send(attribute)).to include :read_stream
65
+ else
66
+ expect(user.send(attribute)).to eq value
67
+ end
68
+ end
69
+
70
+ user.rights.each do |right|
71
+ expect(options[:permissions]).to include right.name
72
+ end
73
+ end
74
+ end
75
+
76
+ context 'with only name option' do
77
+ before { @options = { name: "test_user" } }
78
+
79
+ subject { @user = Facemock::FbGraph::Application::User.new(@options).email }
80
+ it { is_expected.to eq "#{@options[:name]}@example.com" }
81
+ end
82
+ end
83
+
84
+ describe '#fetch' do
85
+ before { @user = Facemock::FbGraph::Application::User.new }
86
+
87
+ context 'when user does not save' do
88
+ subject { @user.fetch }
89
+ it { is_expected.to eq nil }
90
+ end
91
+
92
+ context 'when user already saved' do
93
+ before do
94
+ @user.save!
95
+ end
96
+
97
+ subject { @user.fetch }
98
+ it { is_expected.not_to eq nil }
99
+
100
+ describe '.id' do
101
+ subject { @user.fetch.id }
102
+ it { is_expected.to eq @user.id }
103
+ end
104
+ end
105
+ end
106
+
107
+ describe '#revoke!' do
108
+ context 'when does not have permission' do
109
+ before do
110
+ @user = Facemock::FbGraph::Application::User.new
111
+ @user.save!
112
+ end
113
+
114
+ subject { lambda { @user.revoke! } }
115
+ it { is_expected.not_to raise_error }
116
+ end
117
+
118
+ context 'when have some permissions' do
119
+ before do
120
+ @user = Facemock::FbGraph::Application::User.new({permissions: "email, read_stream"})
121
+ @user.save!
122
+ end
123
+
124
+ it 'should destroy permissions' do
125
+ @user.revoke!
126
+ expect(Facemock::FbGraph::Application::User::Right.find_by_user_id(@user.id)).to be_nil
127
+ expect(@user.permissions).to be_empty
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,140 @@
1
+ require 'spec_helper'
2
+
3
+ describe Facemock::FbGraph::Application do
4
+ let(:table_name) { "applications" }
5
+
6
+ let(:facebook_app_id) { 100000000000000 }
7
+ let(:facebook_app_secret) { "test_secret" }
8
+ let(:access_token) { "access_token" }
9
+
10
+ let(:db_name) { ".test" }
11
+ let(:adapter) { "sqlite3" }
12
+ let(:db_directory) { File.expand_path("../../../../db", __FILE__) }
13
+ let(:db_filepath) { File.join(db_directory, "#{db_name}.#{adapter}") }
14
+
15
+ it 'should have a user class' do
16
+ expect(Facemock::FbGraph::Application::User).to be_truthy
17
+ expect(Facemock::FbGraph::Application::User.ancestors).to include ActiveRecord::Base
18
+ end
19
+
20
+ it 'should have a users class' do
21
+ expect(Facemock::FbGraph::Application::TestUsers).to be_truthy
22
+ expect(Facemock::FbGraph::Application::TestUsers.ancestors).to include Array
23
+ end
24
+
25
+ describe '.table_name' do
26
+ subject { Facemock::FbGraph::Application.table_name }
27
+ it { is_expected.to eq table_name }
28
+ end
29
+
30
+ before do
31
+ stub_const("Facemock::Config::Database::DEFAULT_DB_NAME", db_name)
32
+ Facemock::Config.database
33
+ end
34
+ after { Facemock::Config.database.drop }
35
+
36
+ describe '#new' do
37
+ context 'without argument' do
38
+ subject { lambda { Facemock::FbGraph::Application.new } }
39
+ it { is_expected.to raise_error ArgumentError }
40
+ end
41
+
42
+ context 'with facebook app id and secret' do
43
+ before { @app = Facemock::FbGraph::Application.new(facebook_app_id, secret: facebook_app_secret) }
44
+
45
+ describe '.id' do
46
+ subject { @app.id }
47
+ it { is_expected.to eq facebook_app_id }
48
+ end
49
+
50
+ describe '.secreet' do
51
+ subject { @app.secret }
52
+ it { is_expected.to eq facebook_app_secret }
53
+ end
54
+ end
55
+
56
+ context 'with facebook app id and secret' do
57
+ before do
58
+ options = { secret: facebook_app_secret }
59
+ Facemock::FbGraph.on
60
+ @app = Facemock::FbGraph::Application.new(facebook_app_id, options)
61
+ end
62
+
63
+ describe '.id' do
64
+ subject { @app.id }
65
+ it { is_expected.to eq facebook_app_id }
66
+ end
67
+
68
+ describe '.secreet' do
69
+ subject { @app.secret }
70
+ it { is_expected.to eq facebook_app_secret }
71
+ end
72
+ end
73
+
74
+ context 'with app symbole and access_token' do
75
+ before { @app = Facemock::FbGraph::Application.new(:app, access_token: access_token) }
76
+
77
+ describe '.id' do
78
+ subject { @app.id }
79
+ it { is_expected.to be_kind_of Integer }
80
+ end
81
+
82
+ describe '.secreet' do
83
+ subject { @app.secret }
84
+ it { is_expected.not_to be_empty }
85
+ end
86
+ end
87
+ end
88
+
89
+ describe '#fetch' do
90
+ before { @app = Facemock::FbGraph::Application.new(facebook_app_id, secret: facebook_app_secret) }
91
+
92
+ describe '.id' do
93
+ subject { @app.fetch.identifier }
94
+ it { is_expected.to eq @app.identifier }
95
+ end
96
+
97
+ describe '.secret' do
98
+ subject { @app.fetch.secret }
99
+ it { is_expected.to eq @app.secret }
100
+ end
101
+ end
102
+
103
+ describe '#test_user!' do
104
+ before { @app = Facemock::FbGraph::Application.new(facebook_app_id, secret: facebook_app_secret) }
105
+
106
+ it 'should created user' do
107
+ expect(Facemock::FbGraph::Application::User.all).to be_empty
108
+ user = @app.test_user!
109
+ expect(Facemock::FbGraph::Application::User.find_by_id(user.id)).to eq user
110
+ end
111
+ end
112
+
113
+ describe '#test_users' do
114
+ before do
115
+ @app = Facemock::FbGraph::Application.new(facebook_app_id, secret: facebook_app_secret)
116
+ end
117
+
118
+ context 'when test_user is not created' do
119
+ subject { @app.test_users }
120
+
121
+ it { is_expected.to be_kind_of Facemock::FbGraph::Application::TestUsers }
122
+ it { is_expected.to be_empty }
123
+ end
124
+
125
+ context 'when test_user is created' do
126
+ before do
127
+ @user = @app.test_user!
128
+ end
129
+
130
+ subject { @app.test_users }
131
+ it { is_expected.to be_kind_of Facemock::FbGraph::Application::TestUsers }
132
+ it { is_expected.not_to be_empty }
133
+
134
+ describe '.first.id' do
135
+ subject { @app.test_users.first.id }
136
+ it { is_expected.to eq @user.id }
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Facemock::FbGraph::Errors do
4
+ before do
5
+ Facemock::FbGraph.off
6
+ end
7
+
8
+ it 'should have a error module' do
9
+ expect(Facemock::FbGraph::Errors::Error).to be_truthy
10
+ expect(Facemock::FbGraph::Errors::Error.ancestors).to include StandardError
11
+ expect(Facemock::FbGraph::Errors::InvalidToken.ancestors).to include FbGraph::InvalidToken
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Facemock::FbGraph::User do
4
+ let(:facebook_app_id) { "100000000000000" }
5
+ let(:facebook_app_secret) { "test_secret" }
6
+ let(:db_name) { ".test" }
7
+ let(:adapter) { "sqlite3" }
8
+ let(:table_names) { [:users, :user_rights] }
9
+ let(:db_directory) { File.expand_path("../../../../db", __FILE__) }
10
+ let(:db_filepath) { File.join(db_directory, "#{db_name}.#{adapter}") }
11
+
12
+ before do
13
+ stub_const("Facemock::Config::Database::DEFAULT_DB_NAME", db_name)
14
+ Facemock::Config.database
15
+ end
16
+ after { Facemock::Config.database.drop }
17
+
18
+ describe '.me' do
19
+ context 'when access_token is correct' do
20
+ before do
21
+ app = Facemock::FbGraph::Application.new(facebook_app_id, secret: facebook_app_secret)
22
+ @user = app.test_user!
23
+ @access_token = @user.access_token
24
+ end
25
+
26
+ it 'can get user' do
27
+ user = Facemock::FbGraph::User.me(@access_token)
28
+ Facemock::FbGraph::Application::User.column_names.each do |column|
29
+ expect(user.send(column)).to eq @user.send(column) unless column == "created_at"
30
+ end
31
+ end
32
+ end
33
+
34
+ context 'when access_token is incorrect' do
35
+ subject { Facemock::FbGraph::User.me('incorrect_token') }
36
+ it { is_expected.to eq nil }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Facemock::FbGraph do
4
+ let(:db_name) { ".test" }
5
+
6
+ it 'should have a application class' do
7
+ expect(Facemock::FbGraph::Application).to be_truthy
8
+ end
9
+
10
+ it 'should have a errors module' do
11
+ expect(Facemock::FbGraph::Errors).to be_truthy
12
+ end
13
+
14
+ it 'should have a user module' do
15
+ expect(Facemock::FbGraph::User).to be_truthy
16
+ end
17
+
18
+ before do
19
+ stub_const("Facemock::Config::Database::DEFAULT_DB_NAME", db_name)
20
+ end
21
+ after { Facemock::Config.database.drop }
22
+
23
+ describe '#on' do
24
+ subject { Facemock::FbGraph.on }
25
+ it { is_expected.to be_truthy }
26
+
27
+ context 'FbGraph' do
28
+ before { Facemock::FbGraph.on }
29
+ it { expect(::FbGraph).to eq Facemock::FbGraph }
30
+ it { expect( lambda { Facemock::FbGraph.on } ).not_to raise_error }
31
+ end
32
+ end
33
+
34
+ describe '#off' do
35
+ subject { Facemock::FbGraph.off }
36
+ it { is_expected.to be_truthy }
37
+
38
+ context 'FbGraph' do
39
+ before { Facemock::FbGraph.off }
40
+ it { expect(FbGraph).to eq FbGraph }
41
+ it { expect( lambda { Facemock::FbGraph.off } ).not_to raise_error }
42
+
43
+ context 'when mock is on' do
44
+ before do
45
+ Facemock::FbGraph.on
46
+ Facemock::FbGraph.off
47
+ end
48
+
49
+ subject { ::FbGraph }
50
+ it { is_expected.to eq FbGraph }
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe Facemock do
4
+ let(:version) { "0.0.2" }
5
+ let(:db_name) { ".test" }
6
+
7
+ describe 'VERSION' do
8
+ subject { Facemock::VERSION }
9
+ it { is_expected.to eq version }
10
+ end
11
+
12
+ it 'should have a config module' do
13
+ expect(Facemock::Config).to be_truthy
14
+ end
15
+
16
+ it 'should have a fb_graph module' do
17
+ expect(Facemock::FbGraph).to be_truthy
18
+ end
19
+
20
+ it 'should have a errors module' do
21
+ expect(Facemock::Errors).to be_truthy
22
+ end
23
+
24
+ before do
25
+ stub_const("Facemock::Config::Database::DEFAULT_DB_NAME", db_name)
26
+ end
27
+ after { Facemock::Config.database.drop }
28
+
29
+ describe '#on' do
30
+ subject { Facemock.on }
31
+ it { is_expected.to be_truthy }
32
+
33
+ context 'FbGraph' do
34
+ context 'without option' do
35
+ before { Facemock.on }
36
+ it { expect(::FbGraph).to eq Facemock::FbGraph }
37
+ it { expect( lambda { Facemock.on } ).not_to raise_error }
38
+ end
39
+
40
+ context 'with database_name option' do
41
+ before do
42
+ @options = { database_name: db_name}
43
+ Facemock.on(@options)
44
+ end
45
+ it { expect(::FbGraph).to eq Facemock::FbGraph }
46
+ it { expect( lambda { Facemock.on } ).not_to raise_error }
47
+ it { expect( lambda { Facemock.on(@options) } ).not_to raise_error }
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '#off' do
53
+ subject { Facemock.off }
54
+ it { is_expected.to be_truthy }
55
+
56
+ context 'FbGraph' do
57
+ before { Facemock.off }
58
+ it { expect(FbGraph).to eq FbGraph }
59
+ it { expect( lambda { Facemock.off } ).not_to raise_error }
60
+
61
+ context 'when Mock is on' do
62
+ before do
63
+ Facemock.on
64
+ Facemock.off
65
+ end
66
+
67
+ subject { ::FbGraph }
68
+ it { is_expected.to eq FbGraph }
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'simplecov'
4
+ require 'coveralls'
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+ SimpleCov.start do
11
+ add_filter '.bundle/'
12
+ add_filter '/spec/'
13
+ end
14
+
15
+ require 'facemock'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facemock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-28 00:00:00.000000000 Z
12
+ date: 2014-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: hashie
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: bundler
64
80
  requirement: !ruby/object:Gem::Requirement
@@ -155,14 +171,48 @@ dependencies:
155
171
  - - ! '>='
156
172
  - !ruby/object:Gem::Version
157
173
  version: '0'
158
- description: This is facebook mock application for fb_graph.
174
+ description: This gem is used to mock the communication part of the facebook graph
175
+ api.
159
176
  email:
160
177
  - ogawattim@gmail.com
161
178
  executables: []
162
179
  extensions: []
163
180
  extra_rdoc_files: []
164
- files: []
165
- homepage: ''
181
+ files:
182
+ - .coveralls.yml
183
+ - .gitignore
184
+ - .rspec
185
+ - .travis.yml
186
+ - Gemfile
187
+ - LICENSE.txt
188
+ - README.md
189
+ - Rakefile
190
+ - db/.gitkeep
191
+ - facemock.gemspec
192
+ - lib/facemock.rb
193
+ - lib/facemock/config.rb
194
+ - lib/facemock/config/database.rb
195
+ - lib/facemock/errors.rb
196
+ - lib/facemock/fb_graph.rb
197
+ - lib/facemock/fb_graph/application.rb
198
+ - lib/facemock/fb_graph/application/test_users.rb
199
+ - lib/facemock/fb_graph/application/user.rb
200
+ - lib/facemock/fb_graph/application/user/right.rb
201
+ - lib/facemock/fb_graph/errors.rb
202
+ - lib/facemock/fb_graph/user.rb
203
+ - lib/facemock/version.rb
204
+ - spec/facemock/config/database_spec.rb
205
+ - spec/facemock/config_spec.rb
206
+ - spec/facemock/fb_graph/application/test_users_spec.rb
207
+ - spec/facemock/fb_graph/application/user/right_spec.rb
208
+ - spec/facemock/fb_graph/application/user_spec.rb
209
+ - spec/facemock/fb_graph/application_spec.rb
210
+ - spec/facemock/fb_graph/errors_spec.rb
211
+ - spec/facemock/fb_graph/user_spec.rb
212
+ - spec/facemock/fb_graph_spec.rb
213
+ - spec/facemock_spec.rb
214
+ - spec/spec_helper.rb
215
+ homepage: https://github.com/ogawatti/facemock
166
216
  licenses:
167
217
  - MIT
168
218
  post_install_message:
@@ -175,16 +225,33 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
225
  - - ! '>='
176
226
  - !ruby/object:Gem::Version
177
227
  version: '0'
228
+ segments:
229
+ - 0
230
+ hash: 1510434959302606046
178
231
  required_rubygems_version: !ruby/object:Gem::Requirement
179
232
  none: false
180
233
  requirements:
181
234
  - - ! '>='
182
235
  - !ruby/object:Gem::Version
183
236
  version: '0'
237
+ segments:
238
+ - 0
239
+ hash: 1510434959302606046
184
240
  requirements: []
185
241
  rubyforge_project:
186
242
  rubygems_version: 1.8.25
187
243
  signing_key:
188
244
  specification_version: 3
189
245
  summary: This is facebook mock application for fb_graph.
190
- test_files: []
246
+ test_files:
247
+ - spec/facemock/config/database_spec.rb
248
+ - spec/facemock/config_spec.rb
249
+ - spec/facemock/fb_graph/application/test_users_spec.rb
250
+ - spec/facemock/fb_graph/application/user/right_spec.rb
251
+ - spec/facemock/fb_graph/application/user_spec.rb
252
+ - spec/facemock/fb_graph/application_spec.rb
253
+ - spec/facemock/fb_graph/errors_spec.rb
254
+ - spec/facemock/fb_graph/user_spec.rb
255
+ - spec/facemock/fb_graph_spec.rb
256
+ - spec/facemock_spec.rb
257
+ - spec/spec_helper.rb