selectable_attr_rails 0.3.11 → 0.3.12

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,42 +1,5 @@
1
1
  require 'rubygems'
2
- gem 'rspec', '>= 1.1.4'
3
2
  require 'rake'
4
- require 'rake/rdoctask'
5
- require 'spec/rake/spectask'
6
- require 'spec/rake/verify_rcov'
7
-
8
- desc 'Default: run unit tests.'
9
- task :default => :spec
10
-
11
- task :pre_commit => [:spec, 'coverage:verify']
12
-
13
- desc 'Run all specs under spec/**/*_spec.rb'
14
- Spec::Rake::SpecTask.new(:spec => 'coverage:clean') do |t|
15
- t.spec_files = FileList['spec/**/*_spec.rb']
16
- t.spec_opts = ["-c", "--diff"]
17
- t.rcov = true
18
- t.rcov_opts = ["--include-file", "lib\/*\.rb", "--exclude", "spec\/"]
19
- end
20
-
21
- desc 'Generate documentation for the selectable_attr_rails plugin.'
22
- Rake::RDocTask.new(:rdoc) do |rdoc|
23
- rdoc.rdoc_dir = 'rdoc'
24
- rdoc.title = 'SelectableAttrRails'
25
- rdoc.options << '--line-numbers' << '--inline-source'
26
- rdoc.rdoc_files.include('README')
27
- rdoc.rdoc_files.include('lib/**/*.rb')
28
- end
29
-
30
- namespace :coverage do
31
- desc "Delete aggregate coverage data."
32
- task(:clean) { rm_f "coverage" }
33
-
34
- desc "verify coverage threshold via RCov"
35
- RCov::VerifyTask.new(:verify => :spec) do |t|
36
- t.threshold = 100.0 # Make sure you have rcov 0.7 or higher!
37
- t.index_html = 'coverage/index.html'
38
- end
39
- end
40
3
 
41
4
  begin
42
5
  require 'jeweler'
@@ -51,7 +14,62 @@ begin
51
14
  s.add_dependency("activerecord", ">= 2.0.2")
52
15
  s.add_dependency("actionpack", ">= 2.0.2")
53
16
  s.add_dependency("selectable_attr", ">= 0.3.11")
17
+ s.add_development_dependency "rspec", ">= 1.3.1"
18
+ s.add_development_dependency "sqlite3-ruby"
19
+ s.add_development_dependency "rcov"
20
+ end
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
+ end
24
+
25
+
26
+ require 'spec/rake/spectask'
27
+ Spec::Rake::SpecTask.new(:spec) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.spec_files = FileList['spec/**/*_spec.rb']
30
+ end
31
+
32
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
33
+ spec.libs << 'lib' << 'spec'
34
+ spec.pattern = 'spec/**/*_spec.rb'
35
+ spec.rcov = true
36
+ end
37
+
38
+ task :spec => :check_dependencies
39
+
40
+ begin
41
+ require 'reek/adapters/rake_task'
42
+ Reek::RakeTask.new do |t|
43
+ t.fail_on_error = true
44
+ t.verbose = false
45
+ t.source_files = 'lib/**/*.rb'
46
+ end
47
+ rescue LoadError
48
+ task :reek do
49
+ abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
50
+ end
51
+ end
52
+
53
+ begin
54
+ require 'roodi'
55
+ require 'roodi_task'
56
+ RoodiTask.new do |t|
57
+ t.verbose = false
54
58
  end
55
59
  rescue LoadError
56
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
60
+ task :roodi do
61
+ abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
62
+ end
63
+ end
64
+
65
+ task :default => :spec
66
+
67
+ require 'rake/rdoctask'
68
+ Rake::RDocTask.new do |rdoc|
69
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
70
+
71
+ rdoc.rdoc_dir = 'rdoc'
72
+ rdoc.title = "range_dsl #{version}"
73
+ rdoc.rdoc_files.include('README*')
74
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
75
  end
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :patch: 11
3
- :build:
4
2
  :major: 0
5
3
  :minor: 3
4
+ :patch: 12
5
+ :build:
@@ -9,7 +9,7 @@ if defined?(I18n)
9
9
  enums.each do |instance|
10
10
  unless instance.i18n_scope
11
11
  SelectableAttrRails.logger.debug("no i18n_scope of #{instance.inspect}")
12
- next
12
+ next
13
13
  end
14
14
  paths = instance.i18n_scope.dup
15
15
  current = result
@@ -27,7 +27,7 @@ if defined?(I18n)
27
27
  @i18n_scope = path unless path.empty?
28
28
  @i18n_scope
29
29
  end
30
-
30
+
31
31
  class Entry
32
32
  def name
33
33
  I18n.locale.nil? ? @name :
@@ -7,7 +7,7 @@ module SelectableAttrRails
7
7
  @update_timing = options[:when]
8
8
  self.extend(InstanceMethods) unless respond_to?(:update_entries)
9
9
  end
10
-
10
+
11
11
  module Entry
12
12
 
13
13
  if defined?(I18n)
@@ -20,18 +20,18 @@ module SelectableAttrRails
20
20
  @names_from_db ||= {}
21
21
  @names_from_db[I18n.locale.to_s] = value
22
22
  end
23
-
23
+
24
24
  def name_with_from_db
25
25
  name_from_db || name_without_from_db
26
26
  end
27
27
 
28
28
  else
29
-
29
+
30
30
  attr_accessor :name_from_db
31
31
  def name_with_from_db
32
32
  @name_from_db || name_without_from_db
33
33
  end
34
-
34
+
35
35
  end
36
36
 
37
37
  def self.extended(obj)
@@ -42,18 +42,18 @@ module SelectableAttrRails
42
42
  end
43
43
 
44
44
  end
45
-
45
+
46
46
  module InstanceMethods
47
47
  def entries
48
48
  update_entries if must_be_updated?
49
49
  @entries
50
50
  end
51
-
51
+
52
52
  def must_be_updated?
53
53
  return false if @update_timing == :never
54
54
  return true if @update_timing == :everytime
55
55
  end
56
-
56
+
57
57
  def update_entries
58
58
  unless @original_entries
59
59
  @original_entries = @entries.dup
@@ -68,7 +68,7 @@ module SelectableAttrRails
68
68
  sql = @sql_to_update.gsub(/\:locale/, I18n.locale.to_s.inspect)
69
69
  records = ActiveRecord::Base.connection.select_rows(sql)
70
70
  end
71
-
71
+
72
72
  new_entries = []
73
73
  records.each do |r|
74
74
  if entry = @original_entries.detect{|entry| entry.id == r.first}
@@ -90,6 +90,6 @@ module SelectableAttrRails
90
90
  @entries = new_entries
91
91
  end
92
92
  end
93
-
93
+
94
94
  end
95
95
  end
@@ -1,7 +1,7 @@
1
1
  module SelectableAttrRails::Helpers
2
2
  class AbstractSelectionBuilder
3
3
  attr_reader :entry_hash
4
-
4
+
5
5
  def initialize(object, object_name, method, options, template)
6
6
  @object, @object_name, @method = object, object_name, method
7
7
  @base_name = @object.class.enum_base_name(method.to_s)
@@ -15,7 +15,7 @@ module SelectableAttrRails::Helpers
15
15
  base_name = @object.class.enum_base_name(@method.to_s)
16
16
  @object.send("#{base_name}_hash_array")
17
17
  end
18
-
18
+
19
19
  def enum_hash_array_from_class
20
20
  base_name = @object.class.enum_base_name(@method.to_s)
21
21
  @object.class.send("#{base_name}_hash_array")
@@ -26,19 +26,19 @@ module SelectableAttrRails::Helpers
26
26
  tag.scan(/ id\=\"(.*?)\"/){|s|result = s}
27
27
  return result
28
28
  end
29
-
29
+
30
30
  def add_class_name(options, class_name)
31
31
  (options ||= {}).stringify_keys!
32
32
  (options['class'] ||= '') << ' ' << class_name
33
33
  options
34
34
  end
35
-
35
+
36
36
  def camelize_keys(hash, first_letter = :lower)
37
37
  result = {}
38
38
  hash.each{|key, value|result[key.to_s.camelize(first_letter)] = value}
39
39
  result
40
40
  end
41
-
41
+
42
42
  def update_options(dest, *options_array)
43
43
  result = dest || {}
44
44
  options_array.each do |options|
@@ -50,6 +50,6 @@ module SelectableAttrRails::Helpers
50
50
  end
51
51
  result
52
52
  end
53
-
53
+
54
54
  end
55
55
  end
@@ -2,22 +2,23 @@ require 'selectable_attr_rails/helpers/abstract_selection_helper'
2
2
  module SelectableAttrRails::Helpers
3
3
  module CheckBoxGroupHelper
4
4
  class Builder < SelectableAttrRails::Helpers::AbstractSelectionBuilder
5
-
5
+
6
6
  def initialize(object, object_name, method, options, template)
7
7
  super(object, object_name, method, options, template)
8
8
  @entry_hash_array ||= enum_hash_array_from_object
9
9
  @param_name = "#{@base_name}_ids"
10
10
  @check_box_options = @options.delete(:check_box) || {}
11
11
  end
12
-
12
+
13
13
  def each(&block)
14
- @entry_hash_array.each do |@entry_hash|
14
+ @entry_hash_array.each do |entry_hash|
15
+ @entry_hash= entry_hash
15
16
  @tag_value = @entry_hash[:id].to_s.gsub(/\s/, "_").gsub(/\W/, "")
16
17
  @check_box_id = "#{@object_name}_#{@param_name}_#{@tag_value}"
17
18
  yield(self)
18
19
  end
19
20
  end
20
-
21
+
21
22
  def check_box(options = nil)
22
23
  options = update_options({
23
24
  :id => @check_box_id, :type => 'checkbox', :value => @tag_value,
@@ -26,7 +27,7 @@ module SelectableAttrRails::Helpers
26
27
  options[:checked] = 'checked' if @entry_hash[:select]
27
28
  @template.content_tag("input", nil, options)
28
29
  end
29
-
30
+
30
31
  def label(text = nil, options = nil)
31
32
  @template.content_tag("label", text || @entry_hash[:name],
32
33
  update_options({:for => @check_box_id}, options))
@@ -52,10 +53,10 @@ module SelectableAttrRails::Helpers
52
53
  end
53
54
  end
54
55
  end
55
-
56
+
56
57
  module FormBuilder
57
58
  def check_box_group(method, options = nil, &block)
58
- @template.check_box_group(@object_name, method,
59
+ @template.check_box_group(@object_name, method,
59
60
  (options || {}).merge(:object => @object), &block)
60
61
  end
61
62
  end
@@ -1,10 +1,10 @@
1
1
  module SelectableAttrRails::Helpers
2
2
  module RadioButtonGroupHelper
3
3
  class Builder < SelectableAttrRails::Helpers::AbstractSelectionBuilder
4
-
5
- attr_reader :entry_hash_array
6
- attr_reader :entry_hash
7
- attr_accessor :radio_button_id
4
+
5
+ attr_reader :entry_hash_array
6
+ attr_reader :entry_hash
7
+ attr_accessor :radio_button_id
8
8
 
9
9
  def initialize(object, object_name, method, options, template)
10
10
  super(object, object_name, method, options, template)
@@ -19,12 +19,12 @@ module SelectableAttrRails::Helpers
19
19
  yield(self)
20
20
  end
21
21
  end
22
-
22
+
23
23
  def radio_button(options = nil)
24
- @template.radio_button(@object_name, @method, @entry_hash[:id],
24
+ @template.radio_button(@object_name, @method, @entry_hash[:id],
25
25
  update_options({:id => @radio_button_id}, options))
26
26
  end
27
-
27
+
28
28
  def label(text = nil, options = nil)
29
29
  @template.content_tag("label", text || @entry_hash[:name],
30
30
  update_options({:for => @radio_button_id}, options))
@@ -48,10 +48,10 @@ module SelectableAttrRails::Helpers
48
48
  end
49
49
  end
50
50
  end
51
-
51
+
52
52
  module FormBuilder
53
53
  def radio_button_group(method, options = nil, &block)
54
- @template.radio_button_group(@object_name, method,
54
+ @template.radio_button_group(@object_name, method,
55
55
  (options || {}).merge(:object => @object), &block)
56
56
  end
57
57
  end
@@ -6,7 +6,7 @@ module SelectableAttrRails::Helpers
6
6
  alias_method_chain :select, :attr_enumeable
7
7
  end
8
8
  end
9
-
9
+
10
10
  # def select_with_attr_enumeable(object, method, choices, options = {}, html_options = {})
11
11
  def select_with_attr_enumeable(object_name, method, *args, &block)
12
12
  if args.length > 3
@@ -23,7 +23,7 @@ module SelectableAttrRails::Helpers
23
23
  return single_enum_select(object_name, method, options, html_options, &block) if object.class.respond_to?("#{base_name}_hash_array")
24
24
  raise ArgumentError, "invaliad argument"
25
25
  end
26
-
26
+
27
27
  def single_enum_select(object_name, method, options = {}, html_options = {}, &block)
28
28
  options = update_enum_select_options(options, object_name, method)
29
29
  object = options[:object] # options.delete(:object)
@@ -32,7 +32,7 @@ module SelectableAttrRails::Helpers
32
32
  container = entry_hash_array.map{|hash| [hash[:name].to_s, hash[:id]]}
33
33
  select_without_attr_enumeable(object_name, method, container, options, html_options || {}, &block)
34
34
  end
35
-
35
+
36
36
  def multi_enum_select(object_name, method, options = {}, html_options = {}, &block)
37
37
  html_options = {:size => 5, :multiple => 'multiple'}.update(html_options || {})
38
38
  options = update_enum_select_options(options, object_name, method)
@@ -43,7 +43,7 @@ module SelectableAttrRails::Helpers
43
43
  attr = "#{base_name}_ids"
44
44
  select_without_attr_enumeable(object_name, attr, container, options, html_options, &block)
45
45
  end
46
-
46
+
47
47
  def update_enum_select_options(options, object_name, method)
48
48
  options ||= {}
49
49
  object = (options[:object] ||= instance_variable_get("@#{object_name}"))
@@ -51,7 +51,7 @@ module SelectableAttrRails::Helpers
51
51
  options
52
52
  end
53
53
  end
54
-
54
+
55
55
  module FormBuilder
56
56
  def self.included(base)
57
57
  base.module_eval do
@@ -13,19 +13,19 @@ module SelectableAttrRails
13
13
  def logger=(value)
14
14
  @logger = value
15
15
  end
16
-
16
+
17
17
  def add_features_to_active_record
18
- ActiveRecord::Base.module_eval do
18
+ ActiveRecord::Base.module_eval do
19
19
  include ::SelectableAttr::Base
20
20
  include ::SelectableAttrRails::Validatable::Base
21
21
  end
22
- SelectableAttr::Enum.module_eval do
22
+ SelectableAttr::Enum.module_eval do
23
23
  include ::SelectableAttrRails::DbLoadable
24
24
  include ::SelectableAttrRails::Validatable::Enum
25
25
  end
26
26
  logger.debug("#{self.name}.add_features_to_active_record")
27
27
  end
28
-
28
+
29
29
  def add_features_to_action_view
30
30
  ActionView::Base.module_eval do
31
31
  include ::SelectableAttrRails::Helpers::SelectHelper::Base
@@ -1,12 +1,15 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{selectable_attr_rails}
5
- s.version = "0.3.7"
8
+ s.version = "0.3.12"
6
9
 
7
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
11
  s.authors = ["Takeshi Akima"]
9
- s.date = %q{2009-08-17}
12
+ s.date = %q{2010-11-01}
10
13
  s.description = %q{selectable_attr_rails makes possible to use selectable_attr in rails application}
11
14
  s.email = %q{akima@gmail.com}
12
15
  s.extra_rdoc_files = [
@@ -28,6 +31,9 @@ Gem::Specification.new do |s|
28
31
  "lib/selectable_attr_rails/helpers/check_box_group_helper.rb",
29
32
  "lib/selectable_attr_rails/helpers/radio_button_group_helper.rb",
30
33
  "lib/selectable_attr_rails/helpers/select_helper.rb",
34
+ "lib/selectable_attr_rails/validatable.rb",
35
+ "lib/selectable_attr_rails/validatable/base.rb",
36
+ "lib/selectable_attr_rails/validatable/enum.rb",
31
37
  "lib/selectable_attr_rails/version.rb",
32
38
  "selectable_attr_rails.gemspec",
33
39
  "spec/database.yml",
@@ -41,7 +47,7 @@ Gem::Specification.new do |s|
41
47
  s.homepage = %q{http://github.com/akm/selectable_attr_rails/}
42
48
  s.rdoc_options = ["--charset=UTF-8"]
43
49
  s.require_paths = ["lib"]
44
- s.rubygems_version = %q{1.3.4}
50
+ s.rubygems_version = %q{1.3.7}
45
51
  s.summary = %q{selectable_attr_rails makes possible to use selectable_attr in rails application}
46
52
  s.test_files = [
47
53
  "spec/introduction_spec.rb",
@@ -54,21 +60,31 @@ Gem::Specification.new do |s|
54
60
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
55
61
  s.specification_version = 3
56
62
 
57
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
63
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
58
64
  s.add_runtime_dependency(%q<activesupport>, [">= 2.0.2"])
59
65
  s.add_runtime_dependency(%q<activerecord>, [">= 2.0.2"])
60
66
  s.add_runtime_dependency(%q<actionpack>, [">= 2.0.2"])
61
- s.add_runtime_dependency(%q<akm-selectable_attr>, [">= 0.3.5"])
67
+ s.add_runtime_dependency(%q<selectable_attr>, [">= 0.3.11"])
68
+ s.add_development_dependency(%q<rspec>, [">= 1.3.1"])
69
+ s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
70
+ s.add_development_dependency(%q<rcov>, [">= 0"])
62
71
  else
63
72
  s.add_dependency(%q<activesupport>, [">= 2.0.2"])
64
73
  s.add_dependency(%q<activerecord>, [">= 2.0.2"])
65
74
  s.add_dependency(%q<actionpack>, [">= 2.0.2"])
66
- s.add_dependency(%q<akm-selectable_attr>, [">= 0.3.5"])
75
+ s.add_dependency(%q<selectable_attr>, [">= 0.3.11"])
76
+ s.add_dependency(%q<rspec>, [">= 1.3.1"])
77
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
78
+ s.add_dependency(%q<rcov>, [">= 0"])
67
79
  end
68
80
  else
69
81
  s.add_dependency(%q<activesupport>, [">= 2.0.2"])
70
82
  s.add_dependency(%q<activerecord>, [">= 2.0.2"])
71
83
  s.add_dependency(%q<actionpack>, [">= 2.0.2"])
72
- s.add_dependency(%q<akm-selectable_attr>, [">= 0.3.5"])
84
+ s.add_dependency(%q<selectable_attr>, [">= 0.3.11"])
85
+ s.add_dependency(%q<rspec>, [">= 1.3.1"])
86
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
87
+ s.add_dependency(%q<rcov>, [">= 0"])
73
88
  end
74
89
  end
90
+
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- require File.join(File.dirname(__FILE__), 'spec_helper')
2
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
3
3
 
4
4
  describe SelectableAttr do
5
5
 
@@ -13,81 +13,81 @@ describe SelectableAttr do
13
13
  p3 = klass.new(:name => '未来派野郎', :product_type_cd => '03', :price => 3000)
14
14
  p3.discount_price.should == 1500
15
15
  end
16
-
16
+
17
17
  # 定数をガンガン定義した場合
18
18
  # 大文字が多くて読みにくいし、関連するデータ(ここではDISCOUNT)が増える毎に定数も増えていきます。
19
19
  class LegacyProduct1 < ActiveRecord::Base
20
20
  set_table_name 'products'
21
-
21
+
22
22
  PRODUCT_TYPE_BOOK = '01'
23
23
  PRODUCT_TYPE_DVD = '02'
24
24
  PRODUCT_TYPE_CD = '03'
25
25
  PRODUCT_TYPE_OTHER = '09'
26
-
26
+
27
27
  PRODUCT_TYPE_OPTIONS = [
28
28
  ['書籍', PRODUCT_TYPE_BOOK],
29
29
  ['DVD', PRODUCT_TYPE_DVD],
30
30
  ['CD', PRODUCT_TYPE_CD],
31
31
  ['その他', PRODUCT_TYPE_OTHER]
32
32
  ]
33
-
34
- DISCOUNT = {
33
+
34
+ DISCOUNT = {
35
35
  PRODUCT_TYPE_BOOK => 0.8,
36
36
  PRODUCT_TYPE_DVD => 0.2,
37
37
  PRODUCT_TYPE_CD => 0.5,
38
38
  PRODUCT_TYPE_OTHER => 1
39
39
  }
40
-
40
+
41
41
  def discount_price
42
42
  (DISCOUNT[product_type_cd] * price).to_i
43
43
  end
44
44
  end
45
-
45
+
46
46
  it "test_legacy_product" do
47
47
  assert_product_discount(LegacyProduct1)
48
-
48
+
49
49
  # 選択肢を表示するためのデータは以下のように取得できる
50
50
  LegacyProduct1::PRODUCT_TYPE_OPTIONS.should ==
51
51
  [['書籍', '01'], ['DVD', '02'], ['CD', '03'], ['その他', '09']]
52
52
  end
53
-
54
-
55
-
56
-
53
+
54
+
55
+
56
+
57
57
  # できるだけ定数定義をまとめた場合
58
58
  # 結構すっきりするけど、同じことをいろんなモデルで書くかと思うと気が重い。
59
59
  class LegacyProduct2 < ActiveRecord::Base
60
60
  set_table_name 'products'
61
-
61
+
62
62
  PRODUCT_TYPE_DEFS = [
63
63
  {:id => '01', :name => '書籍', :discount => 0.8},
64
64
  {:id => '02', :name => 'DVD', :discount => 0.2},
65
65
  {:id => '03', :name => 'CD', :discount => 0.5},
66
66
  {:id => '09', :name => 'その他', :discount => 1}
67
67
  ]
68
-
68
+
69
69
  PRODUCT_TYPE_OPTIONS = PRODUCT_TYPE_DEFS.map{|t| [t[:name], t[:id]]}
70
- DISCOUNT = PRODUCT_TYPE_DEFS.inject({}){|dest, t|
70
+ DISCOUNT = PRODUCT_TYPE_DEFS.inject({}){|dest, t|
71
71
  dest[t[:id]] = t[:discount]; dest}
72
-
72
+
73
73
  def discount_price
74
74
  (DISCOUNT[product_type_cd] * price).to_i
75
75
  end
76
76
  end
77
-
77
+
78
78
  it "test_legacy_product" do
79
79
  assert_product_discount(LegacyProduct2)
80
-
80
+
81
81
  # 選択肢を表示するためのデータは以下のように取得できる
82
- LegacyProduct2::PRODUCT_TYPE_OPTIONS.should ==
82
+ LegacyProduct2::PRODUCT_TYPE_OPTIONS.should ==
83
83
  [['書籍', '01'], ['DVD', '02'], ['CD', '03'], ['その他', '09']]
84
84
  end
85
-
85
+
86
86
  # selectable_attrを使った場合
87
87
  # 定義は一カ所にまとめられて、任意の属性(ここでは:discount)も一緒に書くことができてすっきり〜
88
88
  class Product1 < ActiveRecord::Base
89
89
  set_table_name 'products'
90
-
90
+
91
91
  selectable_attr :product_type_cd do
92
92
  entry '01', :book, '書籍', :discount => 0.8
93
93
  entry '02', :dvd, 'DVD', :discount => 0.2
@@ -100,15 +100,15 @@ describe SelectableAttr do
100
100
  (product_type_entry[:discount] * price).to_i
101
101
  end
102
102
  end
103
-
103
+
104
104
  it "test_product1" do
105
105
  assert_product_discount(Product1)
106
106
  # 選択肢を表示するためのデータは以下のように取得できる
107
107
  Product1.product_type_options.should ==
108
108
  [['書籍', '01'], ['DVD', '02'], ['CD', '03'], ['その他', '09']]
109
109
  end
110
-
111
-
110
+
111
+
112
112
  # selectable_attrが定義するインスタンスメソッドの詳細
113
113
  it "test_product_type_instance_methods" do
114
114
  p1 = Product1.new
@@ -117,19 +117,19 @@ describe SelectableAttr do
117
117
  p1.product_type_name.should be_nil
118
118
  # idを変更すると得られるキーも名称も変わります
119
119
  p1.product_type_cd = '02'
120
- p1.product_type_cd.should == '02'
121
- p1.product_type_key.should == :dvd
120
+ p1.product_type_cd.should == '02'
121
+ p1.product_type_key.should == :dvd
122
122
  p1.product_type_name.should == 'DVD'
123
123
  # キーを変更すると得られるidも名称も変わります
124
124
  p1.product_type_key = :book
125
125
  p1.product_type_cd.should == '01'
126
- p1.product_type_key.should == :book
126
+ p1.product_type_key.should == :book
127
127
  p1.product_type_name.should == '書籍'
128
128
  # id、キー、名称以外の任意の属性は、entryの[]メソッドで取得します。
129
129
  p1.product_type_key = :cd
130
130
  p1.product_type_entry[:discount].should == 0.5
131
131
  end
132
-
132
+
133
133
  # selectable_attrが定義するクラスメソッドの詳細
134
134
  it "test_product_type_class_methods" do
135
135
  # キーからid、名称を取得できます
@@ -138,8 +138,8 @@ describe SelectableAttr do
138
138
  Product1.product_type_id_by_key(:cd).should == '03'
139
139
  Product1.product_type_id_by_key(:other).should == '09'
140
140
  Product1.product_type_name_by_key(:book).should == '書籍'
141
- Product1.product_type_name_by_key(:dvd).should == 'DVD'
142
- Product1.product_type_name_by_key(:cd).should == 'CD'
141
+ Product1.product_type_name_by_key(:dvd).should == 'DVD'
142
+ Product1.product_type_name_by_key(:cd).should == 'CD'
143
143
  Product1.product_type_name_by_key(:other).should == 'その他'
144
144
  # 存在しないキーの場合はnilを返します
145
145
  Product1.product_type_id_by_key(nil).should be_nil
@@ -161,7 +161,7 @@ describe SelectableAttr do
161
161
  Product1.product_type_name_by_id(nil).should be_nil
162
162
  Product1.product_type_key_by_id('99').should be_nil
163
163
  Product1.product_type_name_by_id('99').should be_nil
164
-
164
+
165
165
  # id、キー、名称の配列を取得できます
166
166
  Product1.product_type_ids.should == ['01', '02', '03', '09']
167
167
  Product1.product_type_keys.should == [:book, :dvd, :cd, :other]
@@ -169,11 +169,11 @@ describe SelectableAttr do
169
169
  # 一部のものだけ取得することも可能です。
170
170
  Product1.product_type_ids(:cd, :dvd).should == ['03', '02' ]
171
171
  Product1.product_type_keys('02', '03').should == [:dvd, :cd ]
172
- Product1.product_type_names('02', '03').should == ['DVD', 'CD']
172
+ Product1.product_type_names('02', '03').should == ['DVD', 'CD']
173
173
  Product1.product_type_names(:cd, :dvd).should == ['CD', 'DVD']
174
-
174
+
175
175
  # select_tagなどのoption_tagsを作るための配列なんか一発っす
176
- Product1.product_type_options.should ==
176
+ Product1.product_type_options.should ==
177
177
  [['書籍', '01'], ['DVD', '02'], ['CD', '03'], ['その他', '09']]
178
178
  end
179
179
 
@@ -183,12 +183,12 @@ describe SelectableAttr do
183
183
  p1.valid?.should == true
184
184
  p1.errors.empty?.should == true
185
185
 
186
- p1.product_type_key = :book
186
+ p1.product_type_key = :book
187
187
  p1.product_type_cd.should == '01'
188
188
  p1.valid?.should == true
189
189
  p1.errors.empty?.should == true
190
190
 
191
- p1.product_type_cd = 'XX'
191
+ p1.product_type_cd = 'XX'
192
192
  p1.product_type_cd.should == 'XX'
193
193
  p1.valid?.should == false
194
194
  p1.errors.on(:product_type_cd).should == "は次のいずれかでなければなりません。 書籍, DVD, CD, その他"
@@ -197,15 +197,15 @@ describe SelectableAttr do
197
197
  # selectable_attrのエントリ名をDB上に保持するためのモデル
198
198
  class ItemMaster < ActiveRecord::Base
199
199
  end
200
-
200
+
201
201
  # selectable_attrを使った場合その2
202
202
  # アクセス時に毎回アクセス時にDBから項目名を取得します。
203
203
  class ProductWithDB1 < ActiveRecord::Base
204
204
  set_table_name 'products'
205
-
205
+
206
206
  selectable_attr :product_type_cd do
207
207
  update_by(
208
- "select item_cd, name from item_masters where category_name = 'product_type_cd' order by item_no",
208
+ "select item_cd, name from item_masters where category_name = 'product_type_cd' order by item_no",
209
209
  :when => :everytime)
210
210
  entry '01', :book, '書籍', :discount => 0.8
211
211
  entry '02', :dvd, 'DVD', :discount => 0.2
@@ -217,7 +217,7 @@ describe SelectableAttr do
217
217
  (product_type_entry[:discount] * price).to_i
218
218
  end
219
219
  end
220
-
220
+
221
221
  it "test_update_entry_name" do
222
222
  # DBに全くデータがなくてもコードで記述してあるエントリは存在します。
223
223
  ItemMaster.delete_all("category_name = 'product_type_cd'")
@@ -228,17 +228,17 @@ describe SelectableAttr do
228
228
  ProductWithDB1.product_type_name_by_key(:other).should == 'その他'
229
229
 
230
230
  assert_product_discount(ProductWithDB1)
231
-
231
+
232
232
  # DBからエントリの名称を動的に変更できます
233
233
  item_book = ItemMaster.create(:category_name => 'product_type_cd', :item_no => 1, :item_cd => '01', :name => '本')
234
234
  ProductWithDB1.product_type_entries.length.should == 4
235
- ProductWithDB1.product_type_name_by_key(:book).should == '本'
236
- ProductWithDB1.product_type_name_by_key(:dvd).should == 'DVD'
237
- ProductWithDB1.product_type_name_by_key(:cd).should == 'CD'
238
- ProductWithDB1.product_type_name_by_key(:other).should == 'その他'
239
- ProductWithDB1.product_type_options.should ==
235
+ ProductWithDB1.product_type_name_by_key(:book).should == '本'
236
+ ProductWithDB1.product_type_name_by_key(:dvd).should == 'DVD'
237
+ ProductWithDB1.product_type_name_by_key(:cd).should == 'CD'
238
+ ProductWithDB1.product_type_name_by_key(:other).should == 'その他'
239
+ ProductWithDB1.product_type_options.should ==
240
240
  [['本', '01'], ['DVD', '02'], ['CD', '03'], ['その他', '09']]
241
-
241
+
242
242
  # DBからエントリの並び順を動的に変更できます
243
243
  item_book.item_no = 4;
244
244
  item_book.save!
@@ -247,40 +247,40 @@ describe SelectableAttr do
247
247
  item_cd = ItemMaster.create(:category_name => 'product_type_cd', :item_no => 3, :item_cd => '03') # nameは指定しなかったらデフォルトが使われます。
248
248
  ProductWithDB1.product_type_options.should ==
249
249
  [['その他', '09'], ['DVD', '02'], ['CD', '03'], ['本', '01']]
250
-
250
+
251
251
  # DBからエントリを動的に追加することも可能です。
252
252
  item_toys = ItemMaster.create(:category_name => 'product_type_cd', :item_no => 5, :item_cd => '04', :name => 'おもちゃ')
253
- ProductWithDB1.product_type_options.should ==
253
+ ProductWithDB1.product_type_options.should ==
254
254
  [['その他', '09'], ['DVD', '02'], ['CD', '03'], ['本', '01'], ['おもちゃ', '04']]
255
255
  ProductWithDB1.product_type_key_by_id('04').should == :entry_04
256
-
256
+
257
257
  # DBからレコードを削除してもコードで定義したentryは削除されません。
258
258
  # 順番はDBからの取得順で並び替えられたものの後になります
259
259
  item_dvd.destroy
260
- ProductWithDB1.product_type_options.should ==
260
+ ProductWithDB1.product_type_options.should ==
261
261
  [['その他', '09'], ['CD', '03'], ['本', '01'], ['おもちゃ', '04'], ['DVD', '02']]
262
-
262
+
263
263
  # DB上で追加したレコードを削除すると、エントリも削除されます
264
264
  item_toys.destroy
265
- ProductWithDB1.product_type_options.should ==
265
+ ProductWithDB1.product_type_options.should ==
266
266
  [['その他', '09'], ['CD', '03'], ['本', '01'], ['DVD', '02']]
267
-
267
+
268
268
  # 名称を指定していたDBのレコードを削除したら元に戻ります。
269
269
  item_book.destroy
270
- ProductWithDB1.product_type_options.should ==
270
+ ProductWithDB1.product_type_options.should ==
271
271
  [['その他', '09'], ['CD', '03'], ['書籍', '01'], ['DVD', '02']]
272
-
272
+
273
273
  # エントリに該当するレコードを全部削除したら、元に戻ります。
274
274
  ItemMaster.delete_all("category_name = 'product_type_cd'")
275
- ProductWithDB1.product_type_options.should ==
275
+ ProductWithDB1.product_type_options.should ==
276
276
  [['書籍', '01'], ['DVD', '02'], ['CD', '03'], ['その他', '09']]
277
-
277
+
278
278
  assert_product_discount(ProductWithDB1)
279
279
  end
280
-
281
-
282
280
 
283
-
281
+
282
+
283
+
284
284
  # Q: product_type_cd の'_cd'はどこにいっちゃったの?
285
285
  # A: デフォルトでは、/(_cd$|_code$|_cds$|_codes$)/ を削除したものをbase_nameとして
286
286
  # 扱い、それに_keyなどを付加してメソッド名を定義します。もしこのルールを変更したい場合、
@@ -288,7 +288,7 @@ describe SelectableAttr do
288
288
  class Product2 < ActiveRecord::Base
289
289
  set_table_name 'products'
290
290
  self.selectable_attr_name_pattern = /^product_|_cd$/
291
-
291
+
292
292
  selectable_attr :product_type_cd do
293
293
  entry '01', :book, '書籍', :discount => 0.8
294
294
  entry '02', :dvd, 'DVD', :discount => 0.2
@@ -300,7 +300,7 @@ describe SelectableAttr do
300
300
  (type_entry[:discount] * price).to_i
301
301
  end
302
302
  end
303
-
303
+
304
304
  it "test_product2" do
305
305
  assert_product_discount(Product2)
306
306
  # 選択肢を表示するためのデータは以下のように取得できる
@@ -319,12 +319,12 @@ describe SelectableAttr do
319
319
  # キーを変更すると得られるidも名称も変わります
320
320
  p2.type_key = :book
321
321
  p2.product_type_cd.should == '01'
322
- p2.type_key.should == :book
322
+ p2.type_key.should == :book
323
323
  p2.type_name.should == '書籍'
324
324
  # id、キー、名称以外の任意の属性は、entryの[]メソッドで取得します。
325
325
  p2.type_key = :cd
326
326
  p2.type_entry[:discount].should == 0.5
327
-
327
+
328
328
  Product2.type_id_by_key(:book).should == '01'
329
329
  Product2.type_id_by_key(:dvd).should == '02'
330
330
  Product2.type_name_by_key(:cd).should == 'CD'
@@ -336,15 +336,15 @@ describe SelectableAttr do
336
336
  Product2.type_keys('02', '03').should == [:dvd, :cd]
337
337
  Product2.type_names(:cd, :dvd).should == ['CD', 'DVD']
338
338
  end
339
-
340
-
341
-
342
-
339
+
340
+
341
+
342
+
343
343
  # Q: selectable_attrの呼び出し毎にbase_bname(って言うの?)を指定したいんだけど。
344
344
  # A: base_nameオプションを指定してください。
345
345
  class Product3 < ActiveRecord::Base
346
346
  set_table_name 'products'
347
-
347
+
348
348
  selectable_attr :product_type_cd, :base_name => 'type' do
349
349
  entry '01', :book, '書籍', :discount => 0.8
350
350
  entry '02', :dvd, 'DVD', :discount => 0.2
@@ -356,13 +356,13 @@ describe SelectableAttr do
356
356
  (type_entry[:discount] * price).to_i
357
357
  end
358
358
  end
359
-
360
- it "test_product3" do
359
+
360
+ it "test_product3" do
361
361
  assert_product_discount(Product3)
362
362
  # 選択肢を表示するためのデータは以下のように取得できる
363
363
  Product3.type_options.should ==
364
364
  [['書籍', '01'], ['DVD', '02'], ['CD', '03'], ['その他', '09']]
365
-
365
+
366
366
  p3 = Product3.new
367
367
  p3.product_type_cd.should be_nil
368
368
  p3.type_key.should be_nil
@@ -380,18 +380,18 @@ describe SelectableAttr do
380
380
  # id、キー、名称以外の任意の属性は、entryの[]メソッドで取得します。
381
381
  p3.type_key = :cd
382
382
  p3.type_entry[:discount].should == 0.5
383
-
383
+
384
384
  Product3.type_id_by_key(:book).should == '01'
385
- Product3.type_id_by_key(:dvd).should == '02'
386
- Product3.type_name_by_key(:cd).should == 'CD'
385
+ Product3.type_id_by_key(:dvd).should == '02'
386
+ Product3.type_name_by_key(:cd).should == 'CD'
387
387
  Product3.type_name_by_key(:other).should == 'その他'
388
- Product3.type_key_by_id('09').should == :other
389
- Product3.type_name_by_id('01').should == '書籍'
388
+ Product3.type_key_by_id('09').should == :other
389
+ Product3.type_name_by_id('01').should == '書籍'
390
390
  Product3.type_keys.should == [:book, :dvd, :cd, :other]
391
391
  Product3.type_names.should == ['書籍', 'DVD', 'CD', 'その他']
392
392
  Product3.type_keys('02', '03').should == [:dvd, :cd]
393
393
  Product3.type_names(:cd, :dvd).should == ['CD', 'DVD']
394
394
  end
395
-
395
+
396
396
  end
397
397
 
data/spec/schema.rb CHANGED
@@ -7,7 +7,7 @@ ActiveRecord::Schema.define(:version => 1) do
7
7
  t.datetime "created_at"
8
8
  t.datetime "updated_at"
9
9
  end
10
-
10
+
11
11
  create_table "item_masters", :force => true do |t|
12
12
  t.string "category_name", :limit => 20
13
13
  t.integer "item_no"
@@ -16,7 +16,7 @@ ActiveRecord::Schema.define(:version => 1) do
16
16
  t.datetime "created_at"
17
17
  t.datetime "updated_at"
18
18
  end
19
-
19
+
20
20
  create_table "i18n_item_masters", :force => true do |t|
21
21
  t.string "locale", :limit => 5
22
22
  t.string "category_name", :limit => 20
@@ -26,5 +26,5 @@ ActiveRecord::Schema.define(:version => 1) do
26
26
  t.datetime "created_at"
27
27
  t.datetime "updated_at"
28
28
  end
29
-
29
+
30
30
  end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  if defined?(I18n)
3
- require File.join(File.dirname(__FILE__), 'spec_helper')
3
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
4
4
 
5
5
  describe SelectableAttr::Enum do
6
6
 
@@ -27,9 +27,9 @@ if defined?(I18n)
27
27
 
28
28
  it 'test_enum1_i18n' do
29
29
  I18n.locale = nil
30
- I18n.locale.should == :en
30
+ I18n.locale.should == :en
31
31
  Enum1.name_by_key(:entry1).should == "entry one"
32
- Enum1.name_by_key(:entry2).should == "entry two"
32
+ Enum1.name_by_key(:entry2).should == "entry two"
33
33
  Enum1.name_by_key(:entry3).should == "entry three"
34
34
  Enum1.names.should == ["entry one", "entry two", "entry three"]
35
35
 
@@ -62,12 +62,16 @@ if defined?(I18n)
62
62
  it 'test_attr1_i18n' do
63
63
  I18n.default_locale = 'ja'
64
64
  I18n.locale = nil
65
- I18n.locale.should == 'ja'
66
- SelectableAttrMock1.attr1_name_by_key(:entry1).should == "エントリ壱"
67
- SelectableAttrMock1.attr1_name_by_key(:entry2).should == "エントリ弐"
68
- SelectableAttrMock1.attr1_name_by_key(:entry3).should == "エントリ参"
65
+ if ActiveRecord::VERSION::STRING <= "2.2.3"
66
+ I18n.locale.should == 'ja'
67
+ else
68
+ I18n.locale.should == :ja
69
+ end
70
+ SelectableAttrMock1.attr1_name_by_key(:entry1).should == "エントリ壱"
71
+ SelectableAttrMock1.attr1_name_by_key(:entry2).should == "エントリ弐"
72
+ SelectableAttrMock1.attr1_name_by_key(:entry3).should == "エントリ参"
69
73
  SelectableAttrMock1.attr1_options.should == [["エントリ壱",1], ["エントリ弐",2], ["エントリ参",3]]
70
-
74
+
71
75
  I18n.locale = 'ja'
72
76
  SelectableAttrMock1.attr1_name_by_key(:entry1).should == "エントリ壱"
73
77
  SelectableAttrMock1.attr1_name_by_key(:entry2).should == "エントリ弐"
@@ -75,8 +79,8 @@ if defined?(I18n)
75
79
  SelectableAttrMock1.attr1_options.should == [["エントリ壱",1], ["エントリ弐",2], ["エントリ参",3]]
76
80
 
77
81
  I18n.locale = 'en'
78
- SelectableAttrMock1.attr1_name_by_key(:entry1).should == "entry one"
79
- SelectableAttrMock1.attr1_name_by_key(:entry2).should == "entry two"
82
+ SelectableAttrMock1.attr1_name_by_key(:entry1).should == "entry one"
83
+ SelectableAttrMock1.attr1_name_by_key(:entry2).should == "entry two"
80
84
  SelectableAttrMock1.attr1_name_by_key(:entry3).should == "entry three"
81
85
  SelectableAttrMock1.attr1_options.should == [["entry one",1], ["entry two",2], ["entry three",3]]
82
86
  end
@@ -93,7 +97,11 @@ if defined?(I18n)
93
97
  it 'test_enum1_i18n' do
94
98
  I18n.default_locale = 'ja'
95
99
  I18n.locale = nil
96
- I18n.locale.should == 'ja'
100
+ if ActiveRecord::VERSION::STRING <= "2.2.3"
101
+ I18n.locale.should == 'ja'
102
+ else
103
+ I18n.locale.should == :ja
104
+ end
97
105
  SelectableAttrMock2.enum1_name_by_key(:entry1).should == "エントリ壱"
98
106
  SelectableAttrMock2.enum1_name_by_key(:entry2).should == "エントリ弐"
99
107
  SelectableAttrMock2.enum1_name_by_key(:entry3).should == "エントリ参"
@@ -106,8 +114,8 @@ if defined?(I18n)
106
114
  SelectableAttrMock2.enum1_options.should == [["エントリ壱",1], ["エントリ弐",2], ["エントリ参",3]]
107
115
 
108
116
  I18n.locale = 'en'
109
- SelectableAttrMock2.enum1_name_by_key(:entry1).should == "entry one"
110
- SelectableAttrMock2.enum1_name_by_key(:entry2).should == "entry two"
117
+ SelectableAttrMock2.enum1_name_by_key(:entry1).should == "entry one"
118
+ SelectableAttrMock2.enum1_name_by_key(:entry2).should == "entry two"
111
119
  SelectableAttrMock2.enum1_name_by_key(:entry3).should == "entry three"
112
120
  SelectableAttrMock2.enum1_options.should == [["entry one",1], ["entry two",2], ["entry three",3]]
113
121
  end
@@ -125,7 +133,7 @@ if defined?(I18n)
125
133
  # update_byメソッドには、エントリのidと名称を返すSELECT文を指定する代わりに、
126
134
  # エントリのidと名称の配列の配列を返すブロックを指定することも可能です。
127
135
  update_by(:when => :everytime) do
128
- records = I18nItemMaster.find(:all,
136
+ records = I18nItemMaster.find(:all,
129
137
  :conditions => [
130
138
  "category_name = 'product_type_cd' and locale = ? ", I18n.locale.to_s],
131
139
  :order => "item_no")
@@ -148,7 +156,7 @@ if defined?(I18n)
148
156
  ProductWithI18nDB1.product_type_name_by_key(:dvd).should == 'DVD'
149
157
  ProductWithI18nDB1.product_type_name_by_key(:cd).should == 'CD'
150
158
  ProductWithI18nDB1.product_type_name_by_key(:other).should == 'その他'
151
-
159
+
152
160
  ProductWithI18nDB1.product_type_hash_array.should == [
153
161
  {:id => '01', :key => :book, :name => '書籍', :discount => 0.8},
154
162
  {:id => '02', :key => :dvd, :name => 'DVD', :discount => 0.2},
@@ -158,7 +166,7 @@ if defined?(I18n)
158
166
 
159
167
  # DBからエントリの名称を動的に変更できます
160
168
  item_book = I18nItemMaster.create(:locale => 'ja', :category_name => 'product_type_cd', :item_no => 1, :item_cd => '01', :name => '本')
161
- ProductWithI18nDB1.product_type_entries.length.should == 4
169
+ ProductWithI18nDB1.product_type_entries.length.should == 4
162
170
  ProductWithI18nDB1.product_type_name_by_key(:book).should == '本'
163
171
  ProductWithI18nDB1.product_type_name_by_key(:dvd).should == 'DVD'
164
172
  ProductWithI18nDB1.product_type_name_by_key(:cd).should == 'CD'
@@ -200,7 +208,7 @@ if defined?(I18n)
200
208
  item_dvd = I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 2, :item_cd => '02', :name => 'DVD')
201
209
  item_cd = I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 3, :item_cd => '03', :name => 'CD')
202
210
  item_toys = I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 5, :item_cd => '04', :name => 'Toy')
203
-
211
+
204
212
  # 英語名が登録されていてもI18n.localeが変わらなければ、日本語のまま
205
213
  ProductWithI18nDB1.product_type_options.should == [['その他', '09'], ['DVD', '02'], ['CD', '03'], ['本', '01'], ['おもちゃ', '04']]
206
214
  ProductWithI18nDB1.product_type_key_by_id('04').should == :entry_04
@@ -212,7 +220,7 @@ if defined?(I18n)
212
220
  {:id => '01', :key => :book, :name => '本', :discount => 0.8},
213
221
  {:id => '04', :key => :entry_04, :name => 'おもちゃ'}
214
222
  ]
215
-
223
+
216
224
  # I18n.localeを変更すると取得できるエントリの名称も変わります
217
225
  I18n.locale = 'en'
218
226
  ProductWithI18nDB1.product_type_options.should == [['Others', '09'], ['DVD', '02'], ['CD', '03'], ['Book', '01'], ['Toy', '04']]
@@ -229,7 +237,7 @@ if defined?(I18n)
229
237
  I18n.locale = 'ja'
230
238
  ProductWithI18nDB1.product_type_options.should == [['その他', '09'], ['DVD', '02'], ['CD', '03'], ['本', '01'], ['おもちゃ', '04']]
231
239
  ProductWithI18nDB1.product_type_key_by_id('04').should == :entry_04
232
-
240
+
233
241
  I18n.locale = 'en'
234
242
  ProductWithI18nDB1.product_type_options.should == [['Others', '09'], ['DVD', '02'], ['CD', '03'], ['Book', '01'], ['Toy', '04']]
235
243
  ProductWithI18nDB1.product_type_key_by_id('04').should == :entry_04
@@ -276,7 +284,7 @@ if defined?(I18n)
276
284
  I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 3, :item_cd => '03', :name => 'CD')
277
285
  I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 4, :item_cd => '01', :name => 'Book')
278
286
  I18nItemMaster.create(:locale => 'en', :category_name => 'product_type_cd', :item_no => 5, :item_cd => '04', :name => 'Toy')
279
-
287
+
280
288
  I18n.locale = 'en'
281
289
  actual = SelectableAttr::Enum.i18n_export
282
290
  actual.keys.should == ['selectable_attrs']
data/spec/spec_helper.rb CHANGED
@@ -28,3 +28,17 @@ def assert_hash(expected, actual)
28
28
  assert_equal expected[key], actual[key], "unmatch value for #{key.inspect}"
29
29
  end
30
30
  end
31
+
32
+ # http://d.hatena.ne.jp/nedate/20101004/1286183882
33
+ if defined?(Rcov)
34
+ class Rcov::CodeCoverageAnalyzer
35
+ def update_script_lines__
36
+ if '1.9'.respond_to?(:force_encoding)
37
+ SCRIPT_LINES__.each do |k,v|
38
+ v.each { |src| src.force_encoding('utf-8') }
39
+ end
40
+ end
41
+ @script_lines__ = @script_lines__.merge(SCRIPT_LINES__)
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selectable_attr_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.11
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 12
9
+ version: 0.3.12
5
10
  platform: ruby
6
11
  authors:
7
12
  - Takeshi Akima
@@ -9,49 +14,110 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-14 00:00:00 +09:00
17
+ date: 2010-11-01 00:00:00 +09:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: activesupport
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 2
23
32
  version: 2.0.2
24
- version:
33
+ type: :runtime
34
+ version_requirements: *id001
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: activerecord
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
30
40
  requirements:
31
41
  - - ">="
32
42
  - !ruby/object:Gem::Version
43
+ segments:
44
+ - 2
45
+ - 0
46
+ - 2
33
47
  version: 2.0.2
34
- version:
48
+ type: :runtime
49
+ version_requirements: *id002
35
50
  - !ruby/object:Gem::Dependency
36
51
  name: actionpack
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
40
55
  requirements:
41
56
  - - ">="
42
57
  - !ruby/object:Gem::Version
58
+ segments:
59
+ - 2
60
+ - 0
61
+ - 2
43
62
  version: 2.0.2
44
- version:
63
+ type: :runtime
64
+ version_requirements: *id003
45
65
  - !ruby/object:Gem::Dependency
46
66
  name: selectable_attr
47
- type: :runtime
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
50
70
  requirements:
51
71
  - - ">="
52
72
  - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ - 3
76
+ - 11
53
77
  version: 0.3.11
54
- version:
78
+ type: :runtime
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: rspec
82
+ prerelease: false
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 1
90
+ - 3
91
+ - 1
92
+ version: 1.3.1
93
+ type: :development
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: sqlite3-ruby
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ type: :development
107
+ version_requirements: *id006
108
+ - !ruby/object:Gem::Dependency
109
+ name: rcov
110
+ prerelease: false
111
+ requirement: &id007 !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ type: :development
120
+ version_requirements: *id007
55
121
  description: selectable_attr_rails makes possible to use selectable_attr in rails application
56
122
  email: akima@gmail.com
57
123
  executables: []
@@ -98,21 +164,25 @@ rdoc_options:
98
164
  require_paths:
99
165
  - lib
100
166
  required_ruby_version: !ruby/object:Gem::Requirement
167
+ none: false
101
168
  requirements:
102
169
  - - ">="
103
170
  - !ruby/object:Gem::Version
171
+ segments:
172
+ - 0
104
173
  version: "0"
105
- version:
106
174
  required_rubygems_version: !ruby/object:Gem::Requirement
175
+ none: false
107
176
  requirements:
108
177
  - - ">="
109
178
  - !ruby/object:Gem::Version
179
+ segments:
180
+ - 0
110
181
  version: "0"
111
- version:
112
182
  requirements: []
113
183
 
114
184
  rubyforge_project:
115
- rubygems_version: 1.3.5
185
+ rubygems_version: 1.3.7
116
186
  signing_key:
117
187
  specification_version: 3
118
188
  summary: selectable_attr_rails makes possible to use selectable_attr in rails application