Skip to content

Commit

Permalink
Maker#prefix can be used also as a setter.
Browse files Browse the repository at this point in the history
Signed-off-by: Pat Nakajima <patnakajima@gmail.com>
  • Loading branch information
baldowl authored and nakajima committed Feb 5, 2009
1 parent bb0f296 commit 6c5fc32
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/sinatras-hat/maker.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def protect(*actions)
end end


# The path prefix to use for routes and such. # The path prefix to use for routes and such.
def prefix def prefix(name = nil)
options[:prefix] ||= model.plural options[:prefix] ||= (name || model.plural)
end end


# An array of parent Maker instances under which this instance # An array of parent Maker instances under which this instance
Expand Down
22 changes: 22 additions & 0 deletions spec/maker_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -266,6 +266,28 @@ class Comment; end
end end


describe "prefix" do 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 context "when specified as an option" do
it "returns the option value" do it "returns the option value" do
new_maker(Article, :prefix => "posts").prefix.should == "posts" new_maker(Article, :prefix => "posts").prefix.should == "posts"
Expand Down

0 comments on commit 6c5fc32

Please sign in to comment.