fish0 0.0.14 → 0.0.15

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4926b44649bbd6260c6bc5f7b3f604572b33cc51
4
- data.tar.gz: f0eaac6f49a35e74c187747bf7d21a2b685cec16
3
+ metadata.gz: 2021b835ea29a55abd9c8bf3273c7057ca203b31
4
+ data.tar.gz: 7d6b3ac4b3189da0c45c7bb4ebd420f28a7bd596
5
5
  SHA512:
6
- metadata.gz: 75279dfe625e4322fda1665f89ff1c29028a114b5be9d426030f995ccf2690177352c4bb660916d69447bf1445f901c0d2d82296c7b00508540b3fe993cc9d0a
7
- data.tar.gz: aa15b12ac7c969746a974b0ca70c2cb642173928bdec95209fe45fce684916060a80f5f4abd69868ed9f2ef897d5b3be5bfa0dd3584c3e1a9d8a70b2019b0845
6
+ metadata.gz: c38e62e79f5eb07febb7ccc57cbc672a24e638f8bd2f5dd66c37232d64758fb56a8929bbc7d94235e9cba35f3fa2a4c16b91e4f77ccb9c320fe20394c2dd0626
7
+ data.tar.gz: c90292b121a45778a1210937f2b78af4b1bf4bf16aecd5359a9ac1ad7ed59751651b7f1c55707511bb7ffd261cb820111b61d4d2edad34e8c9dc021e46787420
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Fish0
2
2
 
3
+ [![Build Status](https://api.travis-ci.org/rambler-digital-solutions/fish0.svg)](https://travis-ci.org/rambler-digital-solutions/fish0)
4
+ [![Code Climate](https://codeclimate.com/github/rambler-digital-solutions/fish0/badges/gpa.svg)](https://codeclimate.com/github/rambler-digital-solutions/fish0)
5
+ [![Gem Version](https://badge.fury.io/rb/fish0.svg)](https://badge.fury.io/rb/fish0)
6
+
3
7
  > The fish doesn't think because the fish knows everything.
4
8
 
5
9
  Fish0 is the plugin for read-only content websites with MongoDB storage. Works perfect with Rambler&Co CQRS architecture.
data/Rakefile CHANGED
@@ -19,4 +19,4 @@ require 'rspec/core/rake_task'
19
19
  desc 'Run all specs in spec directory (excluding plugin specs)'
20
20
  RSpec::Core::RakeTask.new(:spec)
21
21
 
22
- task :default => :spec
22
+ task default: :spec
@@ -5,11 +5,10 @@ module Fish0
5
5
 
6
6
  included do
7
7
  def cache_key(*timestamp_names)
8
- case
9
- when timestamp_names.any?
8
+ if timestamp_names.any?
10
9
  timestamp = max_updated_column_timestamp(timestamp_names)
11
10
  "#{self.class.to_s.tableize}/#{primary_key_value}-#{timestamp.utc.to_s(:nsec)}"
12
- when timestamp = max_updated_column_timestamp
11
+ elsif timestamp = max_updated_column_timestamp
13
12
  "#{self.class.to_s.tableize}/#{primary_key_value}-#{timestamp.utc.to_s(:nsec)}"
14
13
  else
15
14
  "#{self.class.to_s.tableize}/#{primary_key_value}"
@@ -0,0 +1,10 @@
1
+ module Fish0
2
+ module Concerns
3
+ module Equalable
4
+ def ==(other)
5
+ other.class == self.class && other.attributes == attributes
6
+ end
7
+ alias eql? ==
8
+ end
9
+ end
10
+ end
@@ -13,7 +13,7 @@ module Fish0
13
13
  end
14
14
 
15
15
  def paginate(collection)
16
- Fish0::Paginator.new(collection, page_number: page, per_page: per_page).all
16
+ Fish0::Paginator.new(collection, page_number: page, per_page: per_page).to_collection
17
17
  end
18
18
 
19
19
  def per_page
data/lib/fish0/model.rb CHANGED
@@ -3,5 +3,6 @@ module Fish0
3
3
  extend ActiveModel::Naming
4
4
  include Fish0::Concerns::Base
5
5
  include Fish0::Concerns::ViewModel
6
+ include Fish0::Concerns::Equalable
6
7
  end
7
8
  end
@@ -1,12 +1,14 @@
1
1
  module Fish0
2
2
  class Paginator
3
3
  include Enumerable
4
- delegate :each, :all, :skip, :limit, :padding, :fetch, to: :collection
4
+ delegate :each, :to_collection, :skip, :limit, :padding, :fetch, to: :collection
5
5
 
6
6
  attr_reader :collection
7
7
 
8
8
  def initialize(collection, page_number: 1, per_page: 22, padding: 0)
9
- @collection = collection || (raise ArgumentError)
9
+ raise ArgumentError,
10
+ 'you can paginate only Fish0::Repository' unless collection.is_a?(Fish0::Repository)
11
+ @collection = collection
10
12
  @per = per_page
11
13
  @page = page_number
12
14
  @padding = padding
@@ -11,7 +11,7 @@ module Fish0
11
11
  include Enumerable
12
12
 
13
13
  delegate :aggregate, to: :source
14
- delegate :each, to: :all
14
+ delegate :each, to: :to_collection
15
15
 
16
16
  def initialize(collection, entity_class = nil)
17
17
  raise ArgumentError, 'you should provide collection name' unless collection
@@ -24,12 +24,24 @@ module Fish0
24
24
  @entity_class = entity_class || String(collection).singularize.camelize.constantize
25
25
  end
26
26
 
27
+ def find_one(query)
28
+ where(query).first
29
+ end
30
+
31
+ def find_one!(query)
32
+ find_one(query) || raise(RecordNotFound, "can't find in #{collection} with #{conditions}")
33
+ end
34
+
35
+ def to_collection
36
+ Fish0::Collection.new(fetch.map(&to_entity))
37
+ end
38
+
27
39
  def find(filter = nil, options = {})
28
40
  @source.find filter.dup, options
29
41
  end
30
42
 
31
43
  def all
32
- Fish0::Collection.new(fetch.map(&to_entity))
44
+ self
33
45
  end
34
46
 
35
47
  def projection(values)
@@ -78,8 +90,8 @@ module Fish0
78
90
  def fetch
79
91
  scoped = find(conditions, sort: order)
80
92
  scoped = scoped.projection(@projection) if @projection
81
- scoped = scoped.skip(skip_quantity) if skip_quantity > 0
82
- scoped = scoped.limit(limit_quantity) if limit_quantity > 0
93
+ scoped = scoped.skip(skip_quantity) if skip_quantity.positive?
94
+ scoped = scoped.limit(limit_quantity) if limit_quantity.positive?
83
95
  scoped
84
96
  end
85
97
 
data/lib/fish0/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fish0
2
- VERSION = '0.0.14'.freeze
2
+ VERSION = '0.0.15'.freeze
3
3
  end
data/lib/fish0.rb CHANGED
@@ -7,6 +7,7 @@ require 'fish0/exceptions'
7
7
  require 'fish0/repository'
8
8
  require 'fish0/paginator'
9
9
  require 'fish0/concerns/cacheable'
10
+ require 'fish0/concerns/equalable'
10
11
  require 'fish0/concerns/paginatable'
11
12
  require 'fish0/concerns/view_model'
12
13
  require 'fish0/concerns/base'
data/spec/base_spec.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Fish0::Base' do
4
+ let!(:headline) { FFaker::Lorem.sentence }
5
+ let!(:article) { create(:article, headline: headline) }
6
+ let!(:other_article) { create(:article) }
7
+
8
+ describe '.find_one' do
9
+ subject { Article.find_one(query) }
10
+
11
+ context 'when article with such headline exists in the database' do
12
+ let(:query) { { headline: headline } }
13
+ it { is_expected.to eq(article) }
14
+ end
15
+
16
+ context 'when there is no such article in database' do
17
+ let(:query) { { headline: 'кирриллица' } }
18
+ it { is_expected.to be_nil }
19
+ end
20
+ end
21
+
22
+ describe '.find_one!' do
23
+ subject { Article.find_one!(query) }
24
+
25
+ context 'when article with such headline exists in the database' do
26
+ let(:query) { { headline: headline } }
27
+ it { is_expected.to eq(article) }
28
+ end
29
+
30
+ context 'when there is no such article in database' do
31
+ let(:query) { { headline: 'кирриллица' } }
32
+ it 'raises exception' do
33
+ expect { subject }.to raise_error(Fish0::RecordNotFound)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -19,20 +19,6 @@ Rails.application.configure do
19
19
  # Print deprecation notices to the Rails logger.
20
20
  config.active_support.deprecation = :log
21
21
 
22
- # Debug mode disables concatenation and preprocessing of assets.
23
- # This option may cause significant delays in view rendering with a large
24
- # number of complex assets.
25
- config.assets.debug = true
26
-
27
- # Asset digests allow you to set far-future HTTP expiration dates on all assets,
28
- # yet still be able to expire them through the digest params.
29
- config.assets.digest = true
30
-
31
- # Adds additional error checking when serving assets at runtime.
32
- # Checks for improperly declared sprockets dependencies.
33
- # Raises helpful error messages.
34
- config.assets.raise_runtime_errors = true
35
-
36
22
  # Raises error for missing translations
37
23
  # config.action_view.raise_on_missing_translations = true
38
24
  end
@@ -13,8 +13,8 @@ Rails.application.configure do
13
13
  config.eager_load = false
14
14
 
15
15
  # Configure static file server for tests with Cache-Control for performance.
16
- config.serve_static_files = true
17
- config.static_cache_control = 'public, max-age=3600'
16
+ config.public_file_server.enabled = true
17
+ config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
18
18
 
19
19
  # Show full error reports and disable caching.
20
20
  config.consider_all_requests_local = true
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ factory :article, class: Article do
3
+ slug { FFaker::Internet.slug }
4
+ headline { FFaker::Lorem.sentence }
5
+ end
6
+ end
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,7 @@ require File.expand_path('../dummy/config/environment.rb', __FILE__)
4
4
  require 'rspec/rails'
5
5
  # require 'rspec/autorun'
6
6
  require 'factory_girl_rails'
7
+ require 'ffaker'
7
8
 
8
9
  Rails.backtrace_cleaner.remove_silencers!
9
10
 
@@ -0,0 +1,3 @@
1
+ RSpec.configure do |config|
2
+ config.include FactoryGirl::Syntax::Methods
3
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.configure do |config|
2
+ config.after(:each) do
3
+ Fish0.mongo_reader.database.drop
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module UpdateBehavior
2
+ def save!
3
+ self.class.source.insert_one(attributes)
4
+ end
5
+ end
6
+
7
+ Fish0::Model.include(UpdateBehavior)
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fish0
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Zuev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-05 00:00:00.000000000 Z
11
+ date: 2016-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '4.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '4.2'
41
41
  - !ruby/object:Gem::Dependency
@@ -70,72 +70,86 @@ dependencies:
70
70
  name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.35'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.35'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '3.4'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.4'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec-rails
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '3.4'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '3.4'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: capybara
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '2.7'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '2.7'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: factory_girl_rails
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '4.7'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '4.7'
139
+ - !ruby/object:Gem::Dependency
140
+ name: ffaker
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '2.2'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '2.2'
139
153
  description: |-
140
154
  Plugin for read-only content websites with MongoDB storage.
141
155
  Works perfect with Rambler&Co CQRS projects
@@ -152,6 +166,7 @@ files:
152
166
  - lib/fish0/collection.rb
153
167
  - lib/fish0/concerns/base.rb
154
168
  - lib/fish0/concerns/cacheable.rb
169
+ - lib/fish0/concerns/equalable.rb
155
170
  - lib/fish0/concerns/paginatable.rb
156
171
  - lib/fish0/concerns/view_model.rb
157
172
  - lib/fish0/configuration.rb
@@ -161,6 +176,7 @@ files:
161
176
  - lib/fish0/paginator.rb
162
177
  - lib/fish0/repository.rb
163
178
  - lib/fish0/version.rb
179
+ - spec/base_spec.rb
164
180
  - spec/dummy/README.rdoc
165
181
  - spec/dummy/Rakefile
166
182
  - spec/dummy/app/assets/javascripts/application.js
@@ -181,7 +197,6 @@ files:
181
197
  - spec/dummy/config/environments/development.rb
182
198
  - spec/dummy/config/environments/production.rb
183
199
  - spec/dummy/config/environments/test.rb
184
- - spec/dummy/config/initializers/assets.rb
185
200
  - spec/dummy/config/initializers/backtrace_silencers.rb
186
201
  - spec/dummy/config/initializers/cookies_serializer.rb
187
202
  - spec/dummy/config/initializers/filter_parameter_logging.rb
@@ -194,13 +209,16 @@ files:
194
209
  - spec/dummy/config/routes.rb
195
210
  - spec/dummy/config/secrets.yml
196
211
  - spec/dummy/log/development.log
197
- - spec/dummy/log/test.log
198
212
  - spec/dummy/public/404.html
199
213
  - spec/dummy/public/422.html
200
214
  - spec/dummy/public/500.html
201
215
  - spec/dummy/public/favicon.ico
216
+ - spec/factories/article.rb
202
217
  - spec/models/model_spec.rb
203
218
  - spec/spec_helper.rb
219
+ - spec/support/factory_girl.rb
220
+ - spec/support/mongo_cleaner.rb
221
+ - spec/support/update_behaviour.rb
204
222
  homepage: https://github.com/rambler-digital-solutions/fish0
205
223
  licenses:
206
224
  - MIT
@@ -228,6 +246,7 @@ signing_key:
228
246
  specification_version: 4
229
247
  summary: Plugin for read-only content websites
230
248
  test_files:
249
+ - spec/base_spec.rb
231
250
  - spec/dummy/app/assets/javascripts/application.js
232
251
  - spec/dummy/app/assets/stylesheets/application.css
233
252
  - spec/dummy/app/controllers/application_controller.rb
@@ -245,7 +264,6 @@ test_files:
245
264
  - spec/dummy/config/environments/development.rb
246
265
  - spec/dummy/config/environments/production.rb
247
266
  - spec/dummy/config/environments/test.rb
248
- - spec/dummy/config/initializers/assets.rb
249
267
  - spec/dummy/config/initializers/backtrace_silencers.rb
250
268
  - spec/dummy/config/initializers/cookies_serializer.rb
251
269
  - spec/dummy/config/initializers/filter_parameter_logging.rb
@@ -259,13 +277,16 @@ test_files:
259
277
  - spec/dummy/config/secrets.yml
260
278
  - spec/dummy/config.ru
261
279
  - spec/dummy/log/development.log
262
- - spec/dummy/log/test.log
263
280
  - spec/dummy/public/404.html
264
281
  - spec/dummy/public/422.html
265
282
  - spec/dummy/public/500.html
266
283
  - spec/dummy/public/favicon.ico
267
284
  - spec/dummy/Rakefile
268
285
  - spec/dummy/README.rdoc
286
+ - spec/factories/article.rb
269
287
  - spec/models/model_spec.rb
270
288
  - spec/spec_helper.rb
289
+ - spec/support/factory_girl.rb
290
+ - spec/support/mongo_cleaner.rb
291
+ - spec/support/update_behaviour.rb
271
292
  has_rdoc:
@@ -1,11 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Version of your assets, change this if you want to expire all your assets.
4
- Rails.application.config.assets.version = '1.0'
5
-
6
- # Add additional assets to the asset load path
7
- # Rails.application.config.assets.paths << Emoji.images_path
8
-
9
- # Precompile additional assets.
10
- # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
11
- # Rails.application.config.assets.precompile += %w( search.js )
File without changes