acts_as_relatable 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,7 +10,7 @@ Gem installation :
10
10
 
11
11
  Or you can put it in your Gemfile :
12
12
 
13
- gem "acts_as_relatable", "~> 0.0.3"
13
+ gem "acts_as_relatable", "~> 0.0.4"
14
14
 
15
15
  and then run :
16
16
 
@@ -48,7 +48,7 @@ Followed by :
48
48
  @mixer = Tool.create(:name => "Mixer")
49
49
 
50
50
 
51
- #Creating relationships
51
+ === Creating relationships
52
52
 
53
53
  @butter.relates_to!(@pancake) # #<ActsAsRelatable::Relationship id: 2, relator_id: 2, relator_type: "Product", related_id: 1, related_type: "Recipe">
54
54
  @pancake.relates_to!(@mixer) # #<ActsAsRelatable::Relationship id: 3, relator_id: 1, relator_type: "Recipe", related_id: 1, related_type: "Tool">
@@ -62,7 +62,7 @@ Followed by :
62
62
  @butter.relates_to!(@pancake, false)
63
63
 
64
64
 
65
- #Fetching relationships
65
+ === Fetching relationships
66
66
 
67
67
  @butter.related_recipes # [#<Recipe id: 1, name: "Pancakes">]
68
68
  @butter.related_products # [#<Product id: 1, name: "Bread"]
@@ -81,6 +81,10 @@ Followed by :
81
81
 
82
82
  @butter.destroy_relation_with @pancake
83
83
 
84
+ === Getting Relatable types
85
+
86
+ @pancake.relatable_types # [:product, :tool]
87
+
84
88
  == Configuration
85
89
 
86
90
  To create the acts_as_relatable config file, open a shell and run :
@@ -12,7 +12,7 @@ module ActsAsRelatable
12
12
  # Create polymorphic associations
13
13
  class_attribute :relatable_types
14
14
 
15
- self.relatable_types = relatable_models.to_a.flatten.compact.map(&:to_sym) << self.to_s.underscore
15
+ self.relatable_types = relatable_models.to_a.flatten.compact.map(&:to_sym) << self.to_s.underscore.to_sym
16
16
 
17
17
  has_many :relationships, :as => :relator, :order => "created_at desc", :class_name => "ActsAsRelatable::Relationship", :dependent => :destroy
18
18
  has_many :incoming_relationships, :as => :related, :class_name => "ActsAsRelatable::Relationship", :dependent => :destroy
@@ -34,6 +34,22 @@ describe ActsAsRelatable::Relatable do
34
34
  }
35
35
  }
36
36
 
37
+ context :relatable_types do
38
+
39
+ it "for product" do
40
+ @products[:product1].relatable_types.should == [:shop, :tag, :product]
41
+ end
42
+
43
+ it "for shop" do
44
+ @shops[:shop1].relatable_types.should == [:tag, :product, :shop]
45
+ end
46
+
47
+ it "for tag" do
48
+ @tag.relatable_types.should == [:product, :shop, :tag]
49
+ end
50
+
51
+ end
52
+
37
53
  context :relates_to! do
38
54
 
39
55
  context :both_sided do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: acts_as_relatable
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Fr\xC3\xA9d\xC3\xA9ric Malamitsas"