public
Fork of vigetlabs/crash_cart
Description: Tools to manage ExpressionEngine ... maybe.
Clone URL: git://github.com/reagent/crash_cart.git
reagent (author)
Tue May 13 18:48:13 -0700 2008
commit  0b531f46d2737cd019584988ae279916f0bd05e0
tree    e1418ea86eaa37b71f05061a7df32bbba577ad1d
parent  54a3515aadffd0867e1dcff90e84b6f7b9509ae4
crash_cart / spec / expression_engine / models / template_spec.rb
100644 72 lines (50 sloc) 1.987 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
 
module ExpressionEngine::Models
 
  describe Template do
    
    it "should have an associated file" do
      path = '/path/to/ee/root/templates'
      template_file = mock()
 
      ExpressionEngine::Files::Template.expects(:new).with(path, kind_of(Template)).returns(template_file)
      
      Template.any_instance.expects(:preferences).with(nil).returns({:tmpl_file_basepath => path})
      
      t = Template.find(1)
      t.file.should == template_file
    end
    
  end
 
  describe Template, "with an existing record" do
 
    before { @template = Template.find(1) }
 
    it "should be findable by ID" do
      @template.should be_an_instance_of(Template)
    end
    
    it "should save the associated file if it is configured to do so" do
      @template.save_template_file = true
      @template.file.expects(:save).once
      @template.save_file
    end
    
    it "should not save the associated file if it is not configured to do so" do
      @template.save_template_file = false
      @template.file.expects(:save).never
      @template.save_file
    end
 
    it "should save the template file when saving the record" do
      @template.expects(:save_file).with(nil)
      @template.save
    end
    
    it "should have associated preferences" do
      @template.site.preferences[:template].should == @template.preferences
    end
 
  end
 
  describe Template, "with a new record" do
    
    before { @template = Template.new(:template_name => 'index')}
    
    it "should know if it is saving a file to disk" do
      t = Template.new(:save_template_file => false)
      @template.save_template_file?.should be_false
    end
 
    it "should be able to specify that it's saving a file to disk" do
      t = Template.new(:save_template_file => true)
      t.save_template_file?.should be_true
    end
    
    it "should have a name" do
      @template.name.should == 'index'
    end
    
  end
 
end