Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Respect scope as record differentiator.

Frequently, when I'm creating a site, I'll have elements that have similar names, but are differentiated by their scope (i.e. I might have a 'read more' button that's applicable to both blog and news posts). At present, copywriting will only create one entry for each 'read_more' button, whereas I hold that it is useful and expected behaviour to create multiple entries. As an analogy, you should be able to have a file called 'my_text_file.txt' in both folders Foo and Bar.

This commit addresses that shortcoming and adds an appropriate test to ensure scoping is respected.
  • Loading branch information...
commit 419868453034413be9329622608b7e20271d47ab 1 parent 33067db
@robyurkowski robyurkowski authored
View
4 app/models/refinery/copywriting/phrase.rb
@@ -19,7 +19,7 @@ def self.for(name, options = {})
options[:name] = name.to_s
options[:page_id] ||= options[:page].try(:id)
- phrase = self.find_by_name_and_page_id(options[:name], options[:page_id]) || self.create(options)
+ phrase = self.find_by_name_and_scope_and_page_id(options[:name], options[:scope], options[:page_id]) || self.create(options)
phrase.update_attributes(options.except(:value, :page, :page_id, :locale))
phrase.last_access_at = Date.today
phrase.save if phrase.changed?
@@ -33,4 +33,4 @@ def default_or_value
end
end
-end
+end
View
9 spec/models/copywriting_phrase_spec.rb
@@ -22,7 +22,12 @@
Refinery::Copywriting::Phrase.where(:name => 'name').count.should == 1
end
- it "should return the string the value once its set" do
+ it "differentiates records by scope" do
+ 2.times {|n| Refinery::Copywriting::Phrase.for('name', {:scope => "scope#{n}", :default => 'default'}) }
+ Refinery::Copywriting::Phrase.where(:name => 'name').pluck(:scope).should =~ ['scope0', 'scope1']
+ end
+
+ it "should return the string the value once it is set" do
Refinery::Copywriting::Phrase.for('name', {:scope => 'scope', :default => 'default'}).should == 'default'
copy = Refinery::Copywriting::Phrase.where(:name => 'name').first
copy.value = 'updated!'
@@ -75,4 +80,4 @@
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.