classy_enum 0.6.0 → 0.6.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.1
data/classy_enum.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{classy_enum}
8
- s.version = "0.6.0"
8
+ s.version = "0.6.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Peter Brown"]
12
- s.date = %q{2010-11-13}
12
+ s.date = %q{2010-12-12}
13
13
  s.description = %q{A utility that adds class based enum functionality to ActiveRecord attributes}
14
14
  s.email = %q{github@lette.us}
15
15
  s.extra_rdoc_files = [
@@ -4,7 +4,7 @@ module ClassyEnum
4
4
  enum_class = object.send(method)
5
5
 
6
6
  if enum_class.nil?
7
- enum_class = method.to_s.capitalize.constantize rescue Error.invalid_classy_enum_object(method)
7
+ enum_class = (options[:enum_class] || method).to_s.classify.constantize rescue Error.invalid_classy_enum_object(method)
8
8
  options[:collection] = enum_class.select_options
9
9
  else
10
10
  Error.invalid_classy_enum_object unless enum_class.respond_to? :enum_classes
data/lib/classy_enum.rb CHANGED
@@ -47,7 +47,7 @@ module ClassyEnum
47
47
  module ClassMethods
48
48
 
49
49
  def build(option)
50
- return nil if option.nil?
50
+ return option if option.blank?
51
51
  return TypeError.new("Valid #{self} options are #{self.valid_options}") unless self::OPTIONS.include? option.to_sym
52
52
  Object.const_get("#{self}#{option.to_s.camelize}").new
53
53
  end
@@ -33,6 +33,28 @@ describe 'using enum_select input' do
33
33
  end
34
34
 
35
35
  context "when building a form with a classy_enum select, but the existing value is nil" do
36
+ before(:each) do
37
+ @output = semantic_form_for(Dog.new, :url => "/") do |builder|
38
+ concat(builder.input(:other_breed, :as => :enum_select, :enum_class => :breed))
39
+ end
40
+ end
41
+
42
+ it "should produce a form tag" do
43
+ @output.should =~ /<form/
44
+ end
45
+
46
+ it "should produce an unselected option tag for Golden Retriever" do
47
+ regex = Regexp.new("<option value=\\\"golden_retriever\\\">Golden Retriever")
48
+ @output.should =~ regex
49
+ end
50
+
51
+ it "should produce an unselected option tag for Snoop" do
52
+ regex = Regexp.new("<option value=\\\"snoop\\\">Snoop")
53
+ @output.should =~ regex
54
+ end
55
+ end
56
+
57
+ context "when building a form with a classy_enum select, using the enum_attr option" do
36
58
  before(:each) do
37
59
  @output = semantic_form_for(Dog.new, :url => "/") do |builder|
38
60
  concat(builder.input(:breed, :as => :enum_select))
data/spec/spec_helper.rb CHANGED
@@ -15,6 +15,7 @@ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":me
15
15
  ActiveRecord::Schema.define(:version => 1) do
16
16
  create_table :dogs, :force => true do |t|
17
17
  t.string :breed
18
+ t.string :other_breed
18
19
  end
19
20
 
20
21
  create_table :things, :force => true do |t|
@@ -28,6 +29,7 @@ end
28
29
 
29
30
  class Dog < ActiveRecord::Base
30
31
  classy_enum_attr :breed
32
+ classy_enum_attr :breed, :other_breed
31
33
  end
32
34
 
33
35
  module FormtasticSpecHelper
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classy_enum
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 0
10
- version: 0.6.0
9
+ - 1
10
+ version: 0.6.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Peter Brown
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-13 00:00:00 -05:00
18
+ date: 2010-12-12 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency