facemock 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 835273f7c56ae08b7fda22e1c4290cc0ad91bafe
4
+ data.tar.gz: 3a5c4878f90b434d9806810512ef486d6a3d1fea
5
+ SHA512:
6
+ metadata.gz: 420898edd849b91a9e8c653f805466a59394b954d9029c2b902be6290ae0c5b9dcb0ee929b73855d3ab541106a68a79db1250e4f42751a8f49d307a6d6482b7a
7
+ data.tar.gz: 757d12fb78f3561a12cafedaf33a33f0d3a3d05e18739b11ee5ad5ce50a955a975c1cc5f913e195026a8d6a3c528834c86342a67560d51f63c1da4783aded8f8
data/facemock.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "fb_graph"
23
23
  spec.add_dependency "omniauth"
24
24
  spec.add_dependency "hashie"
25
+ spec.add_dependency "faker"
25
26
 
26
27
  spec.add_development_dependency "bundler", "~> 1.3"
27
28
  spec.add_development_dependency "rake"
@@ -1,3 +1,4 @@
1
+ require 'faker'
1
2
  require 'facemock/database/table'
2
3
  require 'facemock/user'
3
4
 
@@ -10,8 +11,8 @@ module Facemock
10
11
  # WANT : DBに登録済みの値と重複しないようにする(id, secret)
11
12
  def initialize(options={})
12
13
  opts = Hashie::Mash.new(options)
13
- @id = ( opts.id.to_i > 0 ) ? opts.id.to_i : (0..9).to_a.shuffle[0..15].join.to_i
14
- @secret = opts.secret || rand(36**32).to_s(36)
14
+ @id = ( opts.id.to_i > 0 ) ? opts.id.to_i : Faker::Number.number(15).to_i
15
+ @secret = opts.secret || Faker::Lorem.characters(32)
15
16
  @created_at = opts.created_at
16
17
  end
17
18
  end
@@ -8,7 +8,7 @@ module Facemock
8
8
  def initialize(options={})
9
9
  opts = Hashie::Mash.new(options)
10
10
  @id = opts.id
11
- @string = opts.string || rand(36**255).to_s(36)
11
+ @string = opts.string || Faker::Lorem.characters
12
12
  @user_id = opts.user_id
13
13
  @created_at = opts.created_at
14
14
  end
@@ -41,8 +41,10 @@ module Facemock
41
41
  app = Facemock::Application.create!({ id: app_id, secret: app_secret })
42
42
  users.each do |options|
43
43
  user = Facemock::User.new(options)
44
- user.application_id = app.id
45
- user.save!
44
+ unless Facemock::User.find_by_id(user.id)
45
+ user.application_id = app.id
46
+ user.save!
47
+ end
46
48
  end
47
49
  end
48
50
  end
@@ -214,7 +214,6 @@ module Facemock
214
214
  case method_name
215
215
  when /^find_by_(.+)/ then define_find_by_column(column_name)
216
216
  when /^find_all_by_(.+)/ then define_find_all_by_column(column_name)
217
- else false
218
217
  end
219
218
  end
220
219
 
@@ -279,14 +278,12 @@ module Facemock
279
278
  opts = Hashie::Mash.new(options)
280
279
  instance = self.class.new
281
280
  column_names.each do |column_name|
282
- if column_name != :created_at
283
- if self.class.column_notnull(column_name) && column_is_empty?(column_name)
284
- raise Facemock::Errors::ColumnTypeNotNull, "#{column_name} is null"
285
- end
286
- instance.send(column_name.to_s + "=", self.send(column_name))
287
- if opts.send(column_name)
288
- instance.send(column_name.to_s + "=", opts.send(column_name))
289
- end
281
+ next if column_name == :created_at
282
+ notnull_check(column_name)
283
+ instance.send(column_name.to_s + "=", self.send(column_name))
284
+
285
+ if opts.send(column_name)
286
+ instance.send(column_name.to_s + "=", opts.send(column_name))
290
287
  end
291
288
  end
292
289
 
@@ -351,6 +348,12 @@ module Facemock
351
348
  return nil unless column_names.include?(column_name.to_s.to_sym)
352
349
  table_info.send(column_name).notnull
353
350
  end
351
+
352
+ def notnull_check(column_name)
353
+ if self.class.column_notnull(column_name) && column_is_empty?(column_name)
354
+ raise Facemock::Errors::ColumnTypeNotNull, "#{column_name} is null"
355
+ end
356
+ end
354
357
  end
355
358
  end
356
359
  end
data/lib/facemock/user.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'faker'
1
2
  require 'facemock/database/table'
2
3
  require 'facemock/permission'
3
4
  require 'facemock/authorization_code'
@@ -11,15 +12,22 @@ module Facemock
11
12
  def initialize(options={})
12
13
  opts = Hashie::Mash.new(options)
13
14
  id = opts.id || opts.identifier
14
- @id = (id.to_i > 0) ? id.to_i : ("10000" + (0..9).to_a.shuffle[0..10].join).to_i
15
- @name = opts.name || rand(36**10).to_s(36)
16
- @email = opts.email || name.gsub(" ", "_") + "@example.com"
17
- @password = opts.password || rand(36**10).to_s(36)
15
+ @id = (id.to_i > 0) ? id.to_i : ("10000" + Faker::Number.number(10)).to_i
16
+ @name = opts.name || create_user_name
17
+ @email = opts.email || Faker::Internet.email
18
+ @password = opts.password || Faker::Internet.password
18
19
  @installed = opts.installed || false
19
- @access_token = opts.access_token || rand(36**255).to_s(36)
20
+ @access_token = opts.access_token || Faker::Lorem.characters
20
21
  app_id = opts.application_id.to_i
21
22
  @application_id = (app_id > 0) ? app_id : nil
22
23
  @created_at = opts.created_at
23
24
  end
25
+
26
+ private
27
+
28
+ def create_user_name
29
+ n = Faker::Name.name
30
+ n.include?("'") ? create_user_name : n
31
+ end
24
32
  end
25
33
  end
@@ -1,3 +1,3 @@
1
1
  module Facemock
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
@@ -39,6 +39,7 @@ describe Facemock::Application do
39
39
  describe '.id' do
40
40
  subject { Facemock::Application.new.id }
41
41
  it { is_expected.to be > 0 }
42
+ it { is_expected.to be < 1000000000000000 }
42
43
  end
43
44
 
44
45
  describe '.secret' do
@@ -47,7 +48,7 @@ describe Facemock::Application do
47
48
 
48
49
  describe '.size' do
49
50
  subject { Facemock::Application.new.secret.size }
50
- it { is_expected.to be <= 32 }
51
+ it { is_expected.to eq 32 }
51
52
  end
52
53
  end
53
54
 
@@ -53,7 +53,7 @@ describe Facemock::AuthorizationCode do
53
53
  string1 = Facemock::AuthorizationCode.new.string
54
54
  string2 = Facemock::AuthorizationCode.new.string
55
55
  expect(string1).to be_kind_of String
56
- expect(string1.size).to be < 256
56
+ expect(string1.size).to eq 255
57
57
  expect(string1).not_to eq string2
58
58
  end
59
59
  end
@@ -175,6 +175,20 @@ describe Facemock::Config do
175
175
  expect(Facemock::Application.all.count).to eq app_count
176
176
  expect(Facemock::User.all.count).to eq user_count
177
177
  end
178
+
179
+ context 'when already exist specified users' do
180
+ before do
181
+ Facemock::Config.load_users(@path)
182
+ end
183
+
184
+ it 'should not raise error' do
185
+ size = Facemock::User.all.size
186
+ expect(size).to eq 3
187
+ path = create_temporary_yaml_file(yaml_load_data)
188
+ Facemock::Config.load_users(path)
189
+ expect(size).to eq 3
190
+ end
191
+ end
178
192
  end
179
193
  end
180
194
  end
@@ -55,13 +55,6 @@ describe Facemock::FbGraph::Application::User do
55
55
  end
56
56
  end
57
57
  end
58
-
59
- context 'with only name option' do
60
- before { @options = { name: "test_user" } }
61
-
62
- subject { @user = Facemock::FbGraph::Application::User.new(@options).email }
63
- it { is_expected.to eq "#{@options[:name]}@example.com" }
64
- end
65
58
  end
66
59
 
67
60
  describe '#permission' do
@@ -67,7 +67,7 @@ describe Facemock::User do
67
67
 
68
68
  describe '.size' do
69
69
  subject { Facemock::User.new.name.size }
70
- it { is_expected.to be <= 10 }
70
+ it { is_expected.to be > 0 }
71
71
  end
72
72
  end
73
73
 
@@ -75,7 +75,7 @@ describe Facemock::User do
75
75
  before { @user = Facemock::User.new }
76
76
  subject { @user.email }
77
77
  it { is_expected.to be_kind_of String }
78
- it { is_expected.to eq "#{@user.name}@example.com" }
78
+ it { is_expected.to match /^.+@.+$/ }
79
79
  end
80
80
 
81
81
  describe '.password' do
@@ -84,7 +84,7 @@ describe Facemock::User do
84
84
 
85
85
  describe '.size' do
86
86
  subject { Facemock::User.new.password.size }
87
- it { is_expected.to be <= 10 }
87
+ it { is_expected.to be_between(8, 16) }
88
88
  end
89
89
  end
90
90
 
@@ -99,7 +99,7 @@ describe Facemock::User do
99
99
 
100
100
  describe '.size' do
101
101
  subject { Facemock::User.new.access_token.size }
102
- it { is_expected.to be <= 255 }
102
+ it { is_expected.to eq 255 }
103
103
  end
104
104
  end
105
105
 
@@ -154,25 +154,6 @@ describe Facemock::User do
154
154
  end
155
155
  end
156
156
 
157
- context 'with name option' do
158
- before do
159
- @name = "test user"
160
- @opts = { name: @name }
161
- end
162
- subject { Facemock::User.new(@opts) }
163
- it { is_expected.to be_kind_of Facemock::User }
164
-
165
- context '.name' do
166
- subject { Facemock::User.new(@opts).name }
167
- it { is_expected.to eq @name }
168
- end
169
-
170
- context '.email' do
171
- subject { Facemock::User.new(@opts).email }
172
- it { is_expected.to eq @name.gsub(" ", "_") + "@example.com" }
173
- end
174
- end
175
-
176
157
  context 'with all options' do
177
158
  subject { Facemock::User.new(options) }
178
159
  it { is_expected.to be_kind_of Facemock::User }
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Facemock do
4
- let(:version) { '0.0.9' }
4
+ let(:version) { '0.0.10' }
5
5
  let(:db_name) { '.test' }
6
6
 
7
7
  describe 'VERSION' do
@@ -73,6 +73,23 @@ describe Facemock do
73
73
  end
74
74
  end
75
75
 
76
+ context 'with incorrect access_token' do
77
+ before do
78
+ stub_const("Facemock::Database::DEFAULT_DB_NAME", db_name)
79
+ @database = Facemock::Database.new
80
+ @user = Facemock::User.new
81
+ @access_token = @user.access_token
82
+ end
83
+
84
+ context 'that is incorrect' do
85
+ it 'should return empty AuthHash' do
86
+ auth_hash = Facemock.auth_hash(@access_token)
87
+ expect(auth_hash).to be_kind_of Facemock::AuthHash
88
+ expect(auth_hash).to be_empty
89
+ end
90
+ end
91
+ end
92
+
76
93
  context 'with access_token' do
77
94
  before do
78
95
  stub_const("Facemock::Database::DEFAULT_DB_NAME", db_name)
@@ -83,9 +100,6 @@ describe Facemock do
83
100
  end
84
101
  after { @database.drop }
85
102
 
86
- context 'that is incorrect' do
87
- end
88
-
89
103
  context 'that is correct' do
90
104
  it 'should return AuthHash with some keys and value' do
91
105
  auth_hash = Facemock.auth_hash(@access_token)
metadata CHANGED
@@ -1,174 +1,167 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facemock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
5
- prerelease:
4
+ version: 0.0.10
6
5
  platform: ruby
7
6
  authors:
8
7
  - ogawatti
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-09-09 00:00:00.000000000 Z
11
+ date: 2014-10-28 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: sqlite3
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: fb_graph
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: omniauth
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: hashie
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faker
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
76
81
  - !ruby/object:Gem::Version
77
82
  version: '0'
78
83
  - !ruby/object:Gem::Dependency
79
84
  name: bundler
80
85
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
86
  requirements:
83
- - - ~>
87
+ - - "~>"
84
88
  - !ruby/object:Gem::Version
85
89
  version: '1.3'
86
90
  type: :development
87
91
  prerelease: false
88
92
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
93
  requirements:
91
- - - ~>
94
+ - - "~>"
92
95
  - !ruby/object:Gem::Version
93
96
  version: '1.3'
94
97
  - !ruby/object:Gem::Dependency
95
98
  name: rake
96
99
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
100
  requirements:
99
- - - ! '>='
101
+ - - ">="
100
102
  - !ruby/object:Gem::Version
101
103
  version: '0'
102
104
  type: :development
103
105
  prerelease: false
104
106
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
107
  requirements:
107
- - - ! '>='
108
+ - - ">="
108
109
  - !ruby/object:Gem::Version
109
110
  version: '0'
110
111
  - !ruby/object:Gem::Dependency
111
112
  name: rspec
112
113
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
114
  requirements:
115
- - - ! '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
121
  requirements:
123
- - - ! '>='
122
+ - - ">="
124
123
  - !ruby/object:Gem::Version
125
124
  version: '0'
126
125
  - !ruby/object:Gem::Dependency
127
126
  name: simplecov
128
127
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
128
  requirements:
131
- - - ! '>='
129
+ - - ">="
132
130
  - !ruby/object:Gem::Version
133
131
  version: '0'
134
132
  type: :development
135
133
  prerelease: false
136
134
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
135
  requirements:
139
- - - ! '>='
136
+ - - ">="
140
137
  - !ruby/object:Gem::Version
141
138
  version: '0'
142
139
  - !ruby/object:Gem::Dependency
143
140
  name: pry
144
141
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
142
  requirements:
147
- - - ! '>='
143
+ - - ">="
148
144
  - !ruby/object:Gem::Version
149
145
  version: '0'
150
146
  type: :development
151
147
  prerelease: false
152
148
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
149
  requirements:
155
- - - ! '>='
150
+ - - ">="
156
151
  - !ruby/object:Gem::Version
157
152
  version: '0'
158
153
  - !ruby/object:Gem::Dependency
159
154
  name: coveralls
160
155
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
156
  requirements:
163
- - - ! '>='
157
+ - - ">="
164
158
  - !ruby/object:Gem::Version
165
159
  version: '0'
166
160
  type: :development
167
161
  prerelease: false
168
162
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
163
  requirements:
171
- - - ! '>='
164
+ - - ">="
172
165
  - !ruby/object:Gem::Version
173
166
  version: '0'
174
167
  description: This gem is used to mock the communication part of the facebook graph
@@ -179,10 +172,10 @@ executables: []
179
172
  extensions: []
180
173
  extra_rdoc_files: []
181
174
  files:
182
- - .coveralls.yml
183
- - .gitignore
184
- - .rspec
185
- - .travis.yml
175
+ - ".coveralls.yml"
176
+ - ".gitignore"
177
+ - ".rspec"
178
+ - ".travis.yml"
186
179
  - Gemfile
187
180
  - LICENSE.txt
188
181
  - README.md
@@ -209,8 +202,8 @@ files:
209
202
  - lib/facemock/version.rb
210
203
  - spec/facemock/application_spec.rb
211
204
  - spec/facemock/auth_hash_spec.rb
205
+ - spec/facemock/authorization_code.rb
212
206
  - spec/facemock/config_spec.rb
213
- - spec/facemock/database/authorization_code.rb
214
207
  - spec/facemock/database/table_spec.rb
215
208
  - spec/facemock/database_spec.rb
216
209
  - spec/facemock/errors_spec.rb
@@ -229,39 +222,32 @@ files:
229
222
  homepage: https://github.com/ogawatti/facemock
230
223
  licenses:
231
224
  - MIT
225
+ metadata: {}
232
226
  post_install_message:
233
227
  rdoc_options: []
234
228
  require_paths:
235
229
  - lib
236
230
  required_ruby_version: !ruby/object:Gem::Requirement
237
- none: false
238
231
  requirements:
239
- - - ! '>='
232
+ - - ">="
240
233
  - !ruby/object:Gem::Version
241
234
  version: '0'
242
- segments:
243
- - 0
244
- hash: -2277358927019548637
245
235
  required_rubygems_version: !ruby/object:Gem::Requirement
246
- none: false
247
236
  requirements:
248
- - - ! '>='
237
+ - - ">="
249
238
  - !ruby/object:Gem::Version
250
239
  version: '0'
251
- segments:
252
- - 0
253
- hash: -2277358927019548637
254
240
  requirements: []
255
241
  rubyforge_project:
256
- rubygems_version: 1.8.25
242
+ rubygems_version: 2.2.2
257
243
  signing_key:
258
- specification_version: 3
244
+ specification_version: 4
259
245
  summary: This is facebook mock application for fb_graph.
260
246
  test_files:
261
247
  - spec/facemock/application_spec.rb
262
248
  - spec/facemock/auth_hash_spec.rb
249
+ - spec/facemock/authorization_code.rb
263
250
  - spec/facemock/config_spec.rb
264
- - spec/facemock/database/authorization_code.rb
265
251
  - spec/facemock/database/table_spec.rb
266
252
  - spec/facemock/database_spec.rb
267
253
  - spec/facemock/errors_spec.rb