classy_enum 0.3.0 → 0.3.2
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/README.textile +7 -1
- data/VERSION +1 -1
- data/classy_enum.gemspec +4 -2
- data/lib/classy_enum.rb +2 -2
- data/lib/classy_enum/classy_enum_attributes.rb +2 -2
- data/spec/classy_enum_attributes_spec.rb +0 -4
- data/spec/classy_enum_helper_spec.rb +32 -0
- data/spec/spec_helper.rb +41 -2
- metadata +6 -4
data/README.textile
CHANGED
@@ -2,9 +2,15 @@ h1. classy_enum
|
|
2
2
|
|
3
3
|
ClassyEnum adds class-based enumerator functionality to your ActiveRecord model's attributes.
|
4
4
|
|
5
|
+
h2. Requirements
|
6
|
+
|
7
|
+
*Rails:* ClassyEnum should work with any version of Rails 2.3.x. Rails 3 support is in the works, and should be ready soon.
|
8
|
+
|
9
|
+
*Ruby:* ClassyEnum has been tested with Ruby 1.8.7 and 1.9.2.
|
10
|
+
|
5
11
|
h2. Installation
|
6
12
|
|
7
|
-
|
13
|
+
The gem is hosted at "rubygems.org":https://rubygems.org/gems/classy_enum
|
8
14
|
|
9
15
|
It can be installed with:
|
10
16
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
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.3.
|
8
|
+
s.version = "0.3.2"
|
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-10-
|
12
|
+
s.date = %q{2010-10-16}
|
13
13
|
s.description = %q{A utility that adds class based enum functionaltiy to ActiveRecord attributes}
|
14
14
|
s.email = %q{github@lette.us}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/classy_enum/classy_enum_attributes.rb",
|
32
32
|
"lib/classy_enum/classy_enum_helper.rb",
|
33
33
|
"spec/classy_enum_attributes_spec.rb",
|
34
|
+
"spec/classy_enum_helper_spec.rb",
|
34
35
|
"spec/classy_enum_spec.rb",
|
35
36
|
"spec/spec.opts",
|
36
37
|
"spec/spec_helper.rb"
|
@@ -42,6 +43,7 @@ Gem::Specification.new do |s|
|
|
42
43
|
s.summary = %q{A class based enumerator utility for Ruby on Rails}
|
43
44
|
s.test_files = [
|
44
45
|
"spec/classy_enum_attributes_spec.rb",
|
46
|
+
"spec/classy_enum_helper_spec.rb",
|
45
47
|
"spec/classy_enum_spec.rb",
|
46
48
|
"spec/spec_helper.rb"
|
47
49
|
]
|
data/lib/classy_enum.rb
CHANGED
@@ -24,7 +24,7 @@ end
|
|
24
24
|
|
25
25
|
module ClassyEnum
|
26
26
|
|
27
|
-
module
|
27
|
+
module SuperClassMethods
|
28
28
|
|
29
29
|
def new(option)
|
30
30
|
self::OPTION_HASH[option] || TypeError.new("Valid #{self} options are #{self.valid_options}")
|
@@ -51,7 +51,7 @@ module ClassyEnum
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def self.included(other)
|
54
|
-
other.extend
|
54
|
+
other.extend SuperClassMethods
|
55
55
|
|
56
56
|
other.const_set("OPTION_HASH", Hash.new)
|
57
57
|
|
@@ -13,12 +13,12 @@ module ClassyEnumAttributes
|
|
13
13
|
|
14
14
|
# Define getter method
|
15
15
|
define_method method do
|
16
|
-
klass.new(super)
|
16
|
+
klass.new(super())
|
17
17
|
end
|
18
18
|
|
19
19
|
# Define setter method
|
20
20
|
define_method "#{method}=" do |value|
|
21
|
-
super
|
21
|
+
super(value.to_s)
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
describe 'using enum_select input' do
|
4
|
+
include FormtasticSpecHelper
|
5
|
+
|
6
|
+
Formtastic::SemanticFormHelper.builder = ClassyEnumHelper::SemanticFormBuilder
|
7
|
+
|
8
|
+
context "when building a form with a classy_enum select" do
|
9
|
+
before(:each) do
|
10
|
+
@output_buffer = ""
|
11
|
+
@output = semantic_form_for(Dog.new(:breed => :snoop), :url => "/") do |builder|
|
12
|
+
concat(builder.input(:breed, :as => :enum_select))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should produce a form tag" do
|
17
|
+
@output.should =~ /<form/
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should produce an unselected option tag for Golden Retriever" do
|
21
|
+
regex = Regexp.new("<option value=\\\"golden_retriever\\\">Golden Retriever")
|
22
|
+
@output.should =~ regex
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should produce an selected option tag for Snoop" do
|
26
|
+
regex = Regexp.new("<option value=\\\"snoop\\\" selected=\\\"selected\\\">Snoop")
|
27
|
+
@output.should =~ regex
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -4,8 +4,9 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'spec'
|
6
6
|
|
7
|
-
require '
|
8
|
-
require '
|
7
|
+
require 'activerecord'
|
8
|
+
require 'actionpack'
|
9
|
+
require 'action_controller'
|
9
10
|
require 'formtastic'
|
10
11
|
require 'classy_enum'
|
11
12
|
|
@@ -26,3 +27,41 @@ module Breed
|
|
26
27
|
|
27
28
|
include ClassyEnum
|
28
29
|
end
|
30
|
+
|
31
|
+
class Dog < ActiveRecord::Base
|
32
|
+
classy_enum_attr :breed
|
33
|
+
end
|
34
|
+
|
35
|
+
module FormtasticSpecHelper
|
36
|
+
include ActionPack
|
37
|
+
include ActionView::Context if defined?(ActionView::Context)
|
38
|
+
include ActionController::RecordIdentifier
|
39
|
+
include ActionView::Helpers::FormHelper
|
40
|
+
include ActionView::Helpers::FormTagHelper
|
41
|
+
include ActionView::Helpers::FormOptionsHelper
|
42
|
+
include ActionView::Helpers::UrlHelper
|
43
|
+
include ActionView::Helpers::TagHelper
|
44
|
+
include ActionView::Helpers::TextHelper
|
45
|
+
include ActionView::Helpers::DateHelper
|
46
|
+
include ActionView::Helpers::CaptureHelper
|
47
|
+
include ActionView::Helpers::AssetTagHelper
|
48
|
+
include ActiveSupport
|
49
|
+
include ActionView::Helpers::ActiveRecordHelper if defined?(ActionView::Helpers::ActiveRecordHelper)
|
50
|
+
include ActionView::Helpers::ActiveModelHelper if defined?(ActionView::Helpers::ActiveModelHelper)
|
51
|
+
include ActionController::PolymorphicRoutes if defined?(ActionController::PolymorphicRoutes)
|
52
|
+
include Formtastic::SemanticFormHelper
|
53
|
+
|
54
|
+
def self.included(base)
|
55
|
+
base.class_eval do
|
56
|
+
|
57
|
+
attr_accessor :output_buffer
|
58
|
+
|
59
|
+
def protect_against_forgery?
|
60
|
+
false
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
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-10-
|
18
|
+
date: 2010-10-16 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- lib/classy_enum/classy_enum_attributes.rb
|
74
74
|
- lib/classy_enum/classy_enum_helper.rb
|
75
75
|
- spec/classy_enum_attributes_spec.rb
|
76
|
+
- spec/classy_enum_helper_spec.rb
|
76
77
|
- spec/classy_enum_spec.rb
|
77
78
|
- spec/spec.opts
|
78
79
|
- spec/spec_helper.rb
|
@@ -112,5 +113,6 @@ specification_version: 3
|
|
112
113
|
summary: A class based enumerator utility for Ruby on Rails
|
113
114
|
test_files:
|
114
115
|
- spec/classy_enum_attributes_spec.rb
|
116
|
+
- spec/classy_enum_helper_spec.rb
|
115
117
|
- spec/classy_enum_spec.rb
|
116
118
|
- spec/spec_helper.rb
|