Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support for packaging with Jammit

  • Loading branch information...
commit 6e7e5b433e3f56ea502d3f81083b029045c1c8af 1 parent c36c62c
@gabebw gabebw authored
Showing with 114 additions and 0 deletions.
  1. +1 −0  kumade.gemspec
  2. +24 −0 lib/kumade/deployer.rb
  3. +89 −0 spec/deployer_spec.rb
View
1  kumade.gemspec
@@ -23,4 +23,5 @@ Gem::Specification.new do |s|
s.add_development_dependency('rspec', '~> 2.6.0')
s.add_development_dependency('cucumber', '~> 1.0.2')
s.add_development_dependency('aruba', '~> 0.4.3')
+ s.add_development_dependency('jammit', '~> 0.6.3')
end
View
24 lib/kumade/deployer.rb
@@ -7,6 +7,7 @@ def load_tasks
def pre_deploy
ensure_clean_git
ensure_rake_passes
+ package_assets
git_push('origin')
end
@@ -44,6 +45,29 @@ def ensure_rake_passes
end
end
+ def package_assets
+ begin
+ require 'jammit'
+ Jammit.package!
+ announce("Successfully packaged with Jammit")
+ if git_dirty?
+ git_add_and_commit_all_assets
+ end
+ rescue LoadError
+ end
+ end
+
+ def git_add_and_commit_all_assets
+ announce "Committing assets"
+ run_or_raise("git add #{absolute_assets_path} && git commit -m 'Assets'",
+ "Cannot deploy: couldn't commit assets")
+ end
+
+ def absolute_assets_path
+ require 'jammit'
+ File.join(Jammit::PUBLIC_ROOT, Jammit.package_path)
+ end
+
def default_task_exists?
Rake::Task.task_defined?('default')
end
View
89 spec/deployer_spec.rb
@@ -1,4 +1,5 @@
require 'spec_helper'
+require 'jammit'
class Kumade
describe Deployer, "#load_tasks" do
@@ -17,6 +18,7 @@ class Kumade
%w(
ensure_clean_git
ensure_rake_passes
+ package_assets
git_push
).each do |task|
subject.should_receive(task).ordered.and_return(true)
@@ -216,4 +218,91 @@ class Kumade
subject.rake_succeeded?.should be_false
end
end
+
+ describe Deployer, "#package_assets" do
+ before do
+ subject.stub(:git_add_and_commit_all_assets).and_return(true)
+ subject.stub(:announce)
+ Jammit.stub(:package!)
+ end
+
+ it "calls Jammit.package!" do
+ Jammit.should_receive(:package!).once
+ subject.package_assets
+ end
+
+ it "rescues from LoadError" do
+ Jammit.stub(:package!){ raise LoadError }
+ lambda do
+ subject.package_assets
+ end.should_not raise_error
+ end
+
+ it "prints the correct message if packaging succeeded" do
+ subject.should_receive(:announce).with("Successfully packaged with Jammit")
+
+ subject.package_assets
+ end
+
+ it "raises an error if packaging failed" do
+ Jammit.stub(:package!) do
+ raise Jammit::MissingConfiguration.new("random Jammit error")
+ end
+
+ lambda do
+ subject.package_assets
+ end.should raise_error(Jammit::MissingConfiguration)
+ end
+
+ it "calls git_add_and_commit_all_assets if assets were added" do
+ subject.stub(:git_dirty?).and_return(true)
+ subject.should_receive(:git_add_and_commit_all_assets).and_return(true)
+
+ subject.package_assets
+ end
+
+ it "does not call git_add_and_commit_all_assets if no assets were added" do
+ subject.stub(:git_dirty?).and_return(false)
+ subject.should_receive(:git_add_and_commit_all_assets).exactly(0).times
+
+ subject.package_assets
+ end
+ end
+
+ describe Deployer, "#git_add_and_commit_all_assets" do
+ before do
+ subject.stub(:announce)
+ subject.stub(:run).and_return(true)
+ end
+
+ it "announces the correct message" do
+ subject.should_receive(:announce).with("Committing assets")
+
+ subject.git_add_and_commit_all_assets
+ end
+
+ it "runs the correct commands" do
+ subject.stub(:absolute_assets_path).and_return("blerg")
+ subject.should_receive(:run).
+ with("git add blerg && git commit -m 'Assets'")
+
+ subject.git_add_and_commit_all_assets
+ end
+
+ it "raises an error if it could not add and commit assets" do
+ subject.stub(:run).and_return(false)
+
+ lambda do
+ subject.git_add_and_commit_all_assets
+ end.should raise_error("Cannot deploy: couldn't commit assets")
+ end
+ end
+
+ describe Deployer, "#absolute_assets_path" do
+ it "returns the correct asset path" do
+ Jammit.stub(:package_path => 'blerg')
+ current_dir = File.expand_path(Dir.pwd)
+ subject.absolute_assets_path.should == File.join(current_dir, 'public', 'blerg')
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.