hexx-storage 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +9 -0
  4. data/.metrics +9 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +2 -0
  7. data/.travis.yml +12 -0
  8. data/.yardopts +3 -0
  9. data/Gemfile +12 -0
  10. data/Guardfile +14 -0
  11. data/LICENSE +21 -0
  12. data/README.md +351 -0
  13. data/Rakefile +22 -0
  14. data/config/metrics/STYLEGUIDE +230 -0
  15. data/config/metrics/cane.yml +5 -0
  16. data/config/metrics/churn.yml +6 -0
  17. data/config/metrics/flay.yml +2 -0
  18. data/config/metrics/metric_fu.yml +13 -0
  19. data/config/metrics/reek.yml +1 -0
  20. data/config/metrics/roodi.yml +24 -0
  21. data/config/metrics/rubocop.yml +73 -0
  22. data/config/metrics/saikuro.yml +3 -0
  23. data/config/metrics/simplecov.yml +8 -0
  24. data/config/metrics/yardstick.yml +37 -0
  25. data/hexx-storage.gemspec +28 -0
  26. data/lib/hexx-storage.rb +20 -0
  27. data/lib/hexx/storage.rb +17 -0
  28. data/lib/hexx/storage/base.rb +108 -0
  29. data/lib/hexx/storage/patches.rb +135 -0
  30. data/lib/hexx/storage/repositories.rb +40 -0
  31. data/lib/hexx/storage/repositories/base.rb +70 -0
  32. data/lib/hexx/storage/repositories/memory.rb +33 -0
  33. data/lib/hexx/storage/repositories/sql.rb +78 -0
  34. data/lib/hexx/storage/version.rb +13 -0
  35. data/spec/integration/storage.yml +9 -0
  36. data/spec/integration/storage_spec.rb +56 -0
  37. data/spec/spec_helper.rb +12 -0
  38. data/spec/tests/storage/base_spec.rb +178 -0
  39. data/spec/tests/storage/patches_spec.rb +202 -0
  40. data/spec/tests/storage/repositories/base_spec.rb +120 -0
  41. data/spec/tests/storage/repositories/memory_spec.rb +32 -0
  42. data/spec/tests/storage/repositories/sql_spec.rb +180 -0
  43. data/spec/tests/storage/repositories_spec.rb +66 -0
  44. data/spec/tests/storage_spec.rb +24 -0
  45. metadata +168 -0
@@ -0,0 +1,120 @@
1
+ # encoding: utf-8
2
+
3
+ describe Hexx::Storage::Repositories::Base do
4
+
5
+ let(:root) { "foo" }
6
+ subject { described_class.new root: root }
7
+
8
+ describe ".new" do
9
+
10
+ context "with a :root" do
11
+
12
+ it "doesn't fail" do
13
+ expect { subject }.not_to raise_error
14
+ end
15
+
16
+ end # context
17
+
18
+ context "without a :root" do
19
+
20
+ subject { described_class.new }
21
+
22
+ it "raises ArgumentError" do
23
+ expect { subject }.to raise_error ArgumentError
24
+ end
25
+
26
+ end # context
27
+
28
+ context "with a :log" do
29
+
30
+ subject { described_class.new root: root, log: "logs/log" }
31
+
32
+ before { `rm #{ root }/logs -r -f` }
33
+ after { `rm #{ root }/logs -r -f` }
34
+
35
+ it "creates folder for logs" do
36
+ expect { subject }.to change { Dir.exist? "#{ root }/logs" }.to true
37
+ end
38
+
39
+ end # context
40
+
41
+ end # describe .new
42
+
43
+ describe "#root" do
44
+
45
+ it "is initialized" do
46
+ expect(subject.root).to eq root
47
+ end
48
+
49
+ end # describe #root
50
+
51
+ describe "#log" do
52
+
53
+ it "returns nil by default" do
54
+ expect(subject.log).to be_nil
55
+ end
56
+
57
+ it "can be initialized" do
58
+ subject = described_class.new root: "foo", log: "bar"
59
+ expect(subject.log).to eq "bar"
60
+ end
61
+
62
+ end # describe #log
63
+
64
+ describe "#logger" do
65
+
66
+ shared_examples "creating a logger" do |from: nil|
67
+
68
+ let(:logger) { double }
69
+ let(:repo) { described_class.new root: root, log: from }
70
+ subject { repo.logger }
71
+
72
+ it "[creates a logger]" do
73
+ expect(subject).to eq logger
74
+ end
75
+
76
+ end # shared examples
77
+
78
+ context "with some #log" do
79
+
80
+ before do
81
+ allow(Logger).to receive(:new) do |file, *|
82
+ logger if file == "#{ root }/qux/bar.baz"
83
+ end
84
+ end
85
+
86
+ it_behaves_like "creating a logger", from: "qux/bar.baz"
87
+
88
+ end # context
89
+
90
+ context "without #log" do
91
+
92
+ before do
93
+ allow(Logger).to receive(:new) do |file, *|
94
+ logger if file.is_a? StringIO
95
+ end
96
+ end
97
+
98
+ it_behaves_like "creating a logger"
99
+
100
+ end # context
101
+
102
+ end # describe #logger
103
+
104
+ describe "#respond_to?" do
105
+
106
+ it "returns true" do
107
+ expect(subject.respond_to? :foo).to eq true
108
+ end
109
+
110
+ end # describe #respond_to?
111
+
112
+ describe "#foo (arbitrary method)" do
113
+
114
+ it "returns nil" do
115
+ expect(subject.foo).to be_nil
116
+ end
117
+
118
+ end # describe arbitrary method
119
+
120
+ end # describe Hexx::Storage::Repositories::Base
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ require "rom/memory"
4
+
5
+ describe Hexx::Storage::Repositories::Memory do
6
+
7
+ let(:root) { "foo" }
8
+ subject { described_class.new root: root, uri: "uri", foo: "bar" }
9
+
10
+ describe ".new" do
11
+
12
+ it { is_expected.to be_kind_of Hexx::Storage::Repositories::Base }
13
+
14
+ end # describe .new
15
+
16
+ describe "#adapter" do
17
+
18
+ it "returns :memory" do
19
+ expect(subject.adapter).to eq :memory
20
+ end
21
+
22
+ end # describe #adapter
23
+
24
+ describe "#settings" do
25
+
26
+ it "return proper settings" do
27
+ expect(subject.settings).to eq :memory
28
+ end
29
+
30
+ end # describe #settings
31
+
32
+ end # describe Hexx::Storage::Repositories::Memory
@@ -0,0 +1,180 @@
1
+ # encoding: utf-8
2
+
3
+ require "rom-sql"
4
+ require "sequel/adapters/postgres"
5
+
6
+ describe Hexx::Storage::Repositories::SQL do
7
+
8
+ let(:repo_storage) { Hexx::Storage::Repositories::Memory }
9
+
10
+ let(:root) { File.expand_path "..", __FILE__ }
11
+ let(:uri) { "postgres://localhost/rom" }
12
+ let(:user) { "foo" }
13
+ let(:password) { "bar" }
14
+ let(:log) { "baz" }
15
+ let(:options) { { user: user, password: password } }
16
+
17
+ subject do
18
+ described_class.new(
19
+ root: root,
20
+ uri: uri,
21
+ user: user,
22
+ password: password
23
+ )
24
+ end
25
+
26
+ describe ".new" do
27
+
28
+ context "with an :uri" do
29
+
30
+ it { is_expected.to be_kind_of Hexx::Storage::Repositories::Base }
31
+
32
+ end # context
33
+
34
+ context "without :uri" do
35
+
36
+ subject { described_class.new root: root }
37
+
38
+ it "raises ArgumentError" do
39
+ expect { subject }.to raise_error ArgumentError
40
+ end
41
+
42
+ end # context
43
+
44
+ end # describe .new
45
+
46
+ describe "#adapter" do
47
+
48
+ it "returns :sql" do
49
+ expect(subject.adapter).to eq :sql
50
+ end
51
+
52
+ end # describe #adapter
53
+
54
+ describe "#uri" do
55
+
56
+ it "is initialized" do
57
+ expect(subject.uri).to eq uri
58
+ end
59
+
60
+ end # describe #uri
61
+
62
+ describe "#options" do
63
+
64
+ it "returns {} by default" do
65
+ subject = described_class.new(root: root, uri: uri, log: log)
66
+ expect(subject.options).to eq({})
67
+ end
68
+
69
+ it "can be initialized" do
70
+ expect(subject.options).to eq options
71
+ end
72
+
73
+ end # describe #options
74
+
75
+ describe "#migrations=" do
76
+
77
+ context "when a folder exists" do
78
+
79
+ let(:folder) { root }
80
+
81
+ it "sets #migrations" do
82
+ expect { subject.migrations = folder }
83
+ .to change { subject.migrations }
84
+ .to root
85
+ end
86
+
87
+ end # context
88
+
89
+ context "when a folder is absent" do
90
+
91
+ let(:folder) { "," }
92
+
93
+ it "doesn't set #migrations" do
94
+ expect { subject.migrations = folder }
95
+ .not_to change { subject.migrations }
96
+ end
97
+
98
+ end # context
99
+
100
+ end # describe #migrations=
101
+
102
+ describe "#conn" do
103
+
104
+ it "returns a Sequel connection" do
105
+ expect(subject.conn).to be_kind_of Sequel::Database
106
+ end
107
+
108
+ it "uses the #uri" do
109
+ expect(subject.conn.uri).to eq subject.uri
110
+ end
111
+
112
+ it "sets original options" do
113
+ expect(subject.conn.opts[:orig_opts]).to eq subject.options
114
+ end
115
+
116
+ it "sets the logger" do
117
+ logger = double
118
+ allow(subject).to receive(:logger) { logger }
119
+
120
+ expect(subject.conn.loggers).to contain_exactly subject.logger
121
+ end
122
+
123
+ end # describe #conn
124
+
125
+ describe "#migrator" do
126
+
127
+ let(:migrator_class) { ROM::SQL::Migration::Migrator }
128
+
129
+ context "when a #migrations is set" do
130
+
131
+ before { allow(subject).to receive(:migrations) { "foo" } }
132
+
133
+ it "returns a migrator" do
134
+ expect(subject.migrator).to be_kind_of migrator_class
135
+ end
136
+
137
+ it "uses path to #migrations" do
138
+ expect(subject.migrator.path).to eq subject.migrations
139
+ end
140
+
141
+ it "uses the #conn" do
142
+ expect(subject.migrator.connection).to eq subject.conn
143
+ end
144
+
145
+ end # context
146
+
147
+ context "when a #migrations is absent" do
148
+
149
+ it "returns a migrator" do
150
+ expect(subject.migrator).to be_kind_of migrator_class
151
+ end
152
+
153
+ end # context
154
+
155
+ end # describe #migrator
156
+
157
+ describe "#settings" do
158
+
159
+ context "with some #migrations" do
160
+
161
+ before { subject.migrations = subject.root }
162
+
163
+ it "uses both the connection and migrator" do
164
+ expect(subject.settings)
165
+ .to eq [:sql, [subject.conn, migrator: subject.migrator]]
166
+ end
167
+
168
+ end # context
169
+
170
+ context "without #migrations" do
171
+
172
+ it "uses the connection only" do
173
+ expect(subject.settings).to eq [:sql, subject.conn]
174
+ end
175
+
176
+ end # context
177
+
178
+ end # describe #settings
179
+
180
+ end # describe Hexx::Storage::Repositories::SQL
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+
3
+ describe Hexx::Storage::Repositories do
4
+
5
+ describe ".build" do
6
+
7
+ let(:adapter) { "memory" }
8
+ let(:options) { { uri: :foo } }
9
+ let(:repository) { double }
10
+ let(:repository_class) { Hexx::Storage::Repositories::Memory }
11
+
12
+ before { allow(repository_class).to receive(:new) { repository } }
13
+ subject { described_class.build adapter: adapter, **options }
14
+
15
+ context "adapter: :memory" do
16
+
17
+ it "creates the Memory storage" do
18
+ expect(repository_class).to receive(:new).with(options)
19
+ subject
20
+ end
21
+
22
+ it "returns the storage" do
23
+ expect(subject).to eq repository
24
+ end
25
+
26
+ end # context
27
+
28
+ context "adapter: :sql" do
29
+
30
+ let(:adapter) { "sql" }
31
+ let(:repository_class) { Hexx::Storage::Repositories::SQL }
32
+
33
+ it "creates the SQL storage" do
34
+ expect(repository_class).to receive(:new).with(options)
35
+ subject
36
+ end
37
+
38
+ it "returns the storage" do
39
+ expect(subject).to eq repository
40
+ end
41
+
42
+ end # context
43
+
44
+ context "adapter: :unkonwn" do
45
+
46
+ let(:adapter) { :unkonwn }
47
+
48
+ it "fails" do
49
+ expect { subject }.to raise_error ArgumentError
50
+ end
51
+
52
+ end # context
53
+
54
+ context "adapter: nil" do
55
+
56
+ let(:adapter) { nil }
57
+
58
+ it "fails" do
59
+ expect { subject }.to raise_error
60
+ end
61
+
62
+ end # context
63
+
64
+ end # describe .build
65
+
66
+ end # describe Hexx::Storage::Repositories
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ describe Hexx::Storage do
4
+
5
+ let(:storage_class) { Hexx::Storage::Base }
6
+ let(:storage) { double }
7
+ before { allow(storage_class).to receive(:new) { storage } }
8
+
9
+ describe ".setup" do
10
+
11
+ subject { described_class.setup }
12
+
13
+ it "creates the storage object" do
14
+ expect(storage_class).to receive(:new)
15
+ subject
16
+ end
17
+
18
+ it "returns the storage object" do
19
+ expect(subject).to eq storage
20
+ end
21
+
22
+ end # describe #setup
23
+
24
+ end # describe Hexx::Storage
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hexx-storage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kozin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: naught
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rom
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thread_safe
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hexx-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rom-sql
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.4'
83
+ description:
84
+ email: andrew.kozin@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files:
88
+ - README.md
89
+ - LICENSE
90
+ files:
91
+ - ".coveralls.yml"
92
+ - ".gitignore"
93
+ - ".metrics"
94
+ - ".rspec"
95
+ - ".rubocop.yml"
96
+ - ".travis.yml"
97
+ - ".yardopts"
98
+ - Gemfile
99
+ - Guardfile
100
+ - LICENSE
101
+ - README.md
102
+ - Rakefile
103
+ - config/metrics/STYLEGUIDE
104
+ - config/metrics/cane.yml
105
+ - config/metrics/churn.yml
106
+ - config/metrics/flay.yml
107
+ - config/metrics/metric_fu.yml
108
+ - config/metrics/reek.yml
109
+ - config/metrics/roodi.yml
110
+ - config/metrics/rubocop.yml
111
+ - config/metrics/saikuro.yml
112
+ - config/metrics/simplecov.yml
113
+ - config/metrics/yardstick.yml
114
+ - hexx-storage.gemspec
115
+ - lib/hexx-storage.rb
116
+ - lib/hexx/storage.rb
117
+ - lib/hexx/storage/base.rb
118
+ - lib/hexx/storage/patches.rb
119
+ - lib/hexx/storage/repositories.rb
120
+ - lib/hexx/storage/repositories/base.rb
121
+ - lib/hexx/storage/repositories/memory.rb
122
+ - lib/hexx/storage/repositories/sql.rb
123
+ - lib/hexx/storage/version.rb
124
+ - spec/integration/storage.yml
125
+ - spec/integration/storage_spec.rb
126
+ - spec/spec_helper.rb
127
+ - spec/tests/storage/base_spec.rb
128
+ - spec/tests/storage/patches_spec.rb
129
+ - spec/tests/storage/repositories/base_spec.rb
130
+ - spec/tests/storage/repositories/memory_spec.rb
131
+ - spec/tests/storage/repositories/sql_spec.rb
132
+ - spec/tests/storage/repositories_spec.rb
133
+ - spec/tests/storage_spec.rb
134
+ homepage: https://github.com/nepalez/hexx-storage
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '2.0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.4.6
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Settings for ROM storages
158
+ test_files:
159
+ - spec/spec_helper.rb
160
+ - spec/integration/storage_spec.rb
161
+ - spec/tests/storage/patches_spec.rb
162
+ - spec/tests/storage/repositories/memory_spec.rb
163
+ - spec/tests/storage/repositories/sql_spec.rb
164
+ - spec/tests/storage/repositories/base_spec.rb
165
+ - spec/tests/storage/repositories_spec.rb
166
+ - spec/tests/storage/base_spec.rb
167
+ - spec/tests/storage_spec.rb
168
+ has_rdoc: