district_cn 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,8 @@ module DistrictCn
3
3
  module ActiveRecord
4
4
 
5
5
  def act_as_area_field(*attributes)
6
+ define_attribute_methods unless attribute_methods_generated?
7
+
6
8
  attributes.each do |attribute|
7
9
  class_eval <<-EVAL
8
10
  alias_method :_#{attribute}, :#{attribute}
@@ -1,3 +1,3 @@
1
1
  module DistrictCn
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -9,16 +9,17 @@ end
9
9
  ActiveRecord::Base.connection.instance_eval do
10
10
  create_table :companies do |t|
11
11
  t.string :name
12
+ t.string :loc_code
13
+ t.string :another_code
12
14
  t.timestamps
13
15
  end
14
16
  end
15
17
 
16
18
  class Company < ActiveRecord::Base
17
19
  attr_accessor :region_code
18
- attr_accessor :loc_code
19
20
  attr_accessible :region_code
20
21
 
21
- act_as_area_field :region_code
22
+ act_as_area_field :region_code,:loc_code
22
23
  validates :region_code, presence: true
23
24
  end
24
25
 
@@ -38,6 +39,12 @@ describe DistrictCn::ActAsAreaField do
38
39
  expect(subject.region_code).to be_instance_of(DistrictCn::Code)
39
40
  end
40
41
 
42
+ it "should return DistrictCn::Code instance" do
43
+ subject.loc_code = 331002
44
+ expect(subject.loc_code).to be_instance_of(DistrictCn::Code)
45
+ end
46
+
47
+
41
48
  it "should cached" do
42
49
  subject.region_code = 331002
43
50
  expect(subject.region_code.object_id).to eq(subject.region_code.object_id)
@@ -52,9 +59,9 @@ describe DistrictCn::ActAsAreaField do
52
59
  end
53
60
 
54
61
  it "should return real value without acts_as_area_field" do
55
- subject.loc_code = 331002
56
- expect(subject.loc_code).to eq(331002)
57
- expect(subject.loc_code).not_to be_instance_of(DistrictCn::Code)
62
+ subject.another_code = 331002
63
+ expect(subject.another_code).to eq(331002)
64
+ expect(subject.another_code).not_to be_instance_of(DistrictCn::Code)
58
65
  end
59
66
 
60
67
  it "should be unvalid when region_code is blank" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: district_cn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: