Permalink
Browse files

Maker#prefix can be used also as a setter.

Signed-off-by: Pat Nakajima <patnakajima@gmail.com>
  • Loading branch information...
1 parent bb0f296 commit 6c5fc32a5937a32799ca74e124aca5ff2f20307a @baldowl baldowl committed with Feb 5, 2009
Showing with 24 additions and 2 deletions.
  1. +2 −2 lib/sinatras-hat/maker.rb
  2. +22 −0 spec/maker_spec.rb
@@ -116,8 +116,8 @@ def protect(*actions)
end
# The path prefix to use for routes and such.
- def prefix
- options[:prefix] ||= model.plural
+ def prefix(name = nil)
+ options[:prefix] ||= (name || model.plural)
end
# An array of parent Maker instances under which this instance
View
@@ -266,6 +266,28 @@ class Comment; end
end
describe "prefix" do
+ context "when used as a method" do
+ before(:each) do
+ @maker = new_maker(Article)
+ end
+
+ it "is a getter if called without argument" do
+ maker.prefix.should == maker.options[:prefix]
+ end
+
+ it "is a setter if called with an argument" do
+ maker.prefix 'super/heroes'
+ maker.prefix.should == 'super/heroes'
+ maker.prefix.should == maker.options[:prefix]
+ end
+
+ it "memoizes the value" do
+ maker.prefix.should == 'articles'
+ maker.prefix 'secret/agents'
+ maker.prefix.should_not == 'secret/agents'
+ end
+ end
+
context "when specified as an option" do
it "returns the option value" do
new_maker(Article, :prefix => "posts").prefix.should == "posts"

0 comments on commit 6c5fc32

Please sign in to comment.