Sha256: c9470dadf3be27cdb87f12f2904622db3400df5301618afffbc7b5db0f65b943

Contents?: true

Size: 1.64 KB

Versions: 11

Compression:

Stored size: 1.64 KB

Contents

# -*- coding: utf-8 -*-
require 'spec_helper'
require 'rack/test'
require 'fileutils'
require 'sprockets'
require 'tdiary/rack/assets/precompile'

describe TDiary::Rack::Assets::Precompile do
	include Rack::Test::Methods

	let(:app) do
		TDiary::Rack::Assets::Precompile.new(lambda{|env| [200, {}, ['Awesome']]}, @environment)
	end
	let(:assets_path) {"#{TDiary::PATH}/tmp/assets"}

	before do
		FileUtils.mkdir_p assets_path
		@environment = Sprockets::Environment.new
		@environment.append_path assets_path
	end

	after do
		FileUtils.rm_rf assets_path
	end

	context "JavaScript が無い場合" do
		before do
			FileUtils.touch "#{assets_path}/foo.coffee"
			get '/'
		end

		it "JavaScript にコンパイルされる" do
			FileTest.exist?("#{assets_path}/foo.js").should be_true
		end
	end

	context "JavaScript がある場合" do
		context "CoffeeScript の方が新しい場合" do
			before do
				FileUtils.touch "#{assets_path}/foo.js"
				sleep 1
				FileUtils.touch "#{assets_path}/foo.coffee"
				@jstime = File.mtime("#{assets_path}/foo.js").to_i

				get '/'
			end

			it "JavaScript が更新される" do
				@jstime.should < File.mtime("#{assets_path}/foo.js").to_i
			end
		end

		context "JavaScript の方が新しい場合" do
			before do
				FileUtils.touch "#{assets_path}/foo.coffee"
				sleep 1
				FileUtils.touch "#{assets_path}/foo.js"
				@jstime = File.mtime("#{assets_path}/foo.js").to_i

				get '/'
			end

			it "JavaScript は更新されない" do
				@jstime.should == File.mtime("#{assets_path}/foo.js").to_i
			end
		end
	end
end

# Local Variables:
# mode: ruby
# indent-tabs-mode: t
# tab-width: 3
# ruby-indent-level: 3
# End:

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
tdiary-4.0.2.20140201 spec/core/rack/assets/precompile_spec.rb
tdiary-4.0.2 spec/core/rack/assets/precompile_spec.rb
tdiary-4.0.1.20131102 spec/core/rack/assets/precompile_spec.rb
tdiary-4.0.1.20130929 spec/core/rack/assets/precompile_spec.rb
tdiary-4.0.1.20130903 spec/core/rack/assets/precompile_spec.rb
tdiary-4.0.1 spec/core/rack/assets/precompile_spec.rb
tdiary-4.0.0.20130826 spec/core/rack/assets/precompile_spec.rb
tdiary-4.0.0 spec/core/rack/assets/precompile_spec.rb
tdiary-3.2.2.20130727 spec/core/rack/assets/precompile_spec.rb
tdiary-3.2.2.20130722 spec/core/rack/assets/precompile_spec.rb
tdiary-3.2.2.20130720 spec/core/rack/assets/precompile_spec.rb