customize 0.0.2 → 0.0.3

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/customize.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "customize"
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ryan Wong"]
@@ -11,6 +11,7 @@ module Customize
11
11
 
12
12
  def character
13
13
  @character ||= proc {
14
+ ascent_ids = self.class.include?(Customize::Inherited) ? self.ascent_ids : []
14
15
  all_character = Character.where(:related_id=>(ascent_ids | [self.id]), :related_type=>self.class.name)
15
16
  all_character.inject(HashWithIndifferentAccess.new) { |map, item|
16
17
  map[item.key] = item.value
@@ -15,6 +15,9 @@ module Customize
15
15
  end
16
16
 
17
17
  module ClassMethods
18
+ def root
19
+ joins(:inherit_node).where("parent_id is null")
20
+ end
18
21
  end
19
22
 
20
23
  def inherit parent
@@ -14,53 +14,67 @@ describe Customize::Characterize do
14
14
  end
15
15
  end
16
16
 
17
- subject { Product.create! }
18
-
19
- it "has characters" do
20
- subject.characters.should_not be_nil
17
+ with_model :person do
18
+ table do |t|
19
+ end
20
+ model do
21
+ include Customize::Characterize
22
+ end
21
23
  end
22
24
 
23
- context "support type" do
25
+ context :model_without_inherit do
26
+ subject { Person.create }
24
27
 
25
- before :each do
26
- @value = example.metadata[:description_args].first
27
- @type = example.metadata[:type]
28
- subject.characters.create :key=>@type, :type=>@type, :value=>@value
28
+ it :has_character do
29
+ subject.characters.create :key=>:foo, :type=>:boolean, :value=>true
29
30
  subject.reload
31
+ subject.character[:foo].should be_true
30
32
  end
31
33
 
32
- after :each do
33
- subject.character[@type].should == @value
34
- end
34
+ end
35
35
 
36
- it 10, :type=>:integer do
36
+ context :model_with_inherit do
37
+ subject { Product.create! }
38
+
39
+ it "has characters" do
40
+ subject.characters.should_not be_nil
37
41
  end
38
-
39
- it 12.34, :type=>:decimal do
42
+
43
+ context "support type" do
44
+ before :each do
45
+ @value = example.metadata[:description_args].first
46
+ @type = example.metadata[:type]
47
+ subject.characters.create :key=>@type, :type=>@type, :value=>@value
48
+ subject.reload
49
+ end
50
+
51
+ after :each do
52
+ subject.character[@type].should == @value
53
+ end
54
+
55
+ it 10, :type=>:integer do
56
+ end
57
+ it 12.34, :type=>:decimal do
58
+ end
59
+ it 'string', :type=>:string do
60
+ end
61
+ it [1, 2, 3] do
62
+ end
63
+ it Hash.new(:foo=>:bar) do
64
+ end
40
65
  end
41
-
42
- it 'string', :type=>:string do
66
+
67
+ it "has readonly hash character" do
68
+ subject.characters.create! :key=>:foo, :value=>'bar'
69
+ subject.character[:foo].should == 'bar'
43
70
  end
44
-
45
- it [1, 2, 3] do
46
- end
47
-
48
- it Hash.new(:foo=>:bar) do
71
+
72
+ it "has inherited character" do
73
+ parent = Product.create!
74
+ parent.characters.create! :key=>:p, :value=>1
75
+ subject.inherit parent
76
+ subject.character[:p].should == 1
49
77
  end
50
-
51
78
  end
52
79
 
53
- it "has readonly hash character" do
54
- subject.characters.create! :key=>:foo, :value=>'bar'
55
- subject.character[:foo].should == 'bar'
56
- end
57
-
58
- it "has inherited character" do
59
- parent = Product.create!
60
- parent.characters.create! :key=>:p, :value=>1
61
- subject.inherit parent
62
- subject.character[:p].should == 1
63
- end
64
-
65
-
66
80
  end
@@ -43,6 +43,10 @@ describe Customize::Inherited do
43
43
  @child.ascent_ids.should have(1).items
44
44
  end
45
45
 
46
+ it "root has 1 item" do
47
+ Product.root.should have(1).items
48
+ end
49
+
46
50
  it "child should have ascents" do
47
51
  @child.ascents.should have(1).items
48
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: customize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -265,7 +265,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
265
265
  version: '0'
266
266
  segments:
267
267
  - 0
268
- hash: 921921299
268
+ hash: 348052147
269
269
  required_rubygems_version: !ruby/object:Gem::Requirement
270
270
  none: false
271
271
  requirements: