Skip to content
This repository
Browse code

introduces shipped_at field to identify when issues have been shipped

  • Loading branch information...
commit 9b6e6a02bce1ba9703060905e1930d6ca8e10940 1 parent fce2585
Alberto Vena authored August 01, 2012
5  app/models/spree/issue.rb
@@ -3,7 +3,7 @@ class Spree::Issue < ActiveRecord::Base
3 3
   belongs_to :magazine_issue, :class_name => "Spree::Product"
4 4
   has_many :shipped_issues
5 5
 
6  
-  attr_accessible :name, :published_at, :magazine, :magazine_issue_id
  6
+  attr_accessible :name, :published_at, :shipped_at, :magazine, :magazine_issue_id
7 7
 
8 8
   delegate :subscriptions,:to => :magazine
9 9
 
@@ -17,10 +17,11 @@ def name
17 17
 
18 18
   def ship!
19 19
     subscriptions.each{ |s| s.ship!(self) }
  20
+    update_attribute(:shipped_at, Time.now)
20 21
   end
21 22
 
22 23
   def shipped?
23  
-    !shipped_issues.empty?
  24
+    !shipped_at.nil?
24 25
   end
25 26
   
26 27
 end
5  db/migrate/20120801134107_add_shipped_to_spree_issue.rb
... ...
@@ -0,0 +1,5 @@
  1
+class AddShippedToSpreeIssue < ActiveRecord::Migration
  2
+  def change
  3
+    add_column :spree_issues, :shipped_at, :datetime
  4
+  end
  5
+end
12  spec/models/spree/issue_spec.rb
@@ -36,4 +36,16 @@
36 36
     issue = Factory.create(:issue, :magazine => subscription.magazine)
37 37
     expect{ issue.ship! }.to change(issue.shipped_issues, :count).by(1)
38 38
   end
  39
+
  40
+  it "should have shipped_at field to nil when not shipped" do
  41
+    subscription = Factory.create(:paid_subscription)
  42
+    issue = Factory.create(:issue, :magazine => subscription.magazine)
  43
+    issue.shipped_at.should be_nil
  44
+  end
  45
+
  46
+  it "should have shipped_at field not nil when shipped" do
  47
+    subscription = Factory.create(:paid_subscription)
  48
+    issue = Factory.create(:issue, :magazine => subscription.magazine)
  49
+    expect{ issue.ship! }.to change{issue.shipped_at}  
  50
+  end  
39 51
 end

0 notes on commit 9b6e6a0

Please sign in to comment.
Something went wrong with that request. Please try again.