Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

0.0.4 introduce ContentOwner#<content_name>_record which autocreates …

…a record (or builds if owner not saved)
  • Loading branch information...
commit 4f6b9f0be311a8556d7c38247326ef001bc3972a 1 parent 2764f94
@ianwhite ianwhite authored
View
3  CHANGELOG
@@ -1,3 +1,6 @@
+= 0.0.4
+ * introduce ContentOwner#<content_name>_record which autocreates a record (or builds if owner not saved)
+
= 0.0.3
* Set attr_accessible to :content only on the record, set name and owner via relationships
View
81 Gemfile.lock.development
@@ -1,67 +1,62 @@
PATH
remote: .
specs:
- has_content (0.0.3)
+ has_content (0.0.4)
activerecord (>= 3.2)
GEM
remote: http://rubygems.org/
specs:
- activemodel (3.2.6)
- activesupport (= 3.2.6)
+ activemodel (3.2.11)
+ activesupport (= 3.2.11)
builder (~> 3.0.0)
- activerecord (3.2.6)
- activemodel (= 3.2.6)
- activesupport (= 3.2.6)
+ activerecord (3.2.11)
+ activemodel (= 3.2.11)
+ activesupport (= 3.2.11)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
- activesupport (3.2.6)
+ activesupport (3.2.11)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
- builder (3.0.0)
- coderay (1.0.6)
- database_cleaner (0.8.0)
+ builder (3.0.4)
+ coderay (1.0.8)
+ database_cleaner (0.9.1)
diff-lcs (1.1.3)
- ffi (1.0.11)
- guard (1.1.1)
- listen (>= 0.4.2)
+ guard (1.6.1)
+ listen (>= 0.6.0)
+ lumberjack (>= 1.0.2)
+ pry (>= 0.9.10)
thor (>= 0.14.6)
- guard-rspec (1.1.0)
+ guard-rspec (2.3.3)
guard (>= 1.1)
- i18n (0.6.0)
- listen (0.4.6)
- rb-fchange (~> 0.0.5)
- rb-fsevent (~> 0.9.1)
- rb-inotify (~> 0.8.8)
- method_source (0.7.1)
- multi_json (1.3.6)
- pry (0.9.9.6)
+ rspec (~> 2.11)
+ i18n (0.6.1)
+ listen (0.7.1)
+ lumberjack (1.0.2)
+ method_source (0.8.1)
+ multi_json (1.5.0)
+ pry (0.9.10)
coderay (~> 1.0.5)
- method_source (~> 0.7.1)
- slop (>= 2.4.4, < 3)
- rake (0.9.2.2)
- rb-fchange (0.0.5)
- ffi
- rb-fsevent (0.9.1)
- rb-inotify (0.8.8)
- ffi (>= 0.5.0)
- rspec (2.10.0)
- rspec-core (~> 2.10.0)
- rspec-expectations (~> 2.10.0)
- rspec-mocks (~> 2.10.0)
- rspec-core (2.10.1)
- rspec-expectations (2.10.0)
+ method_source (~> 0.8)
+ slop (~> 3.3.1)
+ rake (10.0.3)
+ rspec (2.12.0)
+ rspec-core (~> 2.12.0)
+ rspec-expectations (~> 2.12.0)
+ rspec-mocks (~> 2.12.0)
+ rspec-core (2.12.2)
+ rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
- rspec-mocks (2.10.1)
- simplecov (0.6.4)
+ rspec-mocks (2.12.1)
+ simplecov (0.7.1)
multi_json (~> 1.0)
- simplecov-html (~> 0.5.3)
- simplecov-html (0.5.3)
- slop (2.4.4)
+ simplecov-html (~> 0.7.1)
+ simplecov-html (0.7.1)
+ slop (3.3.3)
sqlite3 (1.3.6)
- thor (0.15.3)
- tzinfo (0.3.33)
+ thor (0.16.0)
+ tzinfo (0.3.35)
PLATFORMS
ruby
View
2  MIT-LICENSE
@@ -1,4 +1,4 @@
-Copyright 2012 Ian White
+Copyright 2012-2013 Ian White
This plugin was developed by Ian White (http://github.com/ianwhite)
while working at Distinctive Doors (http://distinctivedoors.co.uk/oss)
View
9 lib/has_content/content_owner.rb
@@ -43,23 +43,22 @@ def add_content_association name, options
# content getter (delegates to the content association)
define_method name do
- send("get_#{name}_content").content
+ send("#{name}_record").content
end
# content setter (delegates to the content association, updating timestamps on owner record if required)
define_method "#{name}=" do |value|
- (send("get_#{name}_content").content = value).tap do |*|
- if respond_to?(:updated_at?) && send("get_#{name}_content").changed?
+ (send("#{name}_record").content = value).tap do |*|
+ if respond_to?(:updated_at?) && send("#{name}_record").changed?
updated_at_will_change!
end
end
end
# find or build (and save if possible) the content association
- define_method "get_#{name}_content" do
+ define_method "#{name}_record" do
send("#{name}_content") or send("build_#{name}_content").tap {|r| r.name = name; r.save unless new_record? }
end
- private "get_#{name}_content".to_sym
end
end
end
View
2  lib/has_content/version.rb
@@ -1,3 +1,3 @@
module HasContent
- VERSION = '0.0.3'
+ VERSION = '0.0.4'
end
View
13 spec/owner_shared.rb
@@ -41,6 +41,13 @@
lambda { owner.send(content_name) }.should_not change(HasContent::Record, :count)
lambda { owner.save! }.should change(HasContent::Record, :count).by(1)
end
+
+ describe "#<content_name>_association" do
+ subject { owner.send "#{content_name}_record" }
+
+ it { should be_a HasContent::Record }
+ it { should_not be_persisted }
+ end
end
context '[after being saved]' do
@@ -50,5 +57,11 @@
lambda { owner.send(content_name) }.should change(HasContent::Record, :count).by(1)
lambda { owner.save! }.should_not change(HasContent::Record, :count)
end
+
+ describe "#<content_name>_association" do
+ subject { owner.send "#{content_name}_record" }
+
+ it { should be_persisted }
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.