facemock 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- metadata +4 -70
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -22
- data/.rspec +0 -2
- data/.travis.yml +0 -6
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/README.md +0 -154
- data/Rakefile +0 -6
- data/db/.gitkeep +0 -0
- data/facemock.gemspec +0 -32
- data/lib/facemock/config/database.rb +0 -99
- data/lib/facemock/config.rb +0 -92
- data/lib/facemock/errors.rb +0 -6
- data/lib/facemock/fb_graph/application/test_users.rb +0 -36
- data/lib/facemock/fb_graph/application/user/right.rb +0 -14
- data/lib/facemock/fb_graph/application/user.rb +0 -68
- data/lib/facemock/fb_graph/application.rb +0 -44
- data/lib/facemock/fb_graph/errors.rb +0 -11
- data/lib/facemock/fb_graph/user.rb +0 -14
- data/lib/facemock/fb_graph.rb +0 -36
- data/lib/facemock/version.rb +0 -3
- data/lib/facemock.rb +0 -15
- data/spec/facemock/config/database_spec.rb +0 -220
- data/spec/facemock/config_spec.rb +0 -195
- data/spec/facemock/fb_graph/application/test_users_spec.rb +0 -159
- data/spec/facemock/fb_graph/application/user/right_spec.rb +0 -10
- data/spec/facemock/fb_graph/application/user_spec.rb +0 -131
- data/spec/facemock/fb_graph/application_spec.rb +0 -140
- data/spec/facemock/fb_graph/errors_spec.rb +0 -13
- data/spec/facemock/fb_graph/user_spec.rb +0 -39
- data/spec/facemock/fb_graph_spec.rb +0 -54
- data/spec/facemock_spec.rb +0 -72
- data/spec/spec_helper.rb +0 -15
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
require 'hashie'
|
3
|
-
require 'facemock/config'
|
4
|
-
require 'facemock/fb_graph/application/user'
|
5
|
-
require 'facemock/fb_graph/application/test_users'
|
6
|
-
|
7
|
-
module Facemock
|
8
|
-
module FbGraph
|
9
|
-
class Application < ActiveRecord::Base
|
10
|
-
alias_attribute :identifier, :id
|
11
|
-
has_many :users, :dependent => :destroy
|
12
|
-
|
13
|
-
def initialize(identifier, options={})
|
14
|
-
opts = Hashie::Mash.new(options)
|
15
|
-
if (identifier == :app && opts.access_token)
|
16
|
-
identifier = (0..9).to_a.shuffle[0..15].join
|
17
|
-
secret = opts.access_token
|
18
|
-
else
|
19
|
-
identifer = identifier.to_s
|
20
|
-
secret = opts.secret || rand(36**32).to_s(36)
|
21
|
-
end
|
22
|
-
|
23
|
-
super(secret: secret)
|
24
|
-
self.identifier = identifier
|
25
|
-
save! unless Application.find_by_id_and_secret(identifier, secret)
|
26
|
-
end
|
27
|
-
|
28
|
-
def fetch
|
29
|
-
self
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_user!(options={})
|
33
|
-
user = User.new(options)
|
34
|
-
user.application_id = self.identifier
|
35
|
-
user.save!
|
36
|
-
user
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_users(options={})
|
40
|
-
TestUsers.new(self.identifier, options)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/lib/facemock/fb_graph.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'fb_graph'
|
2
|
-
require 'facemock/config'
|
3
|
-
require 'facemock/fb_graph/user'
|
4
|
-
require 'facemock/fb_graph/errors'
|
5
|
-
require 'facemock/fb_graph/application'
|
6
|
-
|
7
|
-
module Facemock
|
8
|
-
module FbGraph
|
9
|
-
extend self
|
10
|
-
|
11
|
-
def on(options={})
|
12
|
-
if ::FbGraph != Facemock::FbGraph
|
13
|
-
Object.const_set(:SourceFbGraph, ::FbGraph)
|
14
|
-
Object.send(:remove_const, :FbGraph) if Object.constants.include?(:FbGraph)
|
15
|
-
Object.const_set(:FbGraph, Facemock::FbGraph)
|
16
|
-
end
|
17
|
-
|
18
|
-
if options[:database_name]
|
19
|
-
Facemock::Config.database(options[:database_name])
|
20
|
-
else
|
21
|
-
Facemock::Config.database
|
22
|
-
end
|
23
|
-
true
|
24
|
-
end
|
25
|
-
|
26
|
-
def off
|
27
|
-
if ::FbGraph == Facemock::FbGraph
|
28
|
-
Object.send(:remove_const, :FbGraph) if Object.constants.include?(:FbGraph)
|
29
|
-
Object.const_set(:FbGraph, ::SourceFbGraph)
|
30
|
-
Object.send(:remove_const, :SourceFbGraph) if Object.constants.include?(:FbGraph)
|
31
|
-
end
|
32
|
-
Facemock::Config.reset_database
|
33
|
-
true
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/facemock/version.rb
DELETED
data/lib/facemock.rb
DELETED
@@ -1,220 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Facemock::Config::Database do
|
4
|
-
let(:default_db_name) { "facemock" }
|
5
|
-
let(:adapter) { "sqlite3" }
|
6
|
-
let(:table_names) { [:applications, :users, :user_rights] }
|
7
|
-
let(:db_directory) { File.expand_path("../../../../db", __FILE__) }
|
8
|
-
let(:db_filepath) { File.join(db_directory, "#{db_name}.#{adapter}") }
|
9
|
-
|
10
|
-
let(:db_name) { ".test" }
|
11
|
-
|
12
|
-
describe '::ADAPTER' do
|
13
|
-
subject { Facemock::Config::Database::ADAPTER }
|
14
|
-
it { is_expected.to eq adapter }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '::DB_DIRECTORY' do
|
18
|
-
subject { Facemock::Config::Database::DB_DIRECTORY }
|
19
|
-
it { is_expected.to eq db_directory }
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '::TABLE_NAMES' do
|
23
|
-
subject { Facemock::Config::Database::TABLE_NAMES }
|
24
|
-
it { is_expected.to eq table_names }
|
25
|
-
end
|
26
|
-
|
27
|
-
describe '::DEFAULT_DB_NAMES' do
|
28
|
-
subject { Facemock::Config::Database::DEFAULT_DB_NAME }
|
29
|
-
it { is_expected.to eq default_db_name }
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#initialize' do
|
33
|
-
before do
|
34
|
-
allow_any_instance_of(Facemock::Config::Database).to receive(:connect) { true }
|
35
|
-
allow_any_instance_of(Facemock::Config::Database).to receive(:create_tables) { true }
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'with database name' do
|
39
|
-
subject { lambda { Facemock::Config::Database.new(db_name) } }
|
40
|
-
it { is_expected.not_to raise_error }
|
41
|
-
|
42
|
-
describe '.name' do
|
43
|
-
subject { Facemock::Config::Database.new(db_name).name }
|
44
|
-
it { is_expected.to eq db_name }
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'without argument' do
|
49
|
-
subject { lambda { Facemock::Config::Database.new } }
|
50
|
-
it { is_expected.not_to raise_error }
|
51
|
-
|
52
|
-
describe '.name' do
|
53
|
-
subject { Facemock::Config::Database.new.name }
|
54
|
-
it { is_expected.to eq default_db_name }
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'with nil or "" or default database name' do
|
59
|
-
[nil, "", "facemock"].each do |argument|
|
60
|
-
subject { lambda { Facemock::Config::Database.new(argument) } }
|
61
|
-
it { is_expected.not_to raise_error }
|
62
|
-
|
63
|
-
describe '.name' do
|
64
|
-
subject { Facemock::Config::Database.new(argument).name }
|
65
|
-
it { is_expected.to eq default_db_name }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe '#connect' do
|
72
|
-
before do
|
73
|
-
allow_any_instance_of(Facemock::Config::Database).to receive(:create_tables) { true }
|
74
|
-
stub_const("Facemock::Config::Database::DEFAULT_DB_NAME", db_name)
|
75
|
-
@database = Facemock::Config.database
|
76
|
-
end
|
77
|
-
|
78
|
-
subject { lambda { @database.connect } }
|
79
|
-
it { is_expected.not_to raise_error }
|
80
|
-
it { expect(ActiveRecord::Base.connected?).to eq true }
|
81
|
-
it { expect(File.exist?(@database.filepath)).to eq true }
|
82
|
-
|
83
|
-
after { Facemock::Config.database.drop }
|
84
|
-
end
|
85
|
-
|
86
|
-
describe '#disconnect' do
|
87
|
-
before do
|
88
|
-
allow_any_instance_of(Facemock::Config::Database).to receive(:create_tables) { true }
|
89
|
-
stub_const("Facemock::Config::Database::DEFAULT_DB_NAME", db_name)
|
90
|
-
@database = Facemock::Config.database
|
91
|
-
end
|
92
|
-
|
93
|
-
subject { lambda { @database.disconnect! } }
|
94
|
-
it { is_expected.not_to raise_error }
|
95
|
-
|
96
|
-
context 'when success' do
|
97
|
-
describe 'datbase file is not removed' do
|
98
|
-
before { @database.disconnect! }
|
99
|
-
it { expect(File.exist?(@database.filepath)).to eq true }
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
after { Facemock::Config.database.drop }
|
104
|
-
end
|
105
|
-
|
106
|
-
describe '#drop' do
|
107
|
-
before do
|
108
|
-
allow_any_instance_of(Facemock::Config::Database).to receive(:create_tables) { true }
|
109
|
-
stub_const("Facemock::Config::Database::DEFAULT_DB_NAME", db_name)
|
110
|
-
@database = Facemock::Config.database
|
111
|
-
end
|
112
|
-
|
113
|
-
subject { lambda { @database.drop } }
|
114
|
-
it { is_expected.not_to raise_error }
|
115
|
-
|
116
|
-
context 'when success' do
|
117
|
-
describe 'database file does not exist' do
|
118
|
-
before { @database.drop }
|
119
|
-
it { expect(File.exist?(@database.filepath)).to eq false }
|
120
|
-
end
|
121
|
-
|
122
|
-
describe 're-drop is success' do
|
123
|
-
before { @database.drop }
|
124
|
-
subject { lambda { @database.drop } }
|
125
|
-
it { is_expected.not_to raise_error }
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
after { Facemock::Config.database.drop }
|
130
|
-
end
|
131
|
-
|
132
|
-
describe '#clear' do
|
133
|
-
before do
|
134
|
-
allow_any_instance_of(Facemock::Config::Database).to receive(:create_tables) { true }
|
135
|
-
stub_const("Facemock::Config::Database::DEFAULT_DB_NAME", db_name)
|
136
|
-
@database = Facemock::Config.database
|
137
|
-
expect(@database).to receive(:drop_tables)
|
138
|
-
expect(@database).to receive(:create_tables)
|
139
|
-
end
|
140
|
-
|
141
|
-
subject { @database.clear }
|
142
|
-
it { is_expected.to be_truthy }
|
143
|
-
|
144
|
-
after { Facemock::Config.database.drop }
|
145
|
-
end
|
146
|
-
|
147
|
-
describe '#create_tables' do
|
148
|
-
before do
|
149
|
-
stub_const("Facemock::Config::Database::DEFAULT_DB_NAME", db_name)
|
150
|
-
@database = Facemock::Config.database
|
151
|
-
@database.drop_tables
|
152
|
-
end
|
153
|
-
|
154
|
-
subject { lambda { @database.create_tables } }
|
155
|
-
it { is_expected.not_to raise_error }
|
156
|
-
|
157
|
-
after { Facemock::Config.database.drop }
|
158
|
-
end
|
159
|
-
|
160
|
-
describe '#drop_tables' do
|
161
|
-
before do
|
162
|
-
stub_const("Facemock::Config::Database::DEFAULT_DB_NAME", db_name)
|
163
|
-
@database = Facemock::Config.database
|
164
|
-
end
|
165
|
-
|
166
|
-
subject { lambda { @database.drop_tables } }
|
167
|
-
it { is_expected.not_to raise_error }
|
168
|
-
|
169
|
-
after { Facemock::Config.database.drop }
|
170
|
-
end
|
171
|
-
|
172
|
-
describe '#filepath' do
|
173
|
-
before do
|
174
|
-
stub_const("Facemock::Config::Database::DEFAULT_DB_NAME", db_name)
|
175
|
-
@database = Facemock::Config.database
|
176
|
-
end
|
177
|
-
|
178
|
-
subject { @database.filepath }
|
179
|
-
it { is_expected.to eq db_filepath }
|
180
|
-
|
181
|
-
context 'then database file is exist' do
|
182
|
-
subject { File.exist? @database.filepath }
|
183
|
-
it { is_expected.to eq true }
|
184
|
-
end
|
185
|
-
|
186
|
-
after { Facemock::Config.database.drop }
|
187
|
-
end
|
188
|
-
|
189
|
-
describe '#connected?' do
|
190
|
-
before do
|
191
|
-
stub_const("Facemock::Config::Database::DEFAULT_DB_NAME", db_name)
|
192
|
-
@database = Facemock::Config.database
|
193
|
-
end
|
194
|
-
after { Facemock::Config.database.drop }
|
195
|
-
|
196
|
-
context 'after new' do
|
197
|
-
subject { @database.connected? }
|
198
|
-
it { is_expected.to eq true }
|
199
|
-
end
|
200
|
-
|
201
|
-
context 'after disconnect!' do
|
202
|
-
before do
|
203
|
-
@database.disconnect!
|
204
|
-
end
|
205
|
-
|
206
|
-
subject { @database.connected? }
|
207
|
-
it { is_expected.to eq false }
|
208
|
-
end
|
209
|
-
|
210
|
-
context 'after connect' do
|
211
|
-
before do
|
212
|
-
@database.disconnect!
|
213
|
-
@database.connect
|
214
|
-
end
|
215
|
-
|
216
|
-
subject { @database.connected? }
|
217
|
-
it { is_expected.to eq true }
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
@@ -1,195 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'tempfile'
|
3
|
-
|
4
|
-
describe Facemock::Config do
|
5
|
-
let(:db_name) { ".test" }
|
6
|
-
let(:ymlfile) { "testdata.yml" }
|
7
|
-
|
8
|
-
it 'should have a database module' do
|
9
|
-
expect(Facemock::Config::Database).to be_truthy
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#default_database' do
|
13
|
-
before do
|
14
|
-
allow_any_instance_of(Facemock::Config::Database).to receive(:connect) { true }
|
15
|
-
allow_any_instance_of(Facemock::Config::Database).to receive(:create_tables) { true }
|
16
|
-
allow_any_instance_of(Facemock::Config::Database).to receive(:disconnect!) { true }
|
17
|
-
end
|
18
|
-
|
19
|
-
subject { Facemock::Config.default_database }
|
20
|
-
it { is_expected.to be_truthy }
|
21
|
-
|
22
|
-
describe '.name' do
|
23
|
-
subject { Facemock::Config.default_database.name }
|
24
|
-
it { is_expected.not_to be_nil }
|
25
|
-
it { is_expected.not_to be_empty }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#database' do
|
30
|
-
before do
|
31
|
-
allow_any_instance_of(Facemock::Config::Database).to receive(:connect) { true }
|
32
|
-
allow_any_instance_of(Facemock::Config::Database).to receive(:create_tables) { true }
|
33
|
-
allow_any_instance_of(Facemock::Config::Database).to receive(:disconnect!) { true }
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'without argument' do
|
37
|
-
subject { Facemock::Config.database }
|
38
|
-
it { is_expected.to be_truthy }
|
39
|
-
|
40
|
-
describe '.name' do
|
41
|
-
subject { Facemock::Config.database.name }
|
42
|
-
it { is_expected.not_to be_nil }
|
43
|
-
it { is_expected.not_to be_empty }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'with name options' do
|
48
|
-
subject { Facemock::Config.database(db_name) }
|
49
|
-
it { is_expected.to be_truthy }
|
50
|
-
|
51
|
-
describe '.name' do
|
52
|
-
subject { Facemock::Config.database(db_name).name }
|
53
|
-
it { is_expected.to eq db_name }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe '#reset_database' do
|
59
|
-
context 'when does not set database' do
|
60
|
-
subject { Facemock::Config.reset_database }
|
61
|
-
it { is_expected.to eq nil }
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'when already set database' do
|
65
|
-
before do
|
66
|
-
stub_const("Facemock::Config::Database::DEFAULT_DATABASE_NAME", db_name)
|
67
|
-
Facemock::Config.database
|
68
|
-
end
|
69
|
-
|
70
|
-
subject { Facemock::Config.reset_database }
|
71
|
-
it { is_expected.to eq nil }
|
72
|
-
|
73
|
-
after { Facemock::Config.database.drop }
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe '#load_users' do
|
78
|
-
let(:user1) { { identifier: "100000000000001",
|
79
|
-
name: "test user one",
|
80
|
-
email: "test_user_one@example.com",
|
81
|
-
password: "testpass" } }
|
82
|
-
let(:user2) { { identifier: "100000000000002",
|
83
|
-
name: "test user two",
|
84
|
-
email: "test_user_two@example.com",
|
85
|
-
password: "testpass" } }
|
86
|
-
let(:user3) { { identifier: 100000000000003,
|
87
|
-
name: "test user three",
|
88
|
-
email: "test_user_three@example.com",
|
89
|
-
password: "testpass" } }
|
90
|
-
|
91
|
-
let(:app1_id) { "000000000000001" }
|
92
|
-
let(:app1_secret) { "test_secret_one" }
|
93
|
-
let(:app1_users) { [user1, user2] }
|
94
|
-
let(:app1) { { app_id: app1_id, app_secret: app1_secret, users: app1_users } }
|
95
|
-
|
96
|
-
let(:app2_id) { 000000000000002 }
|
97
|
-
let(:app2_secret) { "test_secret_two" }
|
98
|
-
let(:app2_users) { [user3] }
|
99
|
-
let(:app2) { { app_id: app2_id, app_secret: app2_secret, users: app2_users } }
|
100
|
-
|
101
|
-
let(:yaml_load_data) { [ app1, app2 ] }
|
102
|
-
|
103
|
-
context 'without argument' do
|
104
|
-
subject { lambda { Facemock::Config.load_users } }
|
105
|
-
it { is_expected.to raise_error ArgumentError }
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'with yaml file path' do
|
109
|
-
before do
|
110
|
-
stub_const("Facemock::Config::Database::DEFAULT_DB_NAME", db_name)
|
111
|
-
Facemock::Config.database
|
112
|
-
end
|
113
|
-
after { Facemock::Config.database.drop }
|
114
|
-
|
115
|
-
context 'but file does not exist' do
|
116
|
-
subject { lambda { Facemock::Config.load_users("testdata.yml") } }
|
117
|
-
it { is_expected.to raise_error Errno::ENOENT }
|
118
|
-
end
|
119
|
-
|
120
|
-
def create_temporary_yaml_file(data)
|
121
|
-
path = Tempfile.open(ymlfile) do |tempfile|
|
122
|
-
tempfile.puts YAML.dump(data)
|
123
|
-
tempfile.path
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
shared_context 'app and user should not be created', assert: :incorrect_data_format do
|
128
|
-
subject { lambda { Facemock::Config.load_users(@path) } }
|
129
|
-
it { is_expected.to raise_error Facemock::Errors::IncorrectDataFormat }
|
130
|
-
|
131
|
-
it 'app and user should not be created' do
|
132
|
-
begin
|
133
|
-
Facemock::Config.load_users(@path)
|
134
|
-
rescue => error
|
135
|
-
expect(Facemock::FbGraph::Application.all).to be_empty
|
136
|
-
expect(Facemock::FbGraph::Application::User.all).to be_empty
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
context 'but incorrect format' do
|
142
|
-
context 'when load data is not array', assert: :incorrect_data_format do
|
143
|
-
before do
|
144
|
-
users_data = ""
|
145
|
-
@path = create_temporary_yaml_file(users_data)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context 'when app id does not exist', assert: :incorrect_data_format do
|
150
|
-
before do
|
151
|
-
users_data = [ { app_secret: app1_secret, users: app1_users } ]
|
152
|
-
@path = create_temporary_yaml_file(users_data)
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
context 'when app secret does not exist', assert: :incorrect_data_format do
|
157
|
-
before do
|
158
|
-
users_data = [ { app_id: app1_id, users: app1_users } ]
|
159
|
-
@path = create_temporary_yaml_file(users_data)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
context 'when users does not exist', assert: :incorrect_data_format do
|
164
|
-
before do
|
165
|
-
users_data = [ { app_id: app1_id, app_secret: app1_secret } ]
|
166
|
-
@path = create_temporary_yaml_file(users_data)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context 'when users have only identifier', assert: :incorrect_data_format do
|
171
|
-
before do
|
172
|
-
users_data = [ { app_id: app1_id, app_secret: app1_secret,
|
173
|
-
users: [ { identifier: "100000000000001" } ] } ]
|
174
|
-
@path = create_temporary_yaml_file(users_data)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
context 'yaml is correct format' do
|
180
|
-
before { @path = create_temporary_yaml_file(yaml_load_data) }
|
181
|
-
|
182
|
-
subject { lambda { Facemock::Config.load_users(@path) } }
|
183
|
-
it { is_expected.not_to raise_error }
|
184
|
-
|
185
|
-
it 'app and user should be created' do
|
186
|
-
app_count = yaml_load_data.size
|
187
|
-
user_count = yaml_load_data.inject(0){|count, data| count += data[:users].size }
|
188
|
-
Facemock::Config.load_users(@path)
|
189
|
-
expect(Facemock::FbGraph::Application.all.count).to eq app_count
|
190
|
-
expect(Facemock::FbGraph::Application::User.all.count).to eq user_count
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
@@ -1,159 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Facemock::FbGraph::Application::TestUsers do
|
4
|
-
let(:default_limit) { 50 }
|
5
|
-
let(:default_after) { 0 }
|
6
|
-
|
7
|
-
let(:db_name) { ".test" }
|
8
|
-
let(:adapter) { "sqlite3" }
|
9
|
-
let(:db_directory) { File.expand_path("../../../../db", __FILE__) }
|
10
|
-
let(:db_filepath) { File.join(db_directory, "#{db_name}.#{adapter}") }
|
11
|
-
let(:facebook_app_id) { "100000000000000" }
|
12
|
-
|
13
|
-
before do
|
14
|
-
stub_const("Facemock::Config::Database::DEFAULT_DB_NAME", db_name)
|
15
|
-
Facemock::Config.database
|
16
|
-
end
|
17
|
-
after { Facemock::Config.database.drop }
|
18
|
-
|
19
|
-
describe '::DEFAULT_LIMIT' do
|
20
|
-
subject { Facemock::FbGraph::Application::TestUsers::DEFAULT_LIMIT }
|
21
|
-
it { is_expected.to eq default_limit }
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '::DEFAULT_AFTER' do
|
25
|
-
subject { Facemock::FbGraph::Application::TestUsers::DEFAULT_AFTER }
|
26
|
-
it { is_expected.to eq default_after }
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#new' do
|
30
|
-
context 'without argument' do
|
31
|
-
subject { lambda { Facemock::FbGraph::Application::TestUsers.new } }
|
32
|
-
it { is_expected.to raise_error ArgumentError }
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'with application id' do
|
36
|
-
subject { Facemock::FbGraph::Application::TestUsers.new(facebook_app_id) }
|
37
|
-
it { is_expected.to be_kind_of Array }
|
38
|
-
|
39
|
-
context 'when user does not exist' do
|
40
|
-
subject { Facemock::FbGraph::Application::TestUsers.new(facebook_app_id) }
|
41
|
-
it { is_expected.to be_empty }
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'when user exist only one' do
|
45
|
-
before do
|
46
|
-
@user = Facemock::FbGraph::Application::User.new(application_id: facebook_app_id)
|
47
|
-
@user.save!
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should have user' do
|
51
|
-
test_users = Facemock::FbGraph::Application::TestUsers.new(facebook_app_id)
|
52
|
-
expect(test_users).not_to be_empty
|
53
|
-
expect(test_users).to include @user
|
54
|
-
expect(test_users.count).to eq 1
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'with application id and options' do
|
60
|
-
context 'that limit is 1' do
|
61
|
-
context 'when user is exist only two' do
|
62
|
-
before do
|
63
|
-
user = Facemock::FbGraph::Application::User.new(application_id: facebook_app_id)
|
64
|
-
user.save!
|
65
|
-
@last_created_user = Facemock::FbGraph::Application::User.new(application_id: facebook_app_id)
|
66
|
-
@last_created_user.save!
|
67
|
-
@limit = 1
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'should have only one user' do
|
71
|
-
test_users = Facemock::FbGraph::Application::TestUsers.new(facebook_app_id, limit: @limit)
|
72
|
-
expect(test_users).not_to be_empty
|
73
|
-
expect(test_users.count).to eq 1
|
74
|
-
expect(test_users).to include @last_created_user
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context 'that after is 1' do
|
80
|
-
context 'when user is exist only two' do
|
81
|
-
before do
|
82
|
-
@first_created_user = Facemock::FbGraph::Application::User.new(application_id: facebook_app_id)
|
83
|
-
@first_created_user.save!
|
84
|
-
user = Facemock::FbGraph::Application::User.new(application_id: facebook_app_id)
|
85
|
-
user.save!
|
86
|
-
@after = 1
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should have only one user' do
|
90
|
-
test_users = Facemock::FbGraph::Application::TestUsers.new(facebook_app_id, after: @after)
|
91
|
-
expect(test_users).not_to be_empty
|
92
|
-
expect(test_users.count).to eq 1
|
93
|
-
expect(test_users).to include @first_created_user
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'that limit and after are both 1' do
|
99
|
-
context 'when user is exist only three' do
|
100
|
-
before do
|
101
|
-
user = Facemock::FbGraph::Application::User.new(application_id: facebook_app_id)
|
102
|
-
user.save!
|
103
|
-
@second_created_user = Facemock::FbGraph::Application::User.new(application_id: facebook_app_id)
|
104
|
-
@second_created_user.save!
|
105
|
-
user = Facemock::FbGraph::Application::User.new(application_id: facebook_app_id)
|
106
|
-
user.save!
|
107
|
-
@options = { limit: 1, after: 1 }
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'should have only one user' do
|
111
|
-
test_users = Facemock::FbGraph::Application::TestUsers.new(facebook_app_id, @options)
|
112
|
-
expect(test_users).not_to be_empty
|
113
|
-
expect(test_users.count).to eq 1
|
114
|
-
expect(test_users).to include @second_created_user
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe '#collection' do
|
122
|
-
before do
|
123
|
-
user = Facemock::FbGraph::Application::User.new(application_id: facebook_app_id)
|
124
|
-
user.save!
|
125
|
-
@test_users = Facemock::FbGraph::Application::TestUsers.new(facebook_app_id)
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'should equal self' do
|
129
|
-
collection = @test_users.collection
|
130
|
-
expect(collection.first).to eq @test_users.first
|
131
|
-
expect(collection.count).to eq @test_users.count
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe '#next' do
|
136
|
-
before do
|
137
|
-
@first_created_user = Facemock::FbGraph::Application::User.new(application_id: facebook_app_id)
|
138
|
-
@first_created_user.save!
|
139
|
-
@second_created_user = Facemock::FbGraph::Application::User.new(application_id: facebook_app_id)
|
140
|
-
@second_created_user.save!
|
141
|
-
@last_created_user = Facemock::FbGraph::Application::User.new(application_id: facebook_app_id)
|
142
|
-
@last_created_user.save!
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'should get next users array' do
|
146
|
-
test_users = Facemock::FbGraph::Application::TestUsers.new(facebook_app_id, limit: 1)
|
147
|
-
expect(test_users.first).to eq @last_created_user
|
148
|
-
expect(test_users.next.first).to eq @second_created_user
|
149
|
-
expect(test_users.next.next.first).to eq @first_created_user
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
describe '#select' do
|
154
|
-
before { @expected = { limit: default_limit, after: default_after } }
|
155
|
-
|
156
|
-
subject { Facemock::FbGraph::Application::TestUsers.new(facebook_app_id).select }
|
157
|
-
it { is_expected.to eq @expected }
|
158
|
-
end
|
159
|
-
end
|