spec/presenter_spec.rb in curly-templates-0.7.0 vs spec/presenter_spec.rb in curly-templates-0.8.0
- old
+ new
@@ -7,14 +7,20 @@
end
end
include MonkeyComponents
- presents :midget, :clown
- attr_reader :midget, :clown
+ presents :midget, :clown, default: nil
+ presents :elephant, default: "Dumbo"
+
+ attr_reader :midget, :clown, :elephant
end
+ class FrenchCircusPresenter < CircusPresenter
+ presents :elephant, default: "Babar"
+ end
+
it "sets the presented parameters as instance variables" do
context = double("context")
presenter = CircusPresenter.new(context,
midget: "Meek Harolson",
@@ -23,10 +29,22 @@
presenter.midget.should == "Meek Harolson"
presenter.clown.should == "Bubbles"
end
+ it "allows specifying default values for parameters" do
+ context = double("context")
+
+ # Make sure subclasses can change default values.
+ french_presenter = FrenchCircusPresenter.new(context)
+ french_presenter.elephant.should == "Babar"
+
+ # The subclass shouldn't change the superclass' defaults, though.
+ presenter = CircusPresenter.new(context)
+ presenter.elephant.should == "Dumbo"
+ end
+
describe ".presenter_for_path" do
it "returns the presenter class for the given path" do
presenter = double("presenter")
stub_const("Foo::BarPresenter", presenter)
@@ -42,9 +60,29 @@
String.any_instance.stub(:constantize).and_raise(error)
expect do
Curly::Presenter.presenter_for_path("foo/bar")
end.to raise_error(NameError)
+ end
+ end
+
+ describe ".available_methods" do
+ it "includes the methods on the presenter" do
+ CircusPresenter.available_methods.should include(:midget)
+ end
+
+ it "does not include methods on the Curly::Presenter base class" do
+ CircusPresenter.available_methods.should_not include(:cache_key)
+ end
+ end
+
+ describe ".method_available?" do
+ it "returns true if the method is available" do
+ CircusPresenter.method_available?(:midget).should be_true
+ end
+
+ it "returns false if the method is not available" do
+ CircusPresenter.method_available?(:bear).should be_false
end
end
describe ".version" do
it "sets the version of the presenter" do