symbolize 3.2.0 → 3.3.0pre

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.rdoc CHANGED
@@ -175,7 +175,22 @@ As the name suggest, the symbol you choose as default will be set in new objects
175
175
  u.save # => validation fails
176
176
 
177
177
 
178
- == Examples Helpers
178
+ == Model Helpers
179
+
180
+
181
+ You may call `Class.get_attr_values` anywhere to get a nice array.
182
+ Works nice with dropdowns. Examples:
183
+
184
+ class Coffee
185
+ symbolize :genetic, :in => [:arabica, :robusta, :blend]
186
+ end
187
+
188
+ Somewhere on a view:
189
+
190
+ = select_tag :kind, Coffee.get_genetic_values
191
+
192
+
193
+ == View Helpers
179
194
 
180
195
  <% form_for @user do |f| %>
181
196
  <%= f.radio_sym "gender" %>
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.0
1
+ 3.3.0
data/lib/symbolize.rb CHANGED
@@ -60,7 +60,6 @@ module Symbolize
60
60
  default_option = configuration.delete :default
61
61
 
62
62
  unless enum.nil?
63
- # enum = enum.map { |e| e.respond_to?(:to_sym) ? e.to_sym : e}
64
63
  # Little monkeypatching, <1.8 Hashes aren't ordered.
65
64
  hsh = RUBY_VERSION > '1.9' || !defined?("ActiveSupport") ? Hash : ActiveSupport::OrderedHash
66
65
 
@@ -101,13 +100,13 @@ module Symbolize
101
100
  values.each do |value|
102
101
  if value[0].respond_to?(:to_sym)
103
102
  scope_comm.call value[0].to_sym, :conditions => { attr_name => value[0].to_sym }
104
- else
103
+ elsif ActiveRecord::VERSION::STRING <= "3.0"
105
104
  if value[0] == true || value[0] == false
106
- scope_comm.call "with_#{attr_name}", :conditions => { attr_name => true }
107
- scope_comm.call "without_#{attr_name}", :conditions => { attr_name => false }
105
+ scope_comm.call "with_#{attr_name}".to_sym, :conditions => { attr_name => '1' }
106
+ scope_comm.call "without_#{attr_name}".to_sym, :conditions => { attr_name => '0' }
108
107
 
109
- scope_comm.call attr_name.to_sym, :conditions => { attr_name => true }
110
- scope_comm.call "not_#{attr_name}", :conditions => { attr_name => false }
108
+ scope_comm.call attr_name.to_sym, :conditions => { attr_name => '1' }
109
+ scope_comm.call "not_#{attr_name}".to_sym, :conditions => { attr_name => '0' }
111
110
  end
112
111
  end
113
112
  end
@@ -166,13 +165,7 @@ module Symbolize
166
165
  val = { "true" => true, "false" => false }[value]
167
166
  val = symbolize_attribute(value) if val.nil?
168
167
 
169
- current_value = self.send(attr_name)
170
- if current_value == val
171
- current_value
172
- else
173
- self[attr_name] = val
174
- val
175
- end
168
+ self[attr_name] = val #.to_s # rails 3.1 fix
176
169
  end
177
170
  end
178
171
 
@@ -189,12 +182,12 @@ end
189
182
  # only used on symbols returned by read_and_symbolize_attribute,
190
183
  # but unfortunately this is not possible since Symbol is an immediate
191
184
  # value and therefore does not support singleton methods.
192
- class Symbol
193
- def quoted_id
194
- # A symbol can contain almost every character (even a backslash or an
195
- # apostrophe), so make sure to properly quote the string value here.
196
- "'#{ActiveRecord::Base.connection.quote_string(self.to_s)}'"
197
- end
198
- end
185
+ # class Symbol
186
+ # def quoted_id
187
+ # # A symbol can contain almost every character (even a backslash or an
188
+ # # apostrophe), so make sure to properly quote the string value here.
189
+ # "'#{ActiveRecord::Base.connection.quote_string(self.to_s)}'"
190
+ # end
191
+ # end
199
192
 
200
193
  ActiveRecord::Base.send(:include, Symbolize) if ActiveRecord::VERSION::MAJOR >= 3
@@ -1,5 +1,5 @@
1
1
  class CreateTestingStructure < ActiveRecord::Migration
2
- def self.up
2
+ def change
3
3
  create_table :users do |t|
4
4
  t.string :name, :so, :gui, :other, :status, :language, :kind
5
5
  t.string :limited, :limit => 10
@@ -22,8 +22,4 @@ class CreateTestingStructure < ActiveRecord::Migration
22
22
  t.integer :lvl, :null => false
23
23
  end
24
24
  end
25
-
26
- def self.down
27
- drop_table :users
28
- end
29
25
  end
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,7 @@ begin
4
4
  rescue LoadError
5
5
  require 'rspec'
6
6
  end
7
+ require 'pry'
7
8
 
8
9
  $LOAD_PATH.unshift(File.dirname(__FILE__))
9
10
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -12,13 +13,18 @@ require 'action_controller'
12
13
  require 'action_view'
13
14
  require 'symbolize'
14
15
  require File.join(File.dirname(__FILE__), '..', 'init')
16
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") #'postgresql', :database => 'symbolize_test', :username => 'postgres')
17
+
18
+ if ActiveRecord::VERSION::STRING >= "3.1"
19
+ ActiveRecord::Migrator.migrate("spec/db")
20
+ else
21
+ require "db/001_create_testing_structure"
22
+ CreateTestingStructure.migrate(:up)
23
+ end
15
24
 
16
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
17
- require File.dirname(__FILE__) + "/db/create_testing_structure"
18
25
  I18n.load_path += Dir[File.join(File.dirname(__FILE__), "locales", "*.{rb,yml}")]
19
26
  I18n.default_locale = "pt"
20
- CreateTestingStructure.migrate(:up)
21
27
 
22
- puts "Running AR #{ActiveRecord::VERSION::MAJOR}"
28
+ puts "Running AR #{ActiveRecord::VERSION::STRING}"
23
29
  # Spec::Runner.configure do |config|
24
30
  # end
@@ -68,7 +68,7 @@ describe "Symbolize" do
68
68
  it "test_symbolize_symbol" do
69
69
  @user.status = :active
70
70
  @user.status.should eql(:active)
71
- @user.status_before_type_cast.should eql('active')
71
+ @user.status_before_type_cast.should eql(:active)
72
72
  # @user.read_attribute(:status).should eql('active')
73
73
  end
74
74
 
@@ -94,6 +94,7 @@ describe "Symbolize" do
94
94
  end
95
95
 
96
96
  it "test_symbols_quoted_id" do
97
+ pending
97
98
  @user.status = :active
98
99
  @user.status.quoted_id.should eql("'active'")
99
100
  end
@@ -390,10 +391,12 @@ describe "Symbolize" do
390
391
 
391
392
  return_value = @anna.language = :pt
392
393
  return_value.should == :pt
394
+ p @anna.changes
393
395
  @anna.language_changed?.should be_false
394
396
  end
395
397
  end
396
398
 
399
+ if ActiveRecord::VERSION::STRING <= "3.0"
397
400
  describe "Named Scopes" do
398
401
 
399
402
  before do
@@ -426,6 +429,7 @@ describe "Symbolize" do
426
429
  end
427
430
 
428
431
  end
432
+ end
429
433
 
430
434
  end
431
435
 
data/symbolize.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{symbolize}
8
- s.version = "3.2.0"
8
+ s.version = "3.3.0pre"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marcos Piccinini"]
12
- s.date = %q{2011-05-26}
12
+ s.date = %q{2011-07-12}
13
13
  s.description = %q{ActiveRecord enums with i18n}
14
14
  s.email = %q{x@nofxx.com}
15
15
  s.extra_rdoc_files = [
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  "lib/symbolize/railtie.rb",
27
27
  "lib/symbolize/symbolize_helper.rb",
28
28
  "rails/init.rb",
29
- "spec/db/create_testing_structure.rb",
29
+ "spec/db/001_create_testing_structure.rb",
30
30
  "spec/locales/en.yml",
31
31
  "spec/locales/pt.yml",
32
32
  "spec/spec_helper.rb",
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: symbolize
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ prerelease: true
5
5
  segments:
6
6
  - 3
7
- - 2
8
- - 0
9
- version: 3.2.0
7
+ - 3
8
+ - 0pre
9
+ version: 3.3.0pre
10
10
  platform: ruby
11
11
  authors:
12
12
  - Marcos Piccinini
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-05-26 00:00:00 -03:00
17
+ date: 2011-07-12 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -62,7 +62,7 @@ files:
62
62
  - lib/symbolize/railtie.rb
63
63
  - lib/symbolize/symbolize_helper.rb
64
64
  - rails/init.rb
65
- - spec/db/create_testing_structure.rb
65
+ - spec/db/001_create_testing_structure.rb
66
66
  - spec/locales/en.yml
67
67
  - spec/locales/pt.yml
68
68
  - spec/spec_helper.rb