couch_potato 1.7.1 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +38 -0
- data/.gitignore +3 -0
- data/CHANGES.md +169 -131
- data/Gemfile +4 -0
- data/README.md +55 -75
- data/Rakefile +11 -10
- data/couch_potato-rspec.gemspec +2 -1
- data/couch_potato.gemspec +8 -6
- data/gemfiles/active_support_5_0 +1 -5
- data/gemfiles/active_support_5_1 +7 -0
- data/gemfiles/active_support_5_2 +7 -0
- data/gemfiles/active_support_6_0 +7 -0
- data/gemfiles/active_support_6_1 +7 -0
- data/lib/couch_potato/database.rb +165 -70
- data/lib/couch_potato/persistence/dirty_attributes.rb +3 -21
- data/lib/couch_potato/persistence/magic_timestamps.rb +3 -3
- data/lib/couch_potato/persistence/properties.rb +15 -10
- data/lib/couch_potato/persistence/simple_property.rb +0 -4
- data/lib/couch_potato/persistence/type_caster.rb +9 -6
- data/lib/couch_potato/persistence.rb +0 -1
- data/lib/couch_potato/railtie.rb +6 -11
- data/lib/couch_potato/validation.rb +8 -0
- data/lib/couch_potato/version.rb +1 -1
- data/lib/couch_potato/view/base_view_spec.rb +8 -32
- data/lib/couch_potato/view/custom_views.rb +4 -3
- data/lib/couch_potato/view/flex_view_spec.rb +121 -0
- data/lib/couch_potato/view/view_parameters.rb +34 -0
- data/lib/couch_potato.rb +32 -9
- data/spec/callbacks_spec.rb +45 -19
- data/spec/conflict_handling_spec.rb +0 -1
- data/spec/property_spec.rb +2 -2
- data/spec/railtie_spec.rb +10 -0
- data/spec/spec_helper.rb +4 -3
- data/spec/unit/active_model_compliance_spec.rb +7 -3
- data/spec/unit/attributes_spec.rb +1 -1
- data/spec/unit/caching_spec.rb +105 -0
- data/spec/unit/couch_potato_spec.rb +70 -5
- data/spec/unit/create_spec.rb +5 -4
- data/spec/unit/database_spec.rb +235 -135
- data/spec/unit/dirty_attributes_spec.rb +5 -26
- data/spec/unit/flex_view_spec_spec.rb +17 -0
- data/spec/unit/model_view_spec_spec.rb +1 -1
- data/spec/unit/rspec_stub_db_spec.rb +31 -0
- data/spec/unit/validation_spec.rb +42 -2
- data/spec/views_spec.rb +214 -103
- data/vendor/pouchdb-collate/LICENSE +202 -0
- data/vendor/pouchdb-collate/pouchdb-collate.js +430 -0
- metadata +46 -42
- data/.ruby-version +0 -1
- data/.travis.yml +0 -21
- data/gemfiles/active_support_4_0 +0 -11
- data/gemfiles/active_support_4_1 +0 -11
- data/gemfiles/active_support_4_2 +0 -11
- data/lib/couch_potato/persistence/deep_dirty_attributes.rb +0 -180
- data/spec/unit/deep_dirty_attributes_spec.rb +0 -434
@@ -1,6 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe CouchPotato, '
|
5
|
+
describe CouchPotato, '.configure' do
|
6
|
+
after(:example) do
|
7
|
+
# reset defaults
|
8
|
+
CouchPotato::Config.database_name = nil
|
9
|
+
CouchPotato::Config.split_design_documents_per_view = false
|
10
|
+
CouchPotato::Config.digest_view_names = false
|
11
|
+
CouchPotato::Config.default_language = :javascript
|
12
|
+
CouchPotato::Config.database_host = 'http://127.0.0.1:5984'
|
13
|
+
CouchPotato::Config.additional_databases = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets the database name when config is a string' do
|
17
|
+
CouchPotato.configure('testdb')
|
18
|
+
|
19
|
+
expect(CouchPotato::Config.database_name).to eq('testdb')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'does not override database_host if not given' do
|
23
|
+
CouchPotato.configure(
|
24
|
+
database: 'testdb'
|
25
|
+
)
|
26
|
+
|
27
|
+
expect(CouchPotato::Config.database_host).to eq('http://127.0.0.1:5984')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'sets the given config options' do
|
31
|
+
CouchPotato.configure(
|
32
|
+
database: 'testdb',
|
33
|
+
database_host: 'http://10.0.0.1:2000',
|
34
|
+
additional_databases: {
|
35
|
+
test2: 'test2_db'
|
36
|
+
},
|
37
|
+
split_design_documents_per_view: true,
|
38
|
+
digest_view_names: true,
|
39
|
+
default_language: 'erlang'
|
40
|
+
)
|
41
|
+
|
42
|
+
expect(CouchPotato::Config.database_name).to eq('testdb')
|
43
|
+
expect(CouchPotato::Config.split_design_documents_per_view).to eq(true)
|
44
|
+
expect(CouchPotato::Config.digest_view_names).to eq(true)
|
45
|
+
expect(CouchPotato::Config.default_language).to eq('erlang')
|
46
|
+
expect(CouchPotato::Config.database_host).to eq('http://10.0.0.1:2000')
|
47
|
+
expect(CouchPotato::Config.additional_databases).to eq('test2' => 'test2_db')
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'works with string keys' do
|
51
|
+
CouchPotato.configure(
|
52
|
+
'database' => 'testdb'
|
53
|
+
)
|
54
|
+
|
55
|
+
expect(CouchPotato::Config.database_name).to eq('testdb')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe CouchPotato, '.full_url_to_database' do
|
4
60
|
before(:each) do
|
5
61
|
@original_database_name = CouchPotato::Config.database_name
|
6
62
|
end
|
@@ -8,12 +64,12 @@ describe CouchPotato, 'full_url_to_database' do
|
|
8
64
|
CouchPotato::Config.database_name = @original_database_name
|
9
65
|
end
|
10
66
|
|
11
|
-
it
|
67
|
+
it 'should add the default localhost and port if only a name is set' do
|
12
68
|
CouchPotato::Config.database_name = 'test'
|
13
69
|
expect(CouchPotato.full_url_to_database).to eq('http://127.0.0.1:5984/test')
|
14
70
|
end
|
15
71
|
|
16
|
-
it
|
72
|
+
it 'should return the set url' do
|
17
73
|
CouchPotato::Config.database_name = 'http://db.local/test'
|
18
74
|
expect(CouchPotato.full_url_to_database).to eq('http://db.local/test')
|
19
75
|
end
|
@@ -21,13 +77,22 @@ end
|
|
21
77
|
|
22
78
|
describe CouchPotato, 'use' do
|
23
79
|
it 'should return the db object' do
|
24
|
-
db = CouchPotato.use(
|
80
|
+
db = CouchPotato.use('testdb')
|
25
81
|
expect(db.couchrest_database.root.to_s).to eq('http://127.0.0.1:5984/testdb')
|
26
82
|
end
|
83
|
+
|
84
|
+
it 'returns a db from the additional_databases pool' do
|
85
|
+
CouchPotato::Config.database_host = 'http://127.0.0.1:5984'
|
86
|
+
CouchPotato::Config.additional_databases = { '1' => 'db1', '2' => 'db2' }
|
87
|
+
|
88
|
+
db = CouchPotato.use('2')
|
89
|
+
|
90
|
+
expect(db.couchrest_database.root.to_s).to eq('http://127.0.0.1:5984/db2')
|
91
|
+
end
|
27
92
|
end
|
28
93
|
|
29
94
|
describe CouchPotato, '.models' do
|
30
|
-
it
|
95
|
+
it 'returns all classes that have implemented CouchPotato::Persistence' do
|
31
96
|
clazz = Class.new
|
32
97
|
clazz.send(:include, CouchPotato::Persistence)
|
33
98
|
|
data/spec/unit/create_spec.rb
CHANGED
@@ -39,7 +39,8 @@ describe "create" do
|
|
39
39
|
describe "fails" do
|
40
40
|
before(:each) do
|
41
41
|
@comment = Comment.new
|
42
|
-
CouchPotato::Database.new(double('database', :info => nil))
|
42
|
+
@db = CouchPotato::Database.new(double('database', :info => nil))
|
43
|
+
@db.save_document(@comment)
|
43
44
|
end
|
44
45
|
|
45
46
|
it "should not assign an id" do
|
@@ -58,11 +59,11 @@ describe "create" do
|
|
58
59
|
expect(@comment.updated_at).to be_nil
|
59
60
|
end
|
60
61
|
|
61
|
-
describe "with
|
62
|
+
describe "with !" do
|
62
63
|
it "should raise an exception" do
|
63
64
|
expect {
|
64
|
-
@
|
65
|
-
}.to raise_error
|
65
|
+
@db.save! @comment
|
66
|
+
}.to raise_error(CouchPotato::Database::ValidationsFailedError)
|
66
67
|
end
|
67
68
|
end
|
68
69
|
end
|