Skip to content

Commit

Permalink
Add "cache_instance_method" rspec matcher. Release 1.1.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
miks committed Aug 31, 2017
1 parent 2e4f13e commit df676c7
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
## Changelog

### 1.1.6 (2017.08.31)
* Add "cache_instance_method" rspec matcher

### 1.1.5 (2017.06.07)
* Fix an incompletely merged PR

Expand Down
3 changes: 2 additions & 1 deletion lib/releaf/rspec.rb
@@ -1,4 +1,5 @@
require 'releaf/test'
require 'releaf/rspec/matchers'
require 'releaf/rspec/matchers/match_html'
require 'releaf/rspec/matchers/cache_instance_method'
require 'releaf/rspec/helpers'
require 'releaf/rspec/features_matchers'
6 changes: 6 additions & 0 deletions lib/releaf/rspec/matchers/cache_instance_method.rb
@@ -0,0 +1,6 @@
RSpec::Matchers.define :cache_instance_method do |method_name|

match do |actual|
described_class.cached_instance_methods.include?(method_name)
end
end
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/releaf/version.rb
@@ -1,3 +1,3 @@
module Releaf
VERSION = "1.1.5"
VERSION = "1.1.6"
end
Expand Up @@ -63,6 +63,7 @@ def returnable_result?(result, options)
result.present? || options.fetch(:inherit_scopes, true) == false
end

cache_instance_method :localization_data
def localization_data
Releaf::I18nDatabase::I18nEntryTranslation
.joins(:i18n_entry)
Expand All @@ -71,12 +72,14 @@ def localization_data
.to_h
end

cache_instance_method :stored_keys
def stored_keys
Releaf::I18nDatabase::I18nEntry.pluck(:key).inject({}) do|h, key|
h.update(key => true)
end
end

cache_instance_method :stored_translations
def stored_translations
stored_keys.map do |key, _|
key_hash(key)
Expand Down Expand Up @@ -136,8 +139,6 @@ def pluralizable_translation?(options)
options.has_key?(:count) && options[:create_plurals] == true
end

cache_instance_methods :stored_translations, :stored_keys, :localization_data

private

def key_locale_hash(localized_key, localization)
Expand Down
Expand Up @@ -277,8 +277,8 @@
"lv.some.good" => "xx")
end

it "caches built hash" do
expect(described_class.cached_instance_methods).to include(:localization_data)
it "has cached method result" do
expect(described_class).to cache_instance_method(:localization_data)
end
end

Expand All @@ -289,8 +289,8 @@
expect(subject.stored_keys).to eq("some.food" => true, "some.good" => true)
end

it "caches built hash" do
expect(described_class.cached_instance_methods).to include(:stored_keys)
it "has cached method result" do
expect(described_class).to cache_instance_method(:stored_keys)
end
end

Expand All @@ -309,8 +309,8 @@
end
end

it "caches built hash" do
expect(described_class.cached_instance_methods).to include(:stored_translations)
it "has cached method result" do
expect(described_class).to cache_instance_method(:stored_translations)
end
end

Expand Down

0 comments on commit df676c7

Please sign in to comment.