Skip to content

Commit

Permalink
Improved generating of test environment; Added unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
romul committed Oct 17, 2010
1 parent e0a1b74 commit 2420984
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
SpreeGiftCards
==============

Introduction goes here.

Installation
=======

1. Add `spree_store_credits` and `spree_gift_cards` to Gemfile
1. Run `rails g spree_gift_cards:install`
1. Run `rails g spree_gift_cards:seed`


To run specs
=======

1. rake test_app
1. rails g spree_gift_cards:install -f
1. rake spec


Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ gems
def install_gems
system("cd spec/test_app && rake spree_core:install")
system("cd spec/test_app && rake spree_auth:install")
generate 'spree_store_credits:install -f'
generate 'spree_store_credits:install -f'
generate 'spree_gift_cards:install -f'
end

def migrate_db
run_migrations
generate 'spree_gift_cards:seed'
end
end
AuthTestAppGenerator.start
Expand Down
6 changes: 0 additions & 6 deletions lib/generators/spree_gift_cards/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ class InstallGenerator < Rails::Generators::Base
def copy_migrations
directory "db"
end

def run_db_seeds
system("cd #{Rails.root} && rake db:migrate RAILS_ENV=#{Rails.env}")
seed_file = File.join(File.expand_path("../../../../db", __FILE__), "seeds.rb")
load(seed_file) if File.exist?(seed_file)
end
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions lib/generators/spree_gift_cards/seed_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module SpreeGiftCards
module Generators
class SeedGenerator < Rails::Generators::Base
source_root File.expand_path("../../templates", __FILE__)

desc "Create demo gift card"

def run_db_seeds
seed_file = File.join(File.expand_path("../../../../db", __FILE__), "seeds.rb")
load(seed_file) if File.exist?(seed_file)
end
end
end
end

30 changes: 17 additions & 13 deletions spec/models/gift_card_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
require 'spec_helper'

describe GiftCard do
let(:gift_card) { GiftCard.new }

context "Store credits." do
before do
end

it "Test" do
1.should == 1
end


end
describe "A new GiftCard" do
it "should validate presence of name and email" do
card = GiftCard.new
card.valid?.should == false
card.errors.keys.should == [:email, :name]
end

it "should generate token before create" do
card = GiftCard.create(:email => "[email protected]", :name => "John", :variant_id => 1)
card.token.should_not == nil
end

it "should not allow user set line_item_id and user_id" do
card = GiftCard.create(:email => "[email protected]", :name => "John", :variant_id => 1, :user_id => 1, :line_item_id => 1)
card.line_item_id.should == nil
card.user_id.should == nil
end
end

0 comments on commit 2420984

Please sign in to comment.