Skip to content

Commit

Permalink
test: define_enum_methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hatsu38 committed Aug 27, 2024
1 parent 44fdbf1 commit 099a1f1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions spec/enum/enum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,35 @@ class Neighborhood < ActiveHash::Base
expect(Movie::THE_INFORMANT.name).to eq('The Informant!')
expect(Movie::IN_OUT.name).to eq('In & Out')
end

describe "define_enum_methods" do
class Movie < ActiveHash::Base
include ActiveHash::Enum
include ActiveHash::Associations

self.data = [
{:name => 'Die Hard 2', :rating => '4.3'},
{:name => 'The Informant!', :rating => '4.3'},
{:name => 'In & Out', :rating => '4.3'}
]

enum_accessor :name
end

it "defines a method for each enum value" do
expect(Movie::DIE_HARD_2.die_hard_2?).to be_truthy
expect(Movie::DIE_HARD_2.the_informant?).to be_falsey
expect(Movie::DIE_HARD_2.in_out?).to be_falsey

expect(Movie::THE_INFORMANT.the_informant?).to be_truthy
expect(Movie::THE_INFORMANT.die_hard_2?).to be_falsey
expect(Movie::THE_INFORMANT.in_out?).to be_falsey

expect(Movie::IN_OUT.in_out?).to be_truthy
expect(Movie::IN_OUT.die_hard_2?).to be_falsey
expect(Movie::IN_OUT.the_informant?).to be_falsey
end
end
end

context "ActiveHash with an enum_accessor set" do
Expand Down

0 comments on commit 099a1f1

Please sign in to comment.