facemock 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -138,8 +138,8 @@ yaml file see below.
138
138
 
139
139
  require 'facemock'
140
140
 
141
- app = Facemock::Database::Application.create!
142
- user = Facemock::Database::User.craete!(application_id: app.id)
141
+ app = Facemock::Application.create!
142
+ user = Facemock::User.craete!(application_id: app.id)
143
143
  auth_hash = Facemock.auth_hash(user.access_token)
144
144
 
145
145
  # auth_hash == { "provider" => "facebook",
data/lib/facemock.rb CHANGED
@@ -1,9 +1,13 @@
1
- require "facemock/version"
2
- require "facemock/config"
3
- require "facemock/fb_graph"
4
- require "facemock/database"
5
- require "facemock/errors"
6
- require "facemock/auth_hash"
1
+ require 'facemock/version'
2
+ require 'facemock/config'
3
+ require 'facemock/fb_graph'
4
+ require 'facemock/database'
5
+ require 'facemock/errors'
6
+ require 'facemock/auth_hash'
7
+ require 'facemock/application'
8
+ require 'facemock/user'
9
+ require 'facemock/permission'
10
+ require 'facemock/authorization_code'
7
11
 
8
12
  module Facemock
9
13
  extend self
@@ -22,7 +26,7 @@ module Facemock
22
26
 
23
27
  def auth_hash(access_token=nil)
24
28
  if access_token.kind_of?(String) && access_token.size > 0
25
- user = Facemock::Database::User.find_by_access_token(access_token)
29
+ user = Facemock::User.find_by_access_token(access_token)
26
30
  if user
27
31
  Facemock::AuthHash.new({
28
32
  provider: "facebook",
@@ -0,0 +1,18 @@
1
+ require 'facemock/database/table'
2
+ require 'facemock/user'
3
+
4
+ module Facemock
5
+ class Application < Database::Table
6
+ TABLE_NAME = :applications
7
+ COLUMN_NAMES = [:id, :secret, :created_at]
8
+ CHILDREN = [ User ]
9
+
10
+ # WANT : DBに登録済みの値と重複しないようにする(id, secret)
11
+ def initialize(options={})
12
+ 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)
15
+ @created_at = opts.created_at
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ require 'facemock/database/table'
2
+
3
+ module Facemock
4
+ class AuthorizationCode < Database::Table
5
+ TABLE_NAME = :authorization_codes
6
+ COLUMN_NAMES = [:id, :string, :user_id, :created_at]
7
+
8
+ def initialize(options={})
9
+ opts = Hashie::Mash.new(options)
10
+ @id = opts.id
11
+ @string = opts.string || rand(36**255).to_s(36)
12
+ @user_id = opts.user_id
13
+ @created_at = opts.created_at
14
+ end
15
+ end
16
+ end
@@ -38,9 +38,9 @@ module Facemock
38
38
  raise Facemock::Errors::IncorrectDataFormat.new "users format is incorrect" unless validate_users(users)
39
39
 
40
40
  # Create application and user record
41
- app = Facemock::Database::Application.create!({ id: app_id, secret: app_secret })
41
+ app = Facemock::Application.create!({ id: app_id, secret: app_secret })
42
42
  users.each do |options|
43
- user = Facemock::Database::User.new(options)
43
+ user = Facemock::User.new(options)
44
44
  user.application_id = app.id
45
45
  user.save!
46
46
  end
@@ -1,9 +1,5 @@
1
1
  require 'sqlite3'
2
2
  require 'facemock/database/table'
3
- require 'facemock/database/application'
4
- require 'facemock/database/user'
5
- require 'facemock/database/permission'
6
- require 'facemock/database/authorization_code'
7
3
 
8
4
  module Facemock
9
5
  class Database
@@ -2,6 +2,7 @@ require 'fb_graph'
2
2
  require 'facemock/config'
3
3
  require 'facemock/fb_graph/user'
4
4
  require 'facemock/fb_graph/application'
5
+ require 'facemock/fb_graph/exception'
5
6
 
6
7
  module Facemock
7
8
  module FbGraph
@@ -2,7 +2,7 @@ require 'hashie'
2
2
  require 'facemock/config'
3
3
  require 'facemock/fb_graph/application/user'
4
4
  require 'facemock/fb_graph/application/test_users'
5
- require 'facemock/database/application'
5
+ require 'facemock/application'
6
6
 
7
7
  module Facemock
8
8
  module FbGraph
@@ -30,7 +30,7 @@ module Facemock
30
30
  elsif !validate_identifier_and_secret
31
31
  raise Facemock::FbGraph::InvalidRequest.new "Unsupported get request."
32
32
  end
33
- Facemock::Database::Application.find_by_id(@identifier)
33
+ Facemock::Application.find_by_id(@identifier)
34
34
  end
35
35
 
36
36
  if @record
@@ -65,8 +65,8 @@ module Facemock
65
65
  def validate_identifier_and_secret
66
66
  if validate_identifier && validate_secret
67
67
  # WANT : find_by_**_and_**(**, **)の実装
68
- app_by_id = Facemock::Database::Application.find_by_id(@identifier)
69
- app_by_secret = Facemock::Database::Application.find_by_secret(@secret)
68
+ app_by_id = Facemock::Application.find_by_id(@identifier)
69
+ app_by_secret = Facemock::Application.find_by_secret(@secret)
70
70
  !!(app_by_id && app_by_secret && app_by_id.identifier == app_by_secret.identifier)
71
71
  else
72
72
  false
@@ -76,23 +76,23 @@ module Facemock
76
76
  def validate_identifier
77
77
  return false if @identifier.nil? || @identifier == ""
78
78
  return false unless [Fixnum, String].include?(@identifier.class)
79
- return false unless Facemock::Database::Application.find_by_id(@identifier)
79
+ return false unless Facemock::Application.find_by_id(@identifier)
80
80
  true
81
81
  end
82
82
 
83
83
  def validate_secret
84
84
  return false if @secret.nil? || @secret == ""
85
- return false unless Facemock::Database::Application.find_by_secret(@secret)
85
+ return false unless Facemock::Application.find_by_secret(@secret)
86
86
  true
87
87
  end
88
88
 
89
89
  def validate_access_token
90
- !!(Facemock::Database::User.find_by_access_token(@access_token))
90
+ !!(Facemock::User.find_by_access_token(@access_token))
91
91
  end
92
92
 
93
93
  def find_by_access_token
94
- if user = Facemock::Database::User.find_by_access_token(@access_token)
95
- Facemock::Database::Application.find_by_id(user.application_id)
94
+ if user = Facemock::User.find_by_access_token(@access_token)
95
+ Facemock::Application.find_by_id(user.application_id)
96
96
  else
97
97
  nil
98
98
  end
@@ -4,7 +4,7 @@ require 'facemock/fb_graph/application/user/permission'
4
4
  module Facemock
5
5
  module FbGraph
6
6
  class Application
7
- class User < Facemock::Database::User
7
+ class User < Facemock::User
8
8
  attr_reader :permission_objects
9
9
 
10
10
  def initialize(options={})
@@ -1,8 +1,11 @@
1
+ require 'facemock/user'
2
+ require 'facemock/permission'
3
+
1
4
  module Facemock
2
5
  module FbGraph
3
6
  class Application
4
- class User < Facemock::Database::User
5
- class Permission < Facemock::Database::Permission
7
+ class User < Facemock::User
8
+ class Permission < Facemock::Permission
6
9
  end
7
10
  end
8
11
  end
@@ -0,0 +1,23 @@
1
+ require 'fb_graph'
2
+
3
+ module Facemock
4
+ module FbGraph
5
+ class Exception < ::FbGraph::Exception; end
6
+ class BadRequest < ::FbGraph::BadRequest; end
7
+ class Unauthorized < ::FbGraph::Unauthorized; end
8
+ class NotFound < ::FbGraph::NotFound; end
9
+ class InternalServerError < ::FbGraph::InternalServerError; end
10
+ class InvalidToken < ::FbGraph::InvalidToken; end
11
+ class InvalidSession < ::FbGraph::InvalidSession; end
12
+ class InvalidRequest < ::FbGraph::InvalidRequest; end
13
+ class CreativeNotSaved < ::FbGraph::CreativeNotSaved; end
14
+ class QueryLockTimeout < ::FbGraph::QueryLockTimeout; end
15
+ class TargetingSpecNotSaved < ::FbGraph::TargetingSpecNotSaved; end
16
+ class AdgroupFetchFailure < ::FbGraph::AdgroupFetchFailure; end
17
+ class OpenProcessFailure < ::FbGraph::OpenProcessFailure; end
18
+ class TransactionCommitFailure < ::FbGraph::TransactionCommitFailure; end
19
+ class QueryError < ::FbGraph::QueryError; end
20
+ class QueryConnection < ::FbGraph::QueryConnection; end
21
+ class QueryDuplicateKey < ::FbGraph::QueryDuplicateKey; end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require 'facemock/database/table'
2
+
3
+ module Facemock
4
+ class Permission < Database::Table
5
+ TABLE_NAME = :permissions
6
+ COLUMN_NAMES = [:id, :name, :user_id, :created_at]
7
+
8
+ def initialize(options={})
9
+ opts = Hashie::Mash.new(options)
10
+ @id = opts.id
11
+ @name = opts.name
12
+ @user_id = opts.user_id
13
+ @created_at = opts.created_at
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ require 'facemock/database/table'
2
+ require 'facemock/permission'
3
+ require 'facemock/authorization_code'
4
+
5
+ module Facemock
6
+ class User < Database::Table
7
+ TABLE_NAME = :users
8
+ COLUMN_NAMES = [:id, :name, :email, :password, :installed, :access_token, :application_id, :created_at]
9
+ CHILDREN = [ Permission, AuthorizationCode ]
10
+
11
+ def initialize(options={})
12
+ opts = Hashie::Mash.new(options)
13
+ @id = (opts.id.to_i > 0) ? opts.id.to_i : ("10000" + (0..9).to_a.shuffle[0..10].join).to_i
14
+ @name = opts.name || rand(36**10).to_s(36)
15
+ @email = opts.email || name.gsub(" ", "_") + "@example.com"
16
+ @password = opts.password || rand(36**10).to_s(36)
17
+ @installed = opts.installed || false
18
+ @access_token = opts.access_token || Digest::SHA512.hexdigest(identifier.to_s)
19
+ app_id = opts.application_id.to_i
20
+ @application_id = (app_id > 0) ? app_id : nil
21
+ @created_at = opts.created_at
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Facemock
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Facemock::Database::Application do
3
+ describe Facemock::Application do
4
4
  include TableHelper
5
5
 
6
6
  let(:db_name) { ".test" }
7
7
 
8
8
  let(:table_name) { :applications }
9
9
  let(:column_names) { [ :id, :secret, :created_at ] }
10
- let(:children) { [ Facemock::Database::User ] }
10
+ let(:children) { [ Facemock::User ] }
11
11
 
12
12
  let(:id) { 1 }
13
13
  let(:secret) { "test_secret" }
@@ -17,65 +17,65 @@ describe Facemock::Database::Application do
17
17
  after { remove_dynamically_defined_all_method }
18
18
 
19
19
  describe '::TABLE_NAME' do
20
- subject { Facemock::Database::Application::TABLE_NAME }
20
+ subject { Facemock::Application::TABLE_NAME }
21
21
  it { is_expected.to eq table_name }
22
22
  end
23
23
 
24
24
  describe '::COLUMN_NAMES' do
25
- subject { Facemock::Database::Application::COLUMN_NAMES }
25
+ subject { Facemock::Application::COLUMN_NAMES }
26
26
  it { is_expected.to eq column_names }
27
27
  end
28
28
 
29
29
  describe '::CHILDREN' do
30
- subject { Facemock::Database::Application::CHILDREN }
30
+ subject { Facemock::Application::CHILDREN }
31
31
  it { is_expected.to eq children }
32
32
  end
33
33
 
34
34
  describe '#initialize' do
35
35
  context 'without option' do
36
- subject { Facemock::Database::Application.new }
37
- it { is_expected.to be_kind_of Facemock::Database::Application }
36
+ subject { Facemock::Application.new }
37
+ it { is_expected.to be_kind_of Facemock::Application }
38
38
 
39
39
  describe '.id' do
40
- subject { Facemock::Database::Application.new.id }
40
+ subject { Facemock::Application.new.id }
41
41
  it { is_expected.to be > 0 }
42
42
  end
43
43
 
44
44
  describe '.secret' do
45
- subject { Facemock::Database::Application.new.secret }
45
+ subject { Facemock::Application.new.secret }
46
46
  it { is_expected.to be_kind_of String }
47
47
 
48
48
  describe '.size' do
49
- subject { Facemock::Database::Application.new.secret.size }
49
+ subject { Facemock::Application.new.secret.size }
50
50
  it { is_expected.to be <= 32 }
51
51
  end
52
52
  end
53
53
 
54
54
  describe '.created_at' do
55
- subject { Facemock::Database::Application.new.created_at }
55
+ subject { Facemock::Application.new.created_at }
56
56
  it { is_expected.to be_nil }
57
57
  end
58
58
  end
59
59
 
60
60
  context 'with id option but it is not integer' do
61
61
  before { @opts = { id: "test_id" } }
62
- subject { Facemock::Database::Application.new(@opts) }
63
- it { is_expected.to be_kind_of Facemock::Database::Application }
62
+ subject { Facemock::Application.new(@opts) }
63
+ it { is_expected.to be_kind_of Facemock::Application }
64
64
 
65
65
  describe '.id' do
66
- subject { Facemock::Database::Application.new(@opts).id }
66
+ subject { Facemock::Application.new(@opts).id }
67
67
  it { is_expected.to be > 0 }
68
68
  end
69
69
  end
70
70
 
71
71
  context 'with all options' do
72
- subject { Facemock::Database::Application.new(options) }
73
- it { is_expected.to be_kind_of Facemock::Database::Application }
72
+ subject { Facemock::Application.new(options) }
73
+ it { is_expected.to be_kind_of Facemock::Application }
74
74
 
75
75
  context 'then attributes' do
76
76
  it 'should set specified values by option' do
77
77
  column_names.each do |column_name|
78
- value = Facemock::Database::Application.new(options).send(column_name)
78
+ value = Facemock::Application.new(options).send(column_name)
79
79
  expect(value).to eq options[column_name]
80
80
  end
81
81
  end
@@ -92,13 +92,13 @@ describe Facemock::Database::Application do
92
92
 
93
93
  context 'when has user' do
94
94
  before do
95
- @application = Facemock::Database::Application.create!
96
- Facemock::Database::User.create!(application_id: @application.id)
95
+ @application = Facemock::Application.create!
96
+ Facemock::User.create!(application_id: @application.id)
97
97
  end
98
98
 
99
99
  it 'should delete permissions' do
100
100
  @application.destroy
101
- users = Facemock::Database::User.find_all_by_application_id(@application.id)
101
+ users = Facemock::User.find_all_by_application_id(@application.id)
102
102
  expect(users).to be_empty
103
103
  end
104
104
  end
@@ -118,8 +118,8 @@ describe Facemock::Config do
118
118
  begin
119
119
  Facemock::Config.load_users(@path)
120
120
  rescue => error
121
- expect(Facemock::Database::Application.all).to be_empty
122
- expect(Facemock::Database::User.all).to be_empty
121
+ expect(Facemock::Application.all).to be_empty
122
+ expect(Facemock::User.all).to be_empty
123
123
  end
124
124
  end
125
125
  end
@@ -172,8 +172,8 @@ describe Facemock::Config do
172
172
  app_count = yaml_load_data.size
173
173
  user_count = yaml_load_data.inject(0){|count, data| count += data[:users].size }
174
174
  Facemock::Config.load_users(@path)
175
- expect(Facemock::Database::Application.all.count).to eq app_count
176
- expect(Facemock::Database::User.all.count).to eq user_count
175
+ expect(Facemock::Application.all.count).to eq app_count
176
+ expect(Facemock::User.all.count).to eq user_count
177
177
  end
178
178
  end
179
179
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Facemock::Database::AuthorizationCode do
3
+ describe Facemock::AuthorizationCode do
4
4
  include TableHelper
5
5
 
6
6
  let(:table_name) { :authorization_codes }
@@ -16,29 +16,29 @@ describe Facemock::Database::AuthorizationCode do
16
16
  after { remove_dynamically_defined_all_method }
17
17
 
18
18
  describe '::TABLE_NAME' do
19
- subject { Facemock::Database::AuthorizationCode::TABLE_NAME }
19
+ subject { Facemock::AuthorizationCode::TABLE_NAME }
20
20
  it { is_expected.to eq table_name }
21
21
  end
22
22
 
23
23
  describe '::COLUMN_NAMES' do
24
- subject { Facemock::Database::AuthorizationCode::COLUMN_NAMES }
24
+ subject { Facemock::AuthorizationCode::COLUMN_NAMES }
25
25
  it { is_expected.to eq column_names }
26
26
  end
27
27
 
28
28
  describe '::CHILDREN' do
29
- subject { Facemock::Database::AuthorizationCode::CHILDREN }
29
+ subject { Facemock::AuthorizationCode::CHILDREN }
30
30
  it { is_expected.to eq children }
31
31
  end
32
32
 
33
33
  describe '#initialize' do
34
34
  context 'without option' do
35
- subject { Facemock::Database::AuthorizationCode.new }
36
- it { is_expected.to be_kind_of Facemock::Database::AuthorizationCode }
35
+ subject { Facemock::AuthorizationCode.new }
36
+ it { is_expected.to be_kind_of Facemock::AuthorizationCode }
37
37
 
38
38
  context 'then attributes' do
39
39
  it 'should be nil except string' do
40
40
  column_names.each do |column_name|
41
- value = Facemock::Database::AuthorizationCode.new.send(column_name)
41
+ value = Facemock::AuthorizationCode.new.send(column_name)
42
42
  if column_name == :string
43
43
  expect(value).not_to be_nil
44
44
  else
@@ -50,8 +50,8 @@ describe Facemock::Database::AuthorizationCode do
50
50
 
51
51
  context 'then string' do
52
52
  it 'should be random string' do
53
- string1 = Facemock::Database::AuthorizationCode.new.string
54
- string2 = Facemock::Database::AuthorizationCode.new.string
53
+ string1 = Facemock::AuthorizationCode.new.string
54
+ string2 = Facemock::AuthorizationCode.new.string
55
55
  expect(string1).to be_kind_of String
56
56
  expect(string1.size).to be < 256
57
57
  expect(string1).not_to eq string2
@@ -60,13 +60,13 @@ describe Facemock::Database::AuthorizationCode do
60
60
  end
61
61
 
62
62
  context 'with all options' do
63
- subject { Facemock::Database::AuthorizationCode.new(options) }
64
- it { is_expected.to be_kind_of Facemock::Database::AuthorizationCode }
63
+ subject { Facemock::AuthorizationCode.new(options) }
64
+ it { is_expected.to be_kind_of Facemock::AuthorizationCode }
65
65
 
66
66
  context 'then attributes' do
67
67
  it 'should set specified value by option' do
68
68
  column_names.each do |column_name|
69
- value = Facemock::Database::AuthorizationCode.new(options).send(column_name)
69
+ value = Facemock::AuthorizationCode.new(options).send(column_name)
70
70
  expect(value).to eq options[column_name]
71
71
  end
72
72
  end
@@ -16,7 +16,7 @@ describe Facemock::FbGraph::Application do
16
16
  after { @database.drop }
17
17
 
18
18
  describe '#new' do
19
- before { @default_record_size = Facemock::Database::Application.all.size }
19
+ before { @default_record_size = Facemock::Application.all.size }
20
20
 
21
21
  context 'without argument' do
22
22
  subject { lambda { Facemock::FbGraph::Application.new } }
@@ -29,7 +29,7 @@ describe Facemock::FbGraph::Application do
29
29
  expect(@app.identifier).to eq @id
30
30
  expect(@app.secret).to be_nil
31
31
  expect(@app.access_token).to be_nil
32
- expect(Facemock::Database::Application.all.size).to eq @default_record_size
32
+ expect(Facemock::Application.all.size).to eq @default_record_size
33
33
  end
34
34
  end
35
35
 
@@ -57,7 +57,7 @@ describe Facemock::FbGraph::Application do
57
57
  expect(@app.identifier).to eq @id
58
58
  expect(@app.secret).to be_nil
59
59
  expect(@app.access_token).to be_nil
60
- expect(Facemock::Database::Application.all.size).to eq @default_record_size
60
+ expect(Facemock::Application.all.size).to eq @default_record_size
61
61
  end
62
62
  end
63
63
 
@@ -71,7 +71,7 @@ describe Facemock::FbGraph::Application do
71
71
  expect(@app.identifier).to eq facebook_app_id
72
72
  expect(@app.secret).to eq @options[:secret]
73
73
  expect(@app.access_token).to eq @options[:access_token]
74
- expect(Facemock::Database::Application.all.size).to eq @default_record_size
74
+ expect(Facemock::Application.all.size).to eq @default_record_size
75
75
  end
76
76
  end
77
77
  end
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+
3
+ describe Facemock::FbGraph::Exception do
4
+ describe 'Exception' do
5
+ subject { Facemock::FbGraph::Exception }
6
+ it { is_expected.not_to be_nil }
7
+ end
8
+ end
9
+
10
+ describe Facemock::FbGraph do
11
+ describe 'BadRequest' do
12
+ subject { Facemock::FbGraph::BadRequest.ancestors }
13
+ it { is_expected.to include ::FbGraph::BadRequest }
14
+ end
15
+
16
+ describe 'Unauthorized' do
17
+ subject { Facemock::FbGraph::Unauthorized.ancestors }
18
+ it { is_expected.to include ::FbGraph::Unauthorized }
19
+ end
20
+
21
+ describe 'NotFound' do
22
+ subject { Facemock::FbGraph::NotFound.ancestors }
23
+ it { is_expected.to include ::FbGraph::NotFound }
24
+ end
25
+
26
+ describe 'InternalServerError' do
27
+ subject { Facemock::FbGraph::InternalServerError.ancestors }
28
+ it { is_expected.to include ::FbGraph::InternalServerError }
29
+ end
30
+
31
+ describe 'InvalidToken' do
32
+ subject { Facemock::FbGraph::InvalidToken.ancestors }
33
+ it { is_expected.to include ::FbGraph::InvalidToken }
34
+ end
35
+
36
+ describe 'InvalidSession' do
37
+ subject { Facemock::FbGraph::InvalidSession.ancestors }
38
+ it { is_expected.to include ::FbGraph::InvalidSession }
39
+ end
40
+
41
+ describe 'InvalidRequest' do
42
+ subject { Facemock::FbGraph::InvalidRequest.ancestors }
43
+ it { is_expected.to include ::FbGraph::InvalidRequest }
44
+ end
45
+
46
+ describe 'CreativeNotSaved' do
47
+ subject { Facemock::FbGraph::CreativeNotSaved.ancestors }
48
+ it { is_expected.to include ::FbGraph::CreativeNotSaved }
49
+ end
50
+
51
+ describe 'QueryLockTimeout' do
52
+ subject { Facemock::FbGraph::QueryLockTimeout.ancestors }
53
+ it { is_expected.to include ::FbGraph::QueryLockTimeout }
54
+ end
55
+
56
+ describe 'TargetingSpecNotSaved' do
57
+ subject { Facemock::FbGraph::TargetingSpecNotSaved.ancestors }
58
+ it { is_expected.to include ::FbGraph::TargetingSpecNotSaved }
59
+ end
60
+
61
+ describe 'AdgroupFetchFailure' do
62
+ subject { Facemock::FbGraph::AdgroupFetchFailure.ancestors }
63
+ it { is_expected.to include ::FbGraph::AdgroupFetchFailure }
64
+ end
65
+
66
+ describe 'OpenProcessFailure' do
67
+ subject { Facemock::FbGraph::OpenProcessFailure.ancestors }
68
+ it { is_expected.to include ::FbGraph::OpenProcessFailure }
69
+ end
70
+
71
+ describe 'TransactionCommitFailure' do
72
+ subject { Facemock::FbGraph::TransactionCommitFailure.ancestors }
73
+ it { is_expected.to include ::FbGraph::TransactionCommitFailure }
74
+ end
75
+
76
+ describe 'QueryError' do
77
+ subject { Facemock::FbGraph::QueryError.ancestors }
78
+ it { is_expected.to include ::FbGraph::QueryError }
79
+ end
80
+
81
+ describe 'QueryConnection' do
82
+ subject { Facemock::FbGraph::QueryConnection.ancestors }
83
+ it { is_expected.to include ::FbGraph::QueryConnection }
84
+ end
85
+
86
+ describe 'QueryDupulicateKey' do
87
+ subject { Facemock::FbGraph::QueryDuplicateKey.ancestors }
88
+ it { is_expected.to include ::FbGraph::QueryDuplicateKey }
89
+ end
90
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Facemock::Database::Permission do
3
+ describe Facemock::Permission do
4
4
  include TableHelper
5
5
 
6
6
  let(:table_name) { :permissions }
@@ -16,29 +16,29 @@ describe Facemock::Database::Permission do
16
16
  after { remove_dynamically_defined_all_method }
17
17
 
18
18
  describe '::TABLE_NAME' do
19
- subject { Facemock::Database::Permission::TABLE_NAME }
19
+ subject { Facemock::Permission::TABLE_NAME }
20
20
  it { is_expected.to eq table_name }
21
21
  end
22
22
 
23
23
  describe '::COLUMN_NAMES' do
24
- subject { Facemock::Database::Permission::COLUMN_NAMES }
24
+ subject { Facemock::Permission::COLUMN_NAMES }
25
25
  it { is_expected.to eq column_names }
26
26
  end
27
27
 
28
28
  describe '::CHILDREN' do
29
- subject { Facemock::Database::Permission::CHILDREN }
29
+ subject { Facemock::Permission::CHILDREN }
30
30
  it { is_expected.to eq children }
31
31
  end
32
32
 
33
33
  describe '#initialize' do
34
34
  context 'without option' do
35
- subject { Facemock::Database::Permission.new }
36
- it { is_expected.to be_kind_of Facemock::Database::Permission }
35
+ subject { Facemock::Permission.new }
36
+ it { is_expected.to be_kind_of Facemock::Permission }
37
37
 
38
38
  context 'then attributes' do
39
39
  it 'should be nil' do
40
40
  column_names.each do |column_name|
41
- value = Facemock::Database::Permission.new.send(column_name)
41
+ value = Facemock::Permission.new.send(column_name)
42
42
  expect(value).to be_nil
43
43
  end
44
44
  end
@@ -46,13 +46,13 @@ describe Facemock::Database::Permission do
46
46
  end
47
47
 
48
48
  context 'with all options' do
49
- subject { Facemock::Database::Permission.new(options) }
50
- it { is_expected.to be_kind_of Facemock::Database::Permission }
49
+ subject { Facemock::Permission.new(options) }
50
+ it { is_expected.to be_kind_of Facemock::Permission }
51
51
 
52
52
  context 'then attributes' do
53
53
  it 'should set specified value by option' do
54
54
  column_names.each do |column_name|
55
- value = Facemock::Database::Permission.new(options).send(column_name)
55
+ value = Facemock::Permission.new(options).send(column_name)
56
56
  expect(value).to eq options[column_name]
57
57
  end
58
58
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Facemock::Database::User do
3
+ describe Facemock::User do
4
4
  include TableHelper
5
5
 
6
6
  let(:db_name) { ".test" }
@@ -13,8 +13,8 @@ describe Facemock::Database::User do
13
13
  :access_token,
14
14
  :application_id,
15
15
  :created_at ] }
16
- let(:children) { [ Facemock::Database::Permission,
17
- Facemock::Database::AuthorizationCode ] }
16
+ let(:children) { [ Facemock::Permission,
17
+ Facemock::AuthorizationCode ] }
18
18
 
19
19
  let(:id) { 1 }
20
20
  let(:name) { "test user" }
@@ -36,91 +36,91 @@ describe Facemock::Database::User do
36
36
  after { remove_dynamically_defined_all_method }
37
37
 
38
38
  describe '::TABLE_NAME' do
39
- subject { Facemock::Database::User::TABLE_NAME }
39
+ subject { Facemock::User::TABLE_NAME }
40
40
  it { is_expected.to eq table_name }
41
41
  end
42
42
 
43
43
  describe '::COLUMN_NAMES' do
44
- subject { Facemock::Database::User::COLUMN_NAMES }
44
+ subject { Facemock::User::COLUMN_NAMES }
45
45
  it { is_expected.to eq column_names }
46
46
  end
47
47
 
48
48
  describe '::CHILDREN' do
49
- subject { Facemock::Database::User::CHILDREN }
49
+ subject { Facemock::User::CHILDREN }
50
50
  it { is_expected.to eq children }
51
51
  end
52
52
 
53
53
  describe '#initialize' do
54
54
  context 'without option' do
55
- subject { Facemock::Database::User.new }
56
- it { is_expected.to be_kind_of Facemock::Database::User }
55
+ subject { Facemock::User.new }
56
+ it { is_expected.to be_kind_of Facemock::User }
57
57
 
58
58
  describe '.id' do
59
- subject { Facemock::Database::User.new.id }
59
+ subject { Facemock::User.new.id }
60
60
  it { is_expected.to be > 0 }
61
61
  it { is_expected.to be < 100010000000000 }
62
62
  end
63
63
 
64
64
  describe '.name' do
65
- subject { Facemock::Database::User.new.name }
65
+ subject { Facemock::User.new.name }
66
66
  it { is_expected.to be_kind_of String }
67
67
 
68
68
  describe '.size' do
69
- subject { Facemock::Database::User.new.name.size }
69
+ subject { Facemock::User.new.name.size }
70
70
  it { is_expected.to be <= 10 }
71
71
  end
72
72
  end
73
73
 
74
74
  describe '.email' do
75
- before { @user = Facemock::Database::User.new }
75
+ before { @user = Facemock::User.new }
76
76
  subject { @user.email }
77
77
  it { is_expected.to be_kind_of String }
78
78
  it { is_expected.to eq "#{@user.name}@example.com" }
79
79
  end
80
80
 
81
81
  describe '.password' do
82
- subject { Facemock::Database::User.new.password }
82
+ subject { Facemock::User.new.password }
83
83
  it { is_expected.to be_kind_of String }
84
84
 
85
85
  describe '.size' do
86
- subject { Facemock::Database::User.new.password.size }
86
+ subject { Facemock::User.new.password.size }
87
87
  it { is_expected.to be <= 10 }
88
88
  end
89
89
  end
90
90
 
91
91
  describe '.installed' do
92
- subject { Facemock::Database::User.new.installed }
92
+ subject { Facemock::User.new.installed }
93
93
  it { is_expected.to eq false }
94
94
  end
95
95
 
96
96
  describe '.access_token' do
97
- subject { Facemock::Database::User.new.access_token }
97
+ subject { Facemock::User.new.access_token }
98
98
  it { is_expected.to be_kind_of String }
99
99
 
100
100
  describe '.size' do
101
- subject { Facemock::Database::User.new.access_token.size }
101
+ subject { Facemock::User.new.access_token.size }
102
102
  it { is_expected.to eq 128 }
103
103
  end
104
104
  end
105
105
 
106
106
  describe '.application_id' do
107
- subject { Facemock::Database::User.new.application_id }
107
+ subject { Facemock::User.new.application_id }
108
108
  it { is_expected.to be_nil }
109
109
  end
110
110
 
111
111
  describe '.created_at' do
112
- subject { Facemock::Database::User.new.created_at }
112
+ subject { Facemock::User.new.created_at }
113
113
  it { is_expected.to be_nil }
114
114
  end
115
115
  end
116
116
 
117
117
  context 'with id option but it is not integer' do
118
118
  before { @opts = { id: "test_id" } }
119
- subject { Facemock::Database::User.new(@opts) }
120
- it { is_expected.to be_kind_of Facemock::Database::User }
119
+ subject { Facemock::User.new(@opts) }
120
+ it { is_expected.to be_kind_of Facemock::User }
121
121
 
122
122
  describe '.id' do
123
- subject { Facemock::Database::User.new(@opts).id }
123
+ subject { Facemock::User.new(@opts).id }
124
124
  it { is_expected.to be > 0 }
125
125
  it { is_expected.to be < 100010000000000 }
126
126
  end
@@ -128,11 +128,11 @@ describe Facemock::Database::User do
128
128
 
129
129
  context 'with application_id option but it is not integer' do
130
130
  before { @opts = { application_id: "test_id" } }
131
- subject { Facemock::Database::User.new(@opts) }
132
- it { is_expected.to be_kind_of Facemock::Database::User }
131
+ subject { Facemock::User.new(@opts) }
132
+ it { is_expected.to be_kind_of Facemock::User }
133
133
 
134
134
  describe '.application_id' do
135
- subject { Facemock::Database::User.new(@opts).application_id }
135
+ subject { Facemock::User.new(@opts).application_id }
136
136
  it { is_expected.to be_nil }
137
137
  end
138
138
  end
@@ -142,28 +142,28 @@ describe Facemock::Database::User do
142
142
  @name = "test user"
143
143
  @opts = { name: @name }
144
144
  end
145
- subject { Facemock::Database::User.new(@opts) }
146
- it { is_expected.to be_kind_of Facemock::Database::User }
145
+ subject { Facemock::User.new(@opts) }
146
+ it { is_expected.to be_kind_of Facemock::User }
147
147
 
148
148
  context '.name' do
149
- subject { Facemock::Database::User.new(@opts).name }
149
+ subject { Facemock::User.new(@opts).name }
150
150
  it { is_expected.to eq @name }
151
151
  end
152
152
 
153
153
  context '.email' do
154
- subject { Facemock::Database::User.new(@opts).email }
154
+ subject { Facemock::User.new(@opts).email }
155
155
  it { is_expected.to eq @name.gsub(" ", "_") + "@example.com" }
156
156
  end
157
157
  end
158
158
 
159
159
  context 'with all options' do
160
- subject { Facemock::Database::User.new(options) }
161
- it { is_expected.to be_kind_of Facemock::Database::User }
160
+ subject { Facemock::User.new(options) }
161
+ it { is_expected.to be_kind_of Facemock::User }
162
162
 
163
163
  context 'then attributes' do
164
164
  it 'should set specified value by option' do
165
165
  column_names.each do |column_name|
166
- value = Facemock::Database::User.new(options).send(column_name)
166
+ value = Facemock::User.new(options).send(column_name)
167
167
  expect(value).to eq options[column_name]
168
168
  end
169
169
  end
@@ -180,19 +180,19 @@ describe Facemock::Database::User do
180
180
 
181
181
  context 'when has permission and authorizaion_code' do
182
182
  before do
183
- application = Facemock::Database::Application.create!
184
- @user = Facemock::Database::User.create!(application_id: application.id)
185
- permission = Facemock::Database::Permission.new(name: "email", user_id: @user.id)
183
+ application = Facemock::Application.create!
184
+ @user = Facemock::User.create!(application_id: application.id)
185
+ permission = Facemock::Permission.new(name: "email", user_id: @user.id)
186
186
  permission.save!
187
- authorization_code = Facemock::Database::AuthorizationCode.new(user_id: @user.id)
187
+ authorization_code = Facemock::AuthorizationCode.new(user_id: @user.id)
188
188
  authorization_code.save!
189
189
  end
190
190
 
191
191
  it 'should delete permissions' do
192
192
  @user.destroy
193
- permissions = Facemock::Database::Permission.find_all_by_user_id(@user.id)
193
+ permissions = Facemock::Permission.find_all_by_user_id(@user.id)
194
194
  expect(permissions).to be_empty
195
- authorization_codes = Facemock::Database::AuthorizationCode.find_all_by_user_id(@user.id)
195
+ authorization_codes = Facemock::AuthorizationCode.find_all_by_user_id(@user.id)
196
196
  expect(authorization_codes).to be_empty
197
197
  end
198
198
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Facemock do
4
- let(:version) { '0.0.7' }
4
+ let(:version) { '0.0.8' }
5
5
  let(:db_name) { '.test' }
6
6
 
7
7
  describe 'VERSION' do
@@ -77,8 +77,8 @@ describe Facemock do
77
77
  before do
78
78
  stub_const("Facemock::Database::DEFAULT_DB_NAME", db_name)
79
79
  @database = Facemock::Database.new
80
- application = Facemock::Database::Application.create!
81
- @user = Facemock::Database::User.create!(application_id: application.id)
80
+ application = Facemock::Application.create!
81
+ @user = Facemock::User.create!(application_id: application.id)
82
82
  @access_token = @user.access_token
83
83
  end
84
84
  after { @database.drop }
@@ -1,5 +1,5 @@
1
1
  module ApplicationCreateHelper
2
2
  def create_application(options={})
3
- Facemock::Database::Application.create!(options)
3
+ Facemock::Application.create!(options)
4
4
  end
5
5
  end
@@ -1,10 +1,10 @@
1
1
  module TableHelper
2
2
  def remove_dynamically_defined_all_method
3
3
  klasses = [Facemock::Database::Table,
4
- Facemock::Database::Application,
5
- Facemock::Database::User,
6
- Facemock::Database::Permission,
7
- Facemock::Database::AuthorizationCode ]
4
+ Facemock::Application,
5
+ Facemock::User,
6
+ Facemock::Permission,
7
+ Facemock::AuthorizationCode ]
8
8
  klasses.each do |klass|
9
9
  remove_dynamically_defined_class_method(klass)
10
10
  remove_dynamically_defined_instance_method(klass)
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.7
4
+ version: 0.0.8
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-09-03 00:00:00.000000000 Z
12
+ date: 2014-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sqlite3
@@ -190,36 +190,38 @@ files:
190
190
  - db/.gitkeep
191
191
  - facemock.gemspec
192
192
  - lib/facemock.rb
193
+ - lib/facemock/application.rb
193
194
  - lib/facemock/auth_hash.rb
195
+ - lib/facemock/authorization_code.rb
194
196
  - lib/facemock/config.rb
195
197
  - lib/facemock/database.rb
196
- - lib/facemock/database/application.rb
197
- - lib/facemock/database/authorization_code.rb
198
- - lib/facemock/database/permission.rb
199
198
  - lib/facemock/database/table.rb
200
- - lib/facemock/database/user.rb
201
199
  - lib/facemock/errors.rb
202
200
  - lib/facemock/fb_graph.rb
203
201
  - lib/facemock/fb_graph/application.rb
204
202
  - lib/facemock/fb_graph/application/test_users.rb
205
203
  - lib/facemock/fb_graph/application/user.rb
206
204
  - lib/facemock/fb_graph/application/user/permission.rb
205
+ - lib/facemock/fb_graph/exception.rb
207
206
  - lib/facemock/fb_graph/user.rb
207
+ - lib/facemock/permission.rb
208
+ - lib/facemock/user.rb
208
209
  - lib/facemock/version.rb
210
+ - spec/facemock/application_spec.rb
209
211
  - spec/facemock/auth_hash_spec.rb
210
212
  - spec/facemock/config_spec.rb
211
- - spec/facemock/database/application_spec.rb
212
213
  - spec/facemock/database/authorization_code.rb
213
- - spec/facemock/database/permission_spec.rb
214
214
  - spec/facemock/database/table_spec.rb
215
- - spec/facemock/database/user_spec.rb
216
215
  - spec/facemock/database_spec.rb
217
216
  - spec/facemock/errors_spec.rb
218
217
  - spec/facemock/fb_graph/application/test_users_spec.rb
219
218
  - spec/facemock/fb_graph/application/user_spec.rb
220
219
  - spec/facemock/fb_graph/application_spec.rb
220
+ - spec/facemock/fb_graph/exeption_spec.rb
221
221
  - spec/facemock/fb_graph/user_spec.rb
222
222
  - spec/facemock/fb_graph_spec.rb
223
+ - spec/facemock/permission_spec.rb
224
+ - spec/facemock/user_spec.rb
223
225
  - spec/facemock_spec.rb
224
226
  - spec/spec_helper.rb
225
227
  - spec/support/application_create_helper.rb
@@ -239,7 +241,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
239
241
  version: '0'
240
242
  segments:
241
243
  - 0
242
- hash: -2537604812428127045
244
+ hash: 1294869249957825564
243
245
  required_rubygems_version: !ruby/object:Gem::Requirement
244
246
  none: false
245
247
  requirements:
@@ -248,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
248
250
  version: '0'
249
251
  segments:
250
252
  - 0
251
- hash: -2537604812428127045
253
+ hash: 1294869249957825564
252
254
  requirements: []
253
255
  rubyforge_project:
254
256
  rubygems_version: 1.8.25
@@ -256,20 +258,21 @@ signing_key:
256
258
  specification_version: 3
257
259
  summary: This is facebook mock application for fb_graph.
258
260
  test_files:
261
+ - spec/facemock/application_spec.rb
259
262
  - spec/facemock/auth_hash_spec.rb
260
263
  - spec/facemock/config_spec.rb
261
- - spec/facemock/database/application_spec.rb
262
264
  - spec/facemock/database/authorization_code.rb
263
- - spec/facemock/database/permission_spec.rb
264
265
  - spec/facemock/database/table_spec.rb
265
- - spec/facemock/database/user_spec.rb
266
266
  - spec/facemock/database_spec.rb
267
267
  - spec/facemock/errors_spec.rb
268
268
  - spec/facemock/fb_graph/application/test_users_spec.rb
269
269
  - spec/facemock/fb_graph/application/user_spec.rb
270
270
  - spec/facemock/fb_graph/application_spec.rb
271
+ - spec/facemock/fb_graph/exeption_spec.rb
271
272
  - spec/facemock/fb_graph/user_spec.rb
272
273
  - spec/facemock/fb_graph_spec.rb
274
+ - spec/facemock/permission_spec.rb
275
+ - spec/facemock/user_spec.rb
273
276
  - spec/facemock_spec.rb
274
277
  - spec/spec_helper.rb
275
278
  - spec/support/application_create_helper.rb
@@ -1,20 +0,0 @@
1
- require 'facemock/database/table'
2
- require 'facemock/database/user'
3
-
4
- module Facemock
5
- class Database
6
- class Application < Table
7
- TABLE_NAME = :applications
8
- COLUMN_NAMES = [:id, :secret, :created_at]
9
- CHILDREN = [ User ]
10
-
11
- # WANT : DBに登録済みの値と重複しないようにする(id, secret)
12
- def initialize(options={})
13
- opts = Hashie::Mash.new(options)
14
- @id = ( opts.id.to_i > 0 ) ? opts.id.to_i : (0..9).to_a.shuffle[0..15].join.to_i
15
- @secret = opts.secret || rand(36**32).to_s(36)
16
- @created_at = opts.created_at
17
- end
18
- end
19
- end
20
- end
@@ -1,18 +0,0 @@
1
- require 'facemock/database/table'
2
-
3
- module Facemock
4
- class Database
5
- class AuthorizationCode < Table
6
- TABLE_NAME = :authorization_codes
7
- COLUMN_NAMES = [:id, :string, :user_id, :created_at]
8
-
9
- def initialize(options={})
10
- opts = Hashie::Mash.new(options)
11
- @id = opts.id
12
- @string = opts.string || rand(36**255).to_s(36)
13
- @user_id = opts.user_id
14
- @created_at = opts.created_at
15
- end
16
- end
17
- end
18
- end
@@ -1,18 +0,0 @@
1
- require 'facemock/database/table'
2
-
3
- module Facemock
4
- class Database
5
- class Permission < Table
6
- TABLE_NAME = :permissions
7
- COLUMN_NAMES = [:id, :name, :user_id, :created_at]
8
-
9
- def initialize(options={})
10
- opts = Hashie::Mash.new(options)
11
- @id = opts.id
12
- @name = opts.name
13
- @user_id = opts.user_id
14
- @created_at = opts.created_at
15
- end
16
- end
17
- end
18
- end
@@ -1,26 +0,0 @@
1
- require 'facemock/database/table'
2
- require 'facemock/database/permission'
3
- require 'facemock/database/authorization_code'
4
-
5
- module Facemock
6
- class Database
7
- class User < Table
8
- TABLE_NAME = :users
9
- COLUMN_NAMES = [:id, :name, :email, :password, :installed, :access_token, :application_id, :created_at]
10
- CHILDREN = [ Permission, AuthorizationCode ]
11
-
12
- def initialize(options={})
13
- opts = Hashie::Mash.new(options)
14
- @id = (opts.id.to_i > 0) ? opts.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)
18
- @installed = opts.installed || false
19
- @access_token = opts.access_token || Digest::SHA512.hexdigest(identifier.to_s)
20
- app_id = opts.application_id.to_i
21
- @application_id = (app_id > 0) ? app_id : nil
22
- @created_at = opts.created_at
23
- end
24
- end
25
- end
26
- end