active_enum 0.9.6 → 0.9.7

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/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ [0.9.7] : 2011-12-11
2
+ - Add Formtastic 2 form helper. [fbuenemann]
3
+
1
4
  [0.9.6] : 2011-09-13
2
5
  - Fix regression in active_enum_for in models without enumerated attributes. (issue #8). [jasoncodes]
3
6
 
data/Rakefile CHANGED
@@ -24,3 +24,8 @@ end
24
24
 
25
25
  desc 'Default: run specs.'
26
26
  task :default => :spec
27
+
28
+ task :all do
29
+ sh "export FORMTASTIC=2.0 && bundle install && bundle exec rake"
30
+ sh "export FORMTASTIC=1.2 && bundle install && bundle exec rake"
31
+ end
@@ -0,0 +1,29 @@
1
+ module Formtastic
2
+ module Inputs
3
+ class EnumInput < Formtastic::Inputs::SelectInput
4
+
5
+ def raw_collection
6
+ @raw_collection ||= begin
7
+ raise "Attribute '#{@method}' has no enum class" unless enum = @object.class.active_enum_for(@method)
8
+ enum.to_select
9
+ end
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+
16
+ module ActiveEnum
17
+ module FormHelpers
18
+ module Formtastic2
19
+
20
+ def default_input_type(method, options)
21
+ return :enum if @object.class.respond_to?(:active_enum_for) && @object.class.active_enum_for(method)
22
+ super
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+
29
+ Formtastic::FormBuilder.send :include, ActiveEnum::FormHelpers::Formtastic2
@@ -1,3 +1,3 @@
1
1
  module ActiveEnum
2
- VERSION = '0.9.6'
2
+ VERSION = '0.9.7'
3
3
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require "spec_helper"
2
2
 
3
3
  describe ActiveEnum::ActsAsEnum do
4
4
  class Person < ActiveRecord::Base
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require "spec_helper"
2
2
 
3
3
  describe ActiveEnum::Base do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require "spec_helper"
2
2
 
3
3
  describe ActiveEnum::Extensions do
4
4
  class Sex < ActiveEnum::Base
@@ -0,0 +1,80 @@
1
+ require "spec_helper"
2
+
3
+ require 'formtastic'
4
+
5
+ if Formtastic.const_defined?(:VERSION) && Formtastic::VERSION =~ /^2\./
6
+ require 'active_enum/form_helpers/formtastic2'
7
+
8
+ describe ActiveEnum::FormHelpers::Formtastic2, :type => :helper do
9
+ include Rails.application.routes.url_helpers
10
+ include Formtastic::Helpers::FormHelper
11
+
12
+ before do
13
+ reset_class Person do
14
+ enumerate :sex do
15
+ value :id => 1, :name => 'Male'
16
+ value :id => 2, :name => 'Female'
17
+ end
18
+ end
19
+ end
20
+
21
+ it "should use enum input type for enumerated attribute" do
22
+ output = semantic_form_for(Person.new, :url => people_path) do |f|
23
+ concat f.input(:sex)
24
+ end
25
+ output.should have_selector('select#person_sex')
26
+ output.should have_xpath('//option[@value=1]', :content => 'Male')
27
+ output.should have_xpath('//option[@value=2]', :content => 'Female')
28
+ end
29
+
30
+ it "should use explicit :enum input type" do
31
+ output = semantic_form_for(Person.new, :url => people_path) do |f|
32
+ concat f.input(:sex, :as => :enum)
33
+ end
34
+ output.should have_selector('select#person_sex')
35
+ output.should have_xpath('//option[@value=1]', :content => 'Male')
36
+ output.should have_xpath('//option[@value=2]', :content => 'Female')
37
+ end
38
+
39
+ it "should not use enum input type if :as option indicates other type" do
40
+ output = semantic_form_for(Person.new, :url => people_path) do |f|
41
+ concat f.input(:sex, :as => :string)
42
+ end
43
+ output.should have_selector('input#person_sex')
44
+ end
45
+
46
+ it "should raise error if attribute for enum input is not enumerated" do
47
+ expect {
48
+ semantic_form_for(Person.new, :url => people_path) do |f|
49
+ f.input(:attending, :as => :enum)
50
+ end
51
+ }.should raise_error "Attribute 'attending' has no enum class"
52
+ end
53
+
54
+ it "should not use enum input type if class does not support ActiveEnum" do
55
+ output = semantic_form_for(NotActiveRecord.new, :as => :not_active_record, :url => people_path) do |f|
56
+ concat f.input(:name)
57
+ end
58
+ output.should have_selector('input#not_active_record_name')
59
+ end
60
+
61
+ it "should allow non-enum fields to use default input determination" do
62
+ output = semantic_form_for(Person.new, :url => people_path) do |f|
63
+ concat f.input(:first_name)
64
+ end
65
+ output.should have_selector('input#person_first_name')
66
+ end
67
+
68
+ it "should allow models without enumerated attributes to behave normally" do
69
+ output = semantic_form_for(NoEnumPerson.new, :url => people_path) do |f|
70
+ concat f.input(:first_name)
71
+ end
72
+ output.should have_selector('input#no_enum_person_first_name')
73
+ end
74
+
75
+ def people_path
76
+ '/people'
77
+ end
78
+ end
79
+
80
+ end
@@ -1,6 +1,12 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
1
+ require "spec_helper"
2
2
 
3
- require 'formtastic'
3
+ begin
4
+ require 'formtastic'
5
+ require 'formtastic/version'
6
+ rescue LoadError
7
+ end
8
+
9
+ unless Formtastic.const_defined?(:VERSION)
4
10
  require 'active_enum/form_helpers/formtastic'
5
11
 
6
12
  describe ActiveEnum::FormHelpers::Formtastic, :type => :helper do
@@ -73,3 +79,5 @@ describe ActiveEnum::FormHelpers::Formtastic, :type => :helper do
73
79
  '/people'
74
80
  end
75
81
  end
82
+
83
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
1
+ require "spec_helper"
2
2
 
3
3
  require 'simple_form'
4
4
  require 'active_enum/form_helpers/simple_form'
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
1
+ require "spec_helper"
2
2
 
3
3
  class TestMemoryStoreEnum < ActiveEnum::Base; end
4
4
  class TestOtherAREnum < ActiveEnum::Base; end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require "spec_helper"
2
2
 
3
3
  describe ActiveEnum do
4
4
 
@@ -2,28 +2,30 @@ require 'rspec'
2
2
 
3
3
  require 'rails'
4
4
  require 'active_record'
5
- require 'action_controller'
5
+ require 'action_controller/railtie'
6
6
  require 'action_view'
7
7
  require 'action_mailer'
8
8
 
9
9
  require 'active_enum'
10
10
  require 'active_enum/acts_as_enum'
11
11
 
12
- module Config
12
+ module ActiveEnum
13
13
  class Application < Rails::Application
14
14
  config.generators do |g|
15
15
  g.orm :active_record
16
16
  g.test_framework :rspec, :fixture => false
17
17
  end
18
+ config.active_support.deprecation = :notify
18
19
  end
19
20
  end
21
+ ActiveEnum::Application.initialize!
20
22
 
21
23
  require 'rspec/rails'
22
24
 
23
25
  ActiveRecord::Migration.verbose = false
24
26
  ActiveRecord::Base.establish_connection({:adapter => 'sqlite3', :database => ':memory:'})
25
27
 
26
- require 'schema'
28
+ require 'support/schema'
27
29
 
28
30
  class Person < ActiveRecord::Base; end
29
31
  class NoEnumPerson < ActiveRecord::Base
File without changes
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_enum
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 53
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 6
10
- version: 0.9.6
9
+ - 7
10
+ version: 0.9.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Meehan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-13 00:00:00 +10:00
18
+ date: 2011-12-11 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -55,6 +55,7 @@ files:
55
55
  - lib/active_enum/base.rb
56
56
  - lib/active_enum/extensions.rb
57
57
  - lib/active_enum/form_helpers/formtastic.rb
58
+ - lib/active_enum/form_helpers/formtastic2.rb
58
59
  - lib/active_enum/form_helpers/simple_form.rb
59
60
  - lib/active_enum/railtie.rb
60
61
  - lib/active_enum/storage/abstract_store.rb
@@ -65,12 +66,13 @@ files:
65
66
  - spec/active_enum/acts_as_enum_spec.rb
66
67
  - spec/active_enum/base_spec.rb
67
68
  - spec/active_enum/extensions_spec.rb
69
+ - spec/active_enum/form_helpers/formtastic2_spec.rb
68
70
  - spec/active_enum/form_helpers/formtastic_spec.rb
69
71
  - spec/active_enum/form_helpers/simple_form_spec.rb
70
72
  - spec/active_enum/storage/memory_store_spec.rb
71
73
  - spec/active_enum_spec.rb
72
- - spec/schema.rb
73
74
  - spec/spec_helper.rb
75
+ - spec/support/schema.rb
74
76
  has_rdoc: true
75
77
  homepage: http://github.com/adzap/active_enum
76
78
  licenses: []
@@ -109,9 +111,10 @@ test_files:
109
111
  - spec/active_enum/acts_as_enum_spec.rb
110
112
  - spec/active_enum/base_spec.rb
111
113
  - spec/active_enum/extensions_spec.rb
114
+ - spec/active_enum/form_helpers/formtastic2_spec.rb
112
115
  - spec/active_enum/form_helpers/formtastic_spec.rb
113
116
  - spec/active_enum/form_helpers/simple_form_spec.rb
114
117
  - spec/active_enum/storage/memory_store_spec.rb
115
118
  - spec/active_enum_spec.rb
116
- - spec/schema.rb
117
119
  - spec/spec_helper.rb
120
+ - spec/support/schema.rb