require "#{File.expand_path(File.dirname(__FILE__))}/helper" describe "ControllerContext" do with_environment :development before :all do @dir = "#{File.expand_path(File.dirname(__FILE__))}/controller_context_spec" $LOAD_PATH << @dir AbstractController = Crystal::AbstractController class ItemSpec inherit AbstractController def show; end def update; end def delete; end def increase; end def decrease; end end class PageSpec < ItemSpec def show; end def increase; end end module NamespaceSpec class ClassSpec inherit AbstractController def show; end def update; end end end end after :all do $LOAD_PATH.delete @dir remove_constants %w( ItemSpec PageSpec NamespaceSpec ItemSpecHelper PageSpecHelper AbstractController ) end describe "basic" do it "should provide template name for non-existing template" do ItemSpec.template_name_for(:delete).should == "/ItemSpec/delete" PageSpec.template_name_for(:delete).should == "/ItemSpec/delete" end it "should provide template name for existing template" do ItemSpec.template_name_for(:update).should == "/ItemSpec/update" end it "should inherit template name for template existing in parent" do PageSpec.template_name_for(:update).should == "/ItemSpec/update" end it "should override template name for template existing in both self and parent" do ItemSpec.template_name_for(:show).should == "/ItemSpec/show" PageSpec.template_name_for(:show).should == "/PageSpec/show" end it "should transfer namespaces into folders" do NamespaceSpec::ClassSpec.template_name_for(:show).should == "/NamespaceSpec/ClassSpec/show" end end describe "actions" do it "should be able to check for action inside of actions.xxx files" do ItemSpec.template_name_for(:increase).should == "/ItemSpec/actions" end it "should be able to check for action inside of actions.xxx files" do ItemSpec.template_name_for(:increase).should == "/ItemSpec/actions" ItemSpec.template_name_for(:decrease).should == "/ItemSpec/actions" end it "should inherit actions.xxx" do PageSpec.template_name_for(:increase).should == "/ItemSpec/actions" PageSpec.template_name_for(:decrease).should == "/PageSpec/actions" end end describe "controller_context_class, helper" do before :each do ItemSpec.instance_variable_set "@controller_context_class", nil ItemSpec.instance_variable_set "@controller_context_class", nil end it "controller_context_class" do ItemSpec.controller_context_class.should == ItemSpec::ItemSpecControllerContext PageSpec.controller_context_class.should == PageSpec::PageSpecControllerContext PageSpec::PageSpecControllerContext.is?(PageSpec::ItemSpecControllerContext).should be_true end it "helper" do module ::ItemSpecHelper def controller_item; end end module ::PageSpecHelper def controller_page; end end ItemSpec.helper ItemSpecHelper PageSpec.helper PageSpecHelper ItemSpec::ItemSpecControllerContext.instance_methods.should include('controller_item') PageSpec::PageSpecControllerContext.instance_methods.should include('controller_page') end end describe "other" do it "should understand underscored paths" do NamespaceSpec::ClassSpec.template_name_for(:update).should == "/namespace_spec/class_spec/update" end end end