active_enum 0.5.0 → 0.5.1

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.
@@ -3,12 +3,13 @@ module ActiveEnum
3
3
  module ActsAsEnum
4
4
 
5
5
  def self.included(base)
6
- base.extend ClassMethods
6
+ base.extend MacroMethods
7
7
  end
8
8
 
9
- module ClassMethods
9
+ module MacroMethods
10
10
 
11
11
  def acts_as_enum(options={})
12
+ extend ClassMethods
12
13
  class_inheritable_accessor :active_enum_options
13
14
  self.active_enum_options = options.reverse_merge(:name_column => 'name')
14
15
  named_scope :enum_values,
@@ -17,6 +18,10 @@ module ActiveEnum
17
18
  :order => "#{primary_key} #{active_enum_options[:order]}"
18
19
  end
19
20
 
21
+ end
22
+
23
+ module ClassMethods
24
+
20
25
  def ids
21
26
  enum_values.map {|v| v.id }
22
27
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveEnum
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
@@ -4,33 +4,47 @@ class Person < ActiveRecord::Base
4
4
  acts_as_enum :name_column => 'first_name'
5
5
  end
6
6
 
7
+ class TestPerson < ActiveRecord::Base
8
+ def self.extended_modules
9
+ class << self
10
+ self.included_modules
11
+ end
12
+ end
13
+ end
14
+
7
15
  describe ActiveEnum::ActsAsEnum do
8
16
  before(:all) do
9
17
  Person.create!(:first_name => 'Dave', :last_name => 'Smith')
10
18
  Person.create!(:first_name => 'John', :last_name => 'Doe')
11
19
  end
12
20
 
13
- it 'return name column value when passing id to [] method' do
21
+ it "should mixin enum class methods only when act_as_enum defined" do
22
+ TestPerson.extended_modules.should_not include(ActiveEnum::ActsAsEnum::ClassMethods)
23
+ TestPerson.acts_as_enum
24
+ TestPerson.extended_modules.should include(ActiveEnum::ActsAsEnum::ClassMethods)
25
+ end
26
+
27
+ it "should return name column value when passing id to [] method" do
14
28
  Person[1].should == 'Dave'
15
29
  end
16
30
 
17
- it 'return id column value when passing string name to [] method' do
31
+ it "should return id column value when passing string name to [] method" do
18
32
  Person['Dave'].should == 1
19
33
  Person['dave'].should == 1
20
34
  end
21
35
 
22
- it 'return id column value when passing symbol name to [] method' do
36
+ it "should return id column value when passing symbol name to [] method" do
23
37
  Person[:dave].should == 1
24
38
  end
25
39
 
26
- it 'should return array for select helpers from to_select' do
40
+ it "should return array for select helpers from to_select" do
27
41
  Person.to_select.should == [['Dave', 1], ['John', 2]]
28
42
  end
29
43
 
30
- it 'should return sorted array from order value for select helpers from to_select' do
44
+ it "should return sorted array from order value for select helpers from to_select" do
31
45
  Person.class_eval do
32
46
  acts_as_enum :name_column => 'first_name', :order => :desc
33
47
  end
34
- Person.to_select.should == [['John', 2], ['Dave', 1]]
48
+ Person.to_select.should == [['John', 2], ['Dave', 1]]
35
49
  end
36
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Meehan
@@ -9,7 +9,7 @@ autorequire: active_enum
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-24 00:00:00 +11:00
12
+ date: 2009-12-15 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -25,17 +25,17 @@ files:
25
25
  - MIT-LICENSE
26
26
  - README.rdoc
27
27
  - Rakefile
28
- - lib/active_enum.rb
28
+ - lib/active_enum/acts_as_enum.rb
29
29
  - lib/active_enum/base.rb
30
- - lib/active_enum/version.rb
31
30
  - lib/active_enum/extensions.rb
32
- - lib/active_enum/acts_as_enum.rb
33
- - spec/schema.rb
34
- - spec/active_enum_spec.rb
35
- - spec/spec_helper.rb
31
+ - lib/active_enum/version.rb
32
+ - lib/active_enum.rb
36
33
  - spec/active_enum/acts_as_enum_spec.rb
37
- - spec/active_enum/extensions_spec.rb
38
34
  - spec/active_enum/base_spec.rb
35
+ - spec/active_enum/extensions_spec.rb
36
+ - spec/active_enum_spec.rb
37
+ - spec/schema.rb
38
+ - spec/spec_helper.rb
39
39
  has_rdoc: true
40
40
  homepage: http://github.com/adzap/active_enum
41
41
  licenses: []
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  requirements: []
61
61
 
62
62
  rubyforge_project: active_enum
63
- rubygems_version: 1.3.4
63
+ rubygems_version: 1.3.5
64
64
  signing_key:
65
65
  specification_version: 3
66
66
  summary: Define enum classes in Rails and use them to enumerate ActiveRecord attributes