Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ Style/Next:

Style/ClassVars:
Enabled: false

Gp/UnsafeYamlMarshal:
Enabled: true
Exclude:
- spec/**/*.rb
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ GIT
PATH
remote: .
specs:
enum_machine (2.0.0)
enum_machine (2.0.1)
activemodel
activerecord
activesupport
Expand Down
2 changes: 2 additions & 0 deletions lib/enum_machine/build_enum_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ def self.call(enum_values:, i18n_scope:, value_class:, machine: nil)
aliases = machine&.instance_variable_get(:@aliases) || {}

Class.new do
const_set(:VALUE_CLASS, value_class)

define_singleton_method(:machine) { machine } if machine
define_singleton_method(:values) { enum_values.map { value_class.new(_1).freeze } }

Expand Down
2 changes: 1 addition & 1 deletion lib/enum_machine/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module EnumMachine
VERSION = "2.0.0"
VERSION = "2.0.1"
end
11 changes: 10 additions & 1 deletion spec/enum_machine/active_record_enum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,23 @@ def am_i_choice?
Object.const_set(:TestModelSerialize, model)
m = TestModelSerialize.create(state: "choice", color: "wrong")

unserialized_m = Marshal.load(Marshal.dump(m)) # rubocop:disable Gp/UnsafeYamlMarshal
unserialized_m = Marshal.load(Marshal.dump(m))

expect(unserialized_m.state).to be_choice
expect(unserialized_m.class::STATE::CHOICE).to eq("choice")
expect(unserialized_m.color).to eq("wrong")
expect(unserialized_m.color.red?).to be(false)
end

it "serialize value" do
Object.const_set(:TestModelSerialize, model)
value = TestModelSerialize::STATE["choice"]
value_after_serialize = Marshal.load(Marshal.dump(value))

expect(value_after_serialize).to eq(value)
expect(value_after_serialize.choice?).to be(true)
end

it "returns state value by []" do
expect(model::STATE["in_delivery"]).to eq "in_delivery"
expect(model::STATE["in_delivery"].in_delivery?).to be(true)
Expand Down
12 changes: 10 additions & 2 deletions spec/enum_machine/driver_simple_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def initialize(state)

it "keeps decorating on serialization" do
m = TestClassWithDecorator.new("choice")
unserialized_m = Marshal.load(Marshal.dump(m)) # rubocop:disable Gp/UnsafeYamlMarshal
unserialized_m = Marshal.load(Marshal.dump(m))
expect(unserialized_m.state.am_i_choice?).to be(true)
end

Expand All @@ -145,9 +145,17 @@ def initialize(state)
it "serialize class" do
m = TestClass.new("choice")

unserialized_m = Marshal.load(Marshal.dump(m)) # rubocop:disable Gp/UnsafeYamlMarshal
unserialized_m = Marshal.load(Marshal.dump(m))

expect(unserialized_m.state).to be_choice
expect(unserialized_m.class::STATE::CHOICE).to eq "choice"
end

it "serialize value" do
value = TestClass::STATE["choice"]
value_after_serialize = Marshal.load(Marshal.dump(value))

expect(value_after_serialize).to eq(value)
expect(value_after_serialize.choice?).to be(true)
end
end
Loading