Commit d6f20222

mo k <mo@mokhan.ca>
2012-10-13 02:35:22
add is_published? to the creation model.
1 parent f071069
Changed files (6)
app/models/creation.rb
@@ -41,4 +41,8 @@ class Creation < ActiveRecord::Base
       photo.image = image.file
       photo.save!
   end
+
+  def is_published?
+    photos.where(:is_primary => true).any?
+  end
 end
config/environments/test.rb
@@ -5,7 +5,7 @@ Cake::Application.configure do
   # test suite.  You never need to work with it otherwise.  Remember that
   # your test database is "scratch space" for the test suite and is wiped
   # and recreated between test runs.  Don't rely on the data there!
-  config.cache_classes = true
+  config.cache_classes = !(ENV['DRB'] == 'true')
 
   # Log error messages when you accidentally call methods on nil.
   config.whiny_nils = true
config/initializers/delayed_job_config.rb
@@ -0,0 +1,6 @@
+Delayed::Worker.destroy_failed_jobs = false
+Delayed::Worker.sleep_delay = 60
+Delayed::Worker.max_attempts = 3
+Delayed::Worker.max_run_time = 5.minutes
+Delayed::Worker.read_ahead = 10
+Delayed::Worker.delay_jobs = !Rails.env.test?
config/deploy.rb
@@ -30,16 +30,14 @@ after 'deploy:update_code', 'deploy:symlink_db'
 after "deploy:start", "delayed_job:start"
 after "deploy:stop", "delayed_job:stop"
 after "deploy:restart", "delayed_job:restart"
-after "deploy:restart", "restart_server"
-
-task :restart_server do
-    run "cd #{current_path}; touch tmp/restart.txt"
-end
 
 namespace :deploy do
   task :symlink_db, :roles => :app do
     run "ln -nfs #{release_path}/config/database.production.yml.example #{release_path}/config/database.yml"
   end
+  task :restart, :roles => :web do
+    run "touch #{current_path}/tmp/restart.txt"
+  end
 end
 namespace :delayed_job do 
   desc "start the delayed_job process"
spec/models/creation_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe Creation do
+  let(:sut) { FactoryGirl.create(:creation) }
+
+  context "when not published" do
+    it "should return false" do
+      sut.is_published?.should == false
+    end
+  end
+  context "when published" do
+    it "should return true" do
+      sut.is_published?.should == true
+    end
+    before(:each) do
+      sut.migrate_primary_image
+    end
+  end
+
+end
spec/spec_helper.rb
@@ -18,6 +18,8 @@ end
 
 Spork.each_run do
   # This code will be run each time you run your specs.
+  ActiveSupport::Dependencies.clear
+  FactoryGirl.reload
   Devise.stretches = 1
   Rails.logger.level = 4
 end