From cbc0afb3994b2feff4e8033ae1e12525a05d81c4 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Wed, 15 Nov 2017 20:40:20 +0530 Subject: [PATCH] REFACTOR: Instance methods added to 'PluginStore' model for easy access (#5315) --- app/models/plugin_store.rb | 18 ++++++++++++++++++ spec/models/plugin_store_spec.rb | 7 ++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/models/plugin_store.rb b/app/models/plugin_store.rb index aebf7f3217e..72d9859e70e 100644 --- a/app/models/plugin_store.rb +++ b/app/models/plugin_store.rb @@ -1,5 +1,23 @@ # API to wrap up plugin store rows class PluginStore + attr_reader :plugin_name + + def initialize(plugin_name) + @plugin_name = plugin_name + end + + def get(key) + self.class.get(plugin_name, key) + end + + def set(key, value) + self.class.set(plugin_name, key, value) + end + + def remove(key) + self.class.remove(plugin_name, key) + end + def self.get(plugin_name, key) if row = PluginStoreRow.find_by(plugin_name: plugin_name, key: key) cast_value(row.type_name, row.value) diff --git a/spec/models/plugin_store_spec.rb b/spec/models/plugin_store_spec.rb index c4f629de3b3..27966c17247 100644 --- a/spec/models/plugin_store_spec.rb +++ b/spec/models/plugin_store_spec.rb @@ -2,16 +2,21 @@ require "rails_helper" require_dependency "plugin_store" describe PluginStore do + let(:store) { PluginStore.new("my_plugin_2") } + def set(k, v) PluginStore.set("my_plugin", k, v) + store.set(k, v) end def get(k) - PluginStore.get("my_plugin", k) + value = PluginStore.get("my_plugin", k) + value == store.get(k) ? value : "values mismatch" end def remove_row(k) PluginStore.remove("my_plugin", k) + store.remove(k) end it "sets strings correctly" do