has_content 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ = 0.0.4
2
+ * introduce ContentOwner#<content_name>_record which autocreates a record (or builds if owner not saved)
3
+
1
4
  = 0.0.3
2
5
  * Set attr_accessible to :content only on the record, set name and owner via relationships
3
6
 
@@ -1,4 +1,4 @@
1
- Copyright 2012 Ian White
1
+ Copyright 2012-2013 Ian White
2
2
 
3
3
  This plugin was developed by Ian White (http://github.com/ianwhite)
4
4
  while working at Distinctive Doors (http://distinctivedoors.co.uk/oss)
@@ -43,23 +43,22 @@ module HasContent
43
43
 
44
44
  # content getter (delegates to the content association)
45
45
  define_method name do
46
- send("get_#{name}_content").content
46
+ send("#{name}_record").content
47
47
  end
48
48
 
49
49
  # content setter (delegates to the content association, updating timestamps on owner record if required)
50
50
  define_method "#{name}=" do |value|
51
- (send("get_#{name}_content").content = value).tap do |*|
52
- if respond_to?(:updated_at?) && send("get_#{name}_content").changed?
51
+ (send("#{name}_record").content = value).tap do |*|
52
+ if respond_to?(:updated_at?) && send("#{name}_record").changed?
53
53
  updated_at_will_change!
54
54
  end
55
55
  end
56
56
  end
57
57
 
58
58
  # find or build (and save if possible) the content association
59
- define_method "get_#{name}_content" do
59
+ define_method "#{name}_record" do
60
60
  send("#{name}_content") or send("build_#{name}_content").tap {|r| r.name = name; r.save unless new_record? }
61
61
  end
62
- private "get_#{name}_content".to_sym
63
62
  end
64
63
  end
65
64
  end
@@ -1,3 +1,3 @@
1
1
  module HasContent
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -41,6 +41,13 @@ shared_examples_for "new owner with has_content" do
41
41
  lambda { owner.send(content_name) }.should_not change(HasContent::Record, :count)
42
42
  lambda { owner.save! }.should change(HasContent::Record, :count).by(1)
43
43
  end
44
+
45
+ describe "#<content_name>_association" do
46
+ subject { owner.send "#{content_name}_record" }
47
+
48
+ it { should be_a HasContent::Record }
49
+ it { should_not be_persisted }
50
+ end
44
51
  end
45
52
 
46
53
  context '[after being saved]' do
@@ -50,5 +57,11 @@ shared_examples_for "new owner with has_content" do
50
57
  lambda { owner.send(content_name) }.should change(HasContent::Record, :count).by(1)
51
58
  lambda { owner.save! }.should_not change(HasContent::Record, :count)
52
59
  end
60
+
61
+ describe "#<content_name>_association" do
62
+ subject { owner.send "#{content_name}_record" }
63
+
64
+ it { should be_persisted }
65
+ end
53
66
  end
54
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_content
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-20 00:00:00.000000000 Z
12
+ date: 2013-01-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70179807906620 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '3.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70179807906620
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rake
27
- requirement: &70179807716000 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70179807716000
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec
38
- requirement: &70179807713540 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '2'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70179807713540
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '2'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: sqlite3
49
- requirement: &70179807710640 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70179807710640
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: database_cleaner
60
- requirement: &70179807709560 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,9 +85,14 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70179807709560
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  description: Simple wrapper for adding content via a polymorphic join for any active
70
- record. Version 0.0.3.
95
+ record. Version 0.0.4.
71
96
  email:
72
97
  - ian.w.white@gmail.com
73
98
  executables: []
@@ -105,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
130
  version: '0'
106
131
  segments:
107
132
  - 0
108
- hash: 778003700105874322
133
+ hash: -1944507275510526427
109
134
  required_rubygems_version: !ruby/object:Gem::Requirement
110
135
  none: false
111
136
  requirements:
@@ -114,10 +139,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
139
  version: '0'
115
140
  segments:
116
141
  - 0
117
- hash: 778003700105874322
142
+ hash: -1944507275510526427
118
143
  requirements: []
119
144
  rubyforge_project:
120
- rubygems_version: 1.8.15
145
+ rubygems_version: 1.8.24
121
146
  signing_key:
122
147
  specification_version: 3
123
148
  summary: Simple wrapper for adding content via a polymorphic join for any active record