Sha256: c9cdd0679d72c9fa10b05f3ab90cb500ee85e6f55ac17257ca30d620e9765999

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'

module Stachio
  class MockProxyObject
    def teapot
      "TEAPOT"
    end
  end

  describe Template do
    let(:template) do
      attrs = { :template_name => "my silly teapot",
                :content => "I am a {{teapot}}",
              }
      template = Template.new(attrs)
      template.proxied = MockProxyObject.new
      template
    end

    it "stores templates in the database" do
      template.save!.should be_true
      Template.count.should eql(1)
      Template.first.should == template
    end

    it "validates the presence of template_name" do
      template.template_name = ""
      template.should_not be_valid
      template.template_name = "but i am a template!"
      template.should be_valid
    end

    it "validates the presence of content" do
      template.content = ""
      template.should_not be_valid
      template.content = "but i am a {{teapot}}!"
      template.should be_valid
    end

    it "fetches templates from the database using the template name" do
      template.save!
      template.should == Template['my silly teapot']
    end

    it "composes messages using the content of the template" do
      template.compose.should == "I am a TEAPOT"
    end

    it "reports an error when it can't compose the message" do
      template.content = "I am not a valid {{horseradish}}"
      expect { template.compose }.to raise_error(Mustache::ContextMiss)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stachio-0.0.2 spec/models/stachio/template_spec.rb
stachio-0.0.1 spec/models/stachio/template_spec.rb