Created
November 13, 2012 10:19
-
-
Save mhenrixon/4065042 to your computer and use it in GitHub Desktop.
More comparisons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Template do | |
let(:site) { create :site } | |
let(:template) { create :template, name: "ABCD", tpl_type: 'tpl', site: site } | |
subject { template } | |
# this also tests downcasing names | |
its(:tpl_name) { should eql('abcd.tpl') } | |
its(:dirname) { should eql("#{Rails.root}/public/sites/#{template.site_id}/templates") } | |
its(:filename) { should eql("#{template.dirname}/#{template.tpl_name}") } | |
before { template.delete_template_file } | |
it "creates a physical file" do | |
template.create_template_file | |
File.exists?(template.filename).should be_true | |
end | |
it "creates a physical file" do | |
template.create_template_file | |
template.delete_template_file | |
File.exists?(template.filename).should be_false | |
end | |
context "deleting a file that does not exist" do | |
it "should not raise errors if file is missing" do | |
expect { | |
template.delete_template_file | |
}.to_not raise_error | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class TemplateTest < ActiveSupport::TestCase | |
test 'to return the full template name' do | |
assert_equal(templates(:one).tpl_name, 'one.tpl') | |
end | |
test 'to return the path to the template files directory' do | |
assert_equal( | |
templates(:one).dirname, | |
"#{Rails.root}/public/sites/#{templates(:one).site_id}/templates") | |
end | |
test 'to return the path to the template file' do | |
assert_equal( | |
templates(:one).filename, | |
"#{templates(:one).dirname}/#{templates(:one).tpl_name}") | |
end | |
test 'to create and delete the physical template file' do | |
assert(!File.exists?(templates(:one).filename)) | |
templates(:one).create_template_file | |
assert(File.exists?(templates(:one).filename)) | |
templates(:one).delete_template_file | |
assert(!File.exists?(templates(:one).filename)) | |
end | |
test 'to delete the template file without failing if the file does not exist' do | |
assert_nothing_raised do | |
templates(:one).delete_template_file | |
assert(!File.exists?(templates(:one).filename)) | |
templates(:one).delete_template_file | |
end | |
end | |
test 'to ensure downcase on the name' do | |
templates(:one).name = 'ONE' | |
templates(:one).ensure_name_downcase | |
assert_equal(templates(:one).name, 'one') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment