require File.dirname(__FILE__) + '/../spec_helper' describe UnstaticHelper, "calling unstatic_content with a new node name" do it "should return an empty string" do unstatic_content("new node").should == "" end end describe UnstaticHelper, "calling unstatic_content with an existing node name" do before(:each) do @unstatic_node = mock_model(UnstaticNode, :content => "content") UnstaticNode.stub!(:find_by_name).and_return(@unstatic_node) end it "should find the node with the requested name" do UnstaticNode.should_receive(:find_by_name).with("node").and_return(@unstatic_node) unstatic_content("node") end it "should return the node's content" do unstatic_content("node").should == markdown("content") end it "should filter node's content through Markdown" do unstatic_content("node").should == "

content

" end end describe UnstaticHelper, "calling unstatic_content while logged in" do before(:each) do @unstatic_node = mock_model(UnstaticNode, :to_param => 1, :content => "") UnstaticNode.stub!(:find_by_name).and_return(@unstatic_node) self.stub!(:unstatic_authorized?).and_return(true) end it "should return a link to edit form if node exists" do unstatic_content("node").should have_tag("a[href=?]", edit_unstatic_node_path(@unstatic_node, :origin => '/', :name => 'node')) end it "should return a link to new form if node does not exist" do UnstaticNode.stub!(:find_by_name).and_return(nil) unstatic_content("node").should have_tag("a[href=?]", new_unstatic_node_path(:origin => '/', :name => 'node')) end it "should return a link to log out" do unstatic_content("node").should have_tag("a[href=?]", unstatic_logout_path) end end describe UnstaticHelper, "calling unstatic_authorized?" do before(:each) do self.stub!(:session).and_return({ :unstatic_password => "pass" }) end it "should return true if password in the session matches a password in the database" do UnstaticPassword.should_receive(:find_by_encrypted).with("pass").and_return(true) unstatic_authorized?.should == true end it "should return false if password in the session does not match a password in the database" do UnstaticPassword.should_receive(:find_by_encrypted).with("pass").and_return(false) unstatic_authorized?.should == false end end