influxdb-api 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +14 -0
- data/README.md +2 -0
- data/influxdb/Dockerfile.0.7.3 +8 -0
- data/influxdb/Dockerfile.0.8.3 +8 -0
- data/influxdb/Dockerfile.0.8.8 +8 -0
- data/lib/influxdb/api.rb +3 -0
- data/lib/influxdb/api/client.rb +5 -1
- data/lib/influxdb/api/database.rb +14 -2
- data/lib/influxdb/api/namespaces/base.rb +7 -0
- data/lib/influxdb/api/namespaces/cluster_admins.rb +4 -0
- data/lib/influxdb/api/namespaces/continuous_queries.rb +28 -4
- data/lib/influxdb/api/namespaces/databases.rb +4 -0
- data/lib/influxdb/api/namespaces/series.rb +3 -0
- data/lib/influxdb/api/namespaces/shards.rb +15 -0
- data/lib/influxdb/api/namespaces/users.rb +7 -0
- data/lib/influxdb/api/server_version.rb +6 -2
- data/lib/influxdb/api/version.rb +1 -1
- data/spec/intergrations/cluster_admins_spec.rb +75 -0
- data/spec/intergrations/continuous_queries_spec.rb +106 -0
- data/spec/intergrations/databases_spec.rb +68 -0
- data/spec/intergrations/series_spec.rb +104 -0
- data/spec/intergrations/servers_spec.rb +35 -0
- data/spec/intergrations/shard_spaces_spec.rb +126 -0
- data/spec/intergrations/shards_spec.rb +85 -0
- data/spec/intergrations/users_0_7_3_spec.rb +104 -0
- data/spec/intergrations/users_spec.rb +124 -0
- data/spec/lib/influxdb/api/database_spec.rb +32 -4
- data/spec/lib/influxdb/api/namespaces/{continuous_queries_spec.rb → continuous_queries/api_spec.rb} +2 -2
- data/spec/lib/influxdb/api/namespaces/continuous_queries/sql_spec.rb +41 -0
- data/spec/lib/influxdb/api/server_version_spec.rb +1 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/version_resolver.rb +56 -0
- metadata +30 -5
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'databases', integration: true do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
|
7
|
+
subject{ client.databases }
|
8
|
+
|
9
|
+
before do
|
10
|
+
subject.all.each{|db| subject.delete(db['name']) }
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
subject.all.each{|db| subject.delete(db['name']) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.all' do
|
18
|
+
context 'when there is none database' do
|
19
|
+
it 'returns empty array' do
|
20
|
+
expect(subject.all).to eq([])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when there are some databases' do
|
25
|
+
before do
|
26
|
+
subject.create('db_name1')
|
27
|
+
subject.create('db_name2')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns the list of databases' do
|
31
|
+
expect(subject.all).to match_array([{ 'name' => 'db_name1' }, { 'name' => 'db_name2' }])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '.create' do
|
37
|
+
it 'creates a new db with given name' do
|
38
|
+
subject.create('db_name')
|
39
|
+
expect(subject.all.include?({ 'name' => 'db_name' })).to be_truthy
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when there is db with the same name' do
|
43
|
+
before{ subject.create('db_name') }
|
44
|
+
|
45
|
+
it 'raises error' do
|
46
|
+
expect{ subject.create('db_name') }.to raise_error(
|
47
|
+
Influxdb::Api::Client::Errors::Conflict, '[409] database db_name exists'
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '.delete' do
|
54
|
+
context 'for unexisted db' do
|
55
|
+
it 'returns false' do
|
56
|
+
expect(subject.delete('db_name')).to be_falsy
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'for existed db' do
|
61
|
+
before{ subject.create('db_name') }
|
62
|
+
|
63
|
+
it 'removes db and returns true' do
|
64
|
+
expect(subject.delete('db_name')).to be_truthy
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'series', integration: true do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
|
7
|
+
subject{ client.databases('db_name').series }
|
8
|
+
|
9
|
+
before do
|
10
|
+
client.databases.create('db_name')
|
11
|
+
subject.all.each{|name| subject.delete(name) }
|
12
|
+
end
|
13
|
+
|
14
|
+
after{ client.databases.delete('db_name') }
|
15
|
+
|
16
|
+
def series_data(name)
|
17
|
+
name = name.to_s
|
18
|
+
subject.execute('select * from ' + name)[name] || []
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.all' do
|
22
|
+
context 'when there is none series' do
|
23
|
+
it 'returns empty array' do
|
24
|
+
expect(subject.all).to eq([])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when there are some series' do
|
29
|
+
before do
|
30
|
+
subject.write('name1', v: 1)
|
31
|
+
subject.write('name2', v: 2)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns the list of series' do
|
35
|
+
expect(subject.all).to match_array(['name1', 'name2'])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '.write' do
|
41
|
+
it 'writes row into the series' do
|
42
|
+
subject.write(:name, v: 1)
|
43
|
+
expect(series_data(:name).size).to eq(1)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'writes multiple rows into the series' do
|
47
|
+
subject.write(:name, [{ v: 1 }, { v: 2 }])
|
48
|
+
expect(series_data(:name).size).to eq(2)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'writes multiple rows into multiple series' do
|
52
|
+
subject.write(name1: [{ v: 1 }], name2: [{ v: 2 }])
|
53
|
+
|
54
|
+
expect(series_data(:name1).size).to eq(1)
|
55
|
+
expect(series_data(:name2).size).to eq(1)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '.execute' do
|
60
|
+
context 'when series does not exist', version: '<=0.8.3' do
|
61
|
+
it 'returns empty Hash' do
|
62
|
+
expect(subject.execute('SELECT * FROM name')).to eq({})
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when series does not exist', version: '>0.8.3' do
|
67
|
+
it 'raises error' do
|
68
|
+
expect{ subject.execute('SELECT * FROM name') }.to raise_error(
|
69
|
+
Influxdb::Api::Client::Errors::BadRequest, "[400] Couldn't find series: name"
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'when series exists', time_freeze: '16.09.2014 00:00:00 +0700' do
|
75
|
+
before{ subject.write(:name, v: 1) }
|
76
|
+
|
77
|
+
let(:result){ subject.execute('SELECT * FROM name') }
|
78
|
+
|
79
|
+
it 'returns result of the query' do
|
80
|
+
expect(result).to be_instance_of(Hash)
|
81
|
+
expect(result['name']).to be_instance_of(Array)
|
82
|
+
expect(result['name'].size).to eq(1)
|
83
|
+
expect(result['name'][0]).to be_instance_of(Hash)
|
84
|
+
expect(result['name'][0]['v']).to eq(1)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '.delete' do
|
90
|
+
context 'for unexisted series' do
|
91
|
+
it 'returns true' do
|
92
|
+
expect(subject.delete('name')).to be_truthy
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'for existed db' do
|
97
|
+
before{ subject.write(:name, v: 1) }
|
98
|
+
|
99
|
+
it 'removes db and returns true' do
|
100
|
+
expect(subject.delete('name')).to be_truthy
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'servers', integration: true do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
let(:result){ subject.all }
|
7
|
+
|
8
|
+
subject{ client.servers }
|
9
|
+
|
10
|
+
before{ client.databases.create('db_name') }
|
11
|
+
after{ client.databases.delete('db_name') }
|
12
|
+
|
13
|
+
describe '.all' do
|
14
|
+
it 'returns list of shards', version: '<=0.7.3' do
|
15
|
+
expect(result).to be_instance_of(Array)
|
16
|
+
expect(result[0]).to include('id', 'protobufConnectString')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns list of shards', version: '0.7.3-0.8.4' do
|
20
|
+
expect(result).to be_instance_of(Array)
|
21
|
+
expect(result[0]).to include(
|
22
|
+
'id', 'isLeader', 'isUp', 'leaderRaftConnectString', 'leaderRaftName', 'protobufConnectString',
|
23
|
+
'raftConnectionString', 'raftName', 'state', 'stateName'
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns list of shards', version: '>0.8.3' do
|
28
|
+
expect(result).to be_instance_of(Array)
|
29
|
+
expect(result[0]).to include(
|
30
|
+
'id', 'isLeader', 'isUp', 'leaderRaftConnectString', 'leaderRaftName', 'protobufConnectString',
|
31
|
+
'raftConnectionString', 'raftName'
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'shard_spaces', version: '>0.7.3', integration: true do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
let(:shard_space){ {
|
7
|
+
'name' => 'default',
|
8
|
+
'database' => 'db_name',
|
9
|
+
'retentionPolicy' => 'inf',
|
10
|
+
'shardDuration' => '7d',
|
11
|
+
'regex' => '/.*/',
|
12
|
+
'replicationFactor' => 1,
|
13
|
+
'split' => 1
|
14
|
+
} }
|
15
|
+
|
16
|
+
subject{ client.databases('db_name').shard_spaces }
|
17
|
+
|
18
|
+
before{ client.databases.create('db_name') }
|
19
|
+
after{ client.databases.delete('db_name') }
|
20
|
+
|
21
|
+
describe '.all' do
|
22
|
+
context 'when database just has been created' do
|
23
|
+
it 'returns empty list' do
|
24
|
+
expect(subject.all).to eq([])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when there are some shard spaces' do
|
29
|
+
before{ client.databases('db_name').series.write(:name, v: 1) }
|
30
|
+
|
31
|
+
it 'returns list of shard spaces' do
|
32
|
+
expect(subject.all).to eq([shard_space])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.create' do
|
38
|
+
it 'creates shard space' do
|
39
|
+
subject.create(shard_space)
|
40
|
+
expect(subject.all).to eq([shard_space])
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when there is already the same shard space' do
|
44
|
+
before{ subject.create(shard_space) }
|
45
|
+
|
46
|
+
it 'raises error' do
|
47
|
+
expect{ subject.create(shard_space) }.to raise_error(
|
48
|
+
Influxdb::Api::Client::Errors::BadRequest, '[400] Shard space default exists for db db_name'
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '.update' do
|
55
|
+
let(:new_attributes){ {
|
56
|
+
retentionPolicy: '30d',
|
57
|
+
shardDuration: '15d',
|
58
|
+
regex: '/.*/',
|
59
|
+
replicationFactor: 1,
|
60
|
+
split: 1
|
61
|
+
} }
|
62
|
+
|
63
|
+
let(:unacceptable_attributes){ {
|
64
|
+
retentionPolicy: '30d',
|
65
|
+
shardDuration: '15d',
|
66
|
+
regex: '/.*/',
|
67
|
+
replicationFactor: 1,
|
68
|
+
split: 1,
|
69
|
+
someuUnacceptableAttribute: 'lalala'
|
70
|
+
} }
|
71
|
+
|
72
|
+
before{ subject.create(shard_space) }
|
73
|
+
|
74
|
+
it 'updates attributes of shard space' do
|
75
|
+
subject.update('default', new_attributes)
|
76
|
+
expect(subject.all).to eq([{
|
77
|
+
'name' => 'default',
|
78
|
+
'database' => 'db_name',
|
79
|
+
'retentionPolicy' => '30d',
|
80
|
+
'shardDuration' => '15d',
|
81
|
+
'regex' => '/.*/',
|
82
|
+
'replicationFactor' => 1,
|
83
|
+
'split' => 1
|
84
|
+
}])
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when same shard space does not exist' do
|
88
|
+
it 'raises error' do
|
89
|
+
expect{ subject.update('unexisted_name', new_attributes) }.to raise_error(
|
90
|
+
Influxdb::Api::Client::Errors::NotAcceptable, "[406] Can't update a shard space that doesn't exist"
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'with unacceptable attributes' do
|
96
|
+
it 'updates only valid attributes' do
|
97
|
+
subject.update('default', unacceptable_attributes)
|
98
|
+
expect(subject.all).to eq([{
|
99
|
+
'name' => 'default',
|
100
|
+
'database' => 'db_name',
|
101
|
+
'retentionPolicy' => '30d',
|
102
|
+
'shardDuration' => '15d',
|
103
|
+
'regex' => '/.*/',
|
104
|
+
'replicationFactor' => 1,
|
105
|
+
'split' => 1
|
106
|
+
}])
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '.delete' do
|
112
|
+
context 'when shard space exists' do
|
113
|
+
before{ subject.create(shard_space) }
|
114
|
+
|
115
|
+
it 'deletes shard space' do
|
116
|
+
expect{ subject.delete('default') }.to change{ subject.all.size }.from(1).to(0)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when shard space does not exist' do
|
121
|
+
it 'does nothing' do
|
122
|
+
expect{ subject.delete('unexisted_name') }.not_to change{ subject.all.size }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'shards', integration: true do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
let(:result){ subject.all }
|
7
|
+
|
8
|
+
subject{ client.shards }
|
9
|
+
|
10
|
+
before do
|
11
|
+
client.databases.create('db_name')
|
12
|
+
client.databases('db_name').series.write(:name, v: 1)
|
13
|
+
end
|
14
|
+
|
15
|
+
after{ client.databases.delete('db_name') }
|
16
|
+
|
17
|
+
describe '.all' do
|
18
|
+
it 'returns list of shards', version: '>0.7.3' do
|
19
|
+
expect(result).to be_instance_of(Array)
|
20
|
+
expect(result).not_to be_empty
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns list of shards', version: '<=0.7.3' do
|
24
|
+
expect(result).to be_instance_of(Hash)
|
25
|
+
expect(result).not_to be_empty
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.create', time_freeze: Time.now, version: '<=0.7.3' do
|
30
|
+
let(:attributes){ {
|
31
|
+
startTime: Time.now,
|
32
|
+
endTime: Time.now.to_i + 86400,
|
33
|
+
spaceName: 'default',
|
34
|
+
shards: [{ serverIds: [1] }],
|
35
|
+
database: 'db_name'
|
36
|
+
} }
|
37
|
+
let(:shard){ result['shortTerm'].sort_by{|v| v['id'] }.last }
|
38
|
+
|
39
|
+
it 'creates new shard' do
|
40
|
+
subject.create(attributes)
|
41
|
+
|
42
|
+
expect(result['shortTerm'].size).to eq(2)
|
43
|
+
expect(shard['startTime']).to eq(Time.now.to_i)
|
44
|
+
expect(shard['endTime']).to eq(Time.now.to_i + 86400)
|
45
|
+
expect(shard['spaceName']).to be_nil
|
46
|
+
expect(shard['database']).to be_nil
|
47
|
+
expect(shard['serverIds']).to eq([1])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '.create', time_freeze: Time.now, version: '>0.7.3' do
|
52
|
+
let(:attributes){ {
|
53
|
+
startTime: Time.now,
|
54
|
+
endTime: Time.now.to_i + 86400,
|
55
|
+
spaceName: 'default',
|
56
|
+
shards: [{ serverIds: [1] }],
|
57
|
+
database: 'db_name'
|
58
|
+
} }
|
59
|
+
let(:shard){ result.sort_by{|v| v['id'] }.last }
|
60
|
+
|
61
|
+
it 'creates new shard' do
|
62
|
+
subject.create(attributes)
|
63
|
+
|
64
|
+
expect(result.size).to eq(2)
|
65
|
+
expect(shard['startTime']).to eq(Time.now.to_i)
|
66
|
+
expect(shard['endTime']).to eq(Time.now.to_i + 86400)
|
67
|
+
expect(shard['spaceName']).to eq('default')
|
68
|
+
expect(shard['database']).to eq('db_name')
|
69
|
+
expect(shard['serverIds']).to eq([1])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '.delete' do
|
74
|
+
# It doesn't work on InfluxDB before 0.9.0
|
75
|
+
# https://github.com/influxdb/influxdb/issues/1043
|
76
|
+
skip("It doesn't work on InfluxDB before 0.9.0 (https://github.com/influxdb/influxdb/issues/1043)") do
|
77
|
+
|
78
|
+
let(:shard_id){ result[0]['id'] }
|
79
|
+
|
80
|
+
it 'deletes shard' do
|
81
|
+
expect{ subject.delete(shard_id) }.to change{ subject.all.size }.from(1).to(0)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'users', version: '<0.8.0', integration: true do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
|
7
|
+
subject{ client.databases('db_name').users }
|
8
|
+
|
9
|
+
before do
|
10
|
+
client.databases.create('db_name')
|
11
|
+
subject.all.each{|u| subject.delete(u['name']) }
|
12
|
+
end
|
13
|
+
|
14
|
+
after{ client.databases.delete('db_name') }
|
15
|
+
|
16
|
+
describe '.all' do
|
17
|
+
context 'when there are no users' do
|
18
|
+
it 'returns empty array' do
|
19
|
+
expect(subject.all).to eq([])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when there are some users' do
|
24
|
+
before do
|
25
|
+
subject.create(name: 'username1', password: 'mypass1')
|
26
|
+
subject.create(name: 'username2', password: 'mypass2')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns the list of users' do
|
30
|
+
expect(subject.all).to match_array([
|
31
|
+
{ 'name' => 'username1', 'isAdmin' => false },
|
32
|
+
{ 'name' => 'username2', 'isAdmin' => false }
|
33
|
+
])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.create' do
|
39
|
+
it 'creates a new user with given name' do
|
40
|
+
expect{ subject.create(name: 'username', password: 'mypass') }.to change{ subject.all.size }.from(0).to(1)
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when there is user with the same name' do
|
44
|
+
before{ subject.create(name: 'username', password: 'mypass') }
|
45
|
+
|
46
|
+
it 'raises error' do
|
47
|
+
expect{ subject.create(name: 'username', password: 'mypass') }.to raise_error(
|
48
|
+
Influxdb::Api::Client::Errors::BadRequest, '[400] User username already exists'
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '.update' do
|
55
|
+
context 'when user does not exist' do
|
56
|
+
it 'raises error' do
|
57
|
+
expect{ subject.update('username', admin: true) }.to raise_error(
|
58
|
+
Influxdb::Api::Client::Errors::BadRequest, '[400] Invalid username username'
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when user exists' do
|
64
|
+
before{ subject.create(name: 'username', password: 'mypass') }
|
65
|
+
|
66
|
+
it 'updates user attributes' do
|
67
|
+
subject.update('username', admin: true)
|
68
|
+
expect(subject.all).to eq([{ 'name' => 'username', 'isAdmin' => true }])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '.find' do
|
74
|
+
context 'when user does not exist' do
|
75
|
+
it 'returns nil' do
|
76
|
+
expect(subject.find('username2')).to be_nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when user exists' do
|
81
|
+
before{ subject.create(name: 'username', password: 'mypass') }
|
82
|
+
|
83
|
+
it 'returns user' do
|
84
|
+
expect(subject.find('username')).to eq('name' => 'username', 'isAdmin' => false)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '.delete' do
|
90
|
+
context 'when user does not exist' do
|
91
|
+
it 'returns false' do
|
92
|
+
expect(subject.delete('username')).to be_falsy
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when user exists' do
|
97
|
+
before{ subject.create(name: 'username', password: 'mypass') }
|
98
|
+
|
99
|
+
it 'removes db and returns true' do
|
100
|
+
expect(subject.delete('username')).to be_truthy
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|