Permalink
Browse files

Fixing mass assignment issue for Spree 1.1 / Rails 3.2. Adding initia…

…l tests for video model
  • Loading branch information...
1 parent ec214de commit eb8736316797f7078836aefd332440873ed96c32 @iloveitaly committed May 18, 2012
Showing with 98 additions and 6 deletions.
  1. +2 −0 .gitignore
  2. +19 −0 Gemfile
  3. +19 −0 Guardfile
  4. +2 −0 README.md
  5. +2 −0 app/models/spree/video.rb
  6. +6 −0 spec/factories/video_factory.rb
  7. +22 −0 spec/models/video_spec.rb
  8. +12 −2 spec/spec_helper.rb
  9. +14 −4 spree_videos.gemspec
View
@@ -7,3 +7,5 @@
tmp
nbproject
*.swp
+spec/dummy
+Gemfile.lock
View
19 Gemfile
@@ -0,0 +1,19 @@
+source 'http://rubygems.org'
+
+group :test do
+ gem 'launchy'
+ gem 'sass'
+ gem 'database_cleaner'
+ gem 'ffaker'
+ gem 'shoulda-matchers'
+ gem 'guard-rspec'
+
+ if RUBY_PLATFORM.downcase.include? "darwin"
+ gem 'rb-fsevent'
+ gem 'growl'
+ end
+end
+
+gem 'spree', '~> 1.1'
+
+gemspec
View
@@ -0,0 +1,19 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+
+ # Rails example
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+ # Capybara request specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
+end
+
View
@@ -29,6 +29,8 @@ You can specify configuration options that get passed through to the JS dynamic
}
end
+Note that as of 05/11/2012 you might have to reference a newer version of `youtube_it` in your Gemfile to get some of the newer features.
+
Contributors
=======
* Mark Linn, @markalinn
@@ -1,6 +1,8 @@
module Spree
class Video < ActiveRecord::Base
belongs_to :product
+
+ attr_accessible :youtube_ref
validates_presence_of :youtube_ref
validates_uniqueness_of :youtube_ref, :scope => [:product_id]
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :video, :class => Spree::Video do |f|
+ youtube_ref 'oUKbtfL4wqk'
+ f.product { |p| p.association(:product) }
+ end
+end
View
@@ -0,0 +1,22 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe Spree::Video do
+ before { @video = FactoryGirl.create(:video) }
+ let(:video) { @video }
+
+ it "should handle different youtube strings" do
+ video.youtube_ref = "http://www.youtube.com/watch?v=9t0n5MD9SBU"
+ video.save
+ video.reload.youtube_ref.should == "9t0n5MD9SBU"
+
+ video.update_attributes :youtube_ref => 'iJ4T9CQA0UM'
+ video.reload.youtube_ref.should == 'iJ4T9CQA0UM'
+
+ video.update_attributes :youtube_ref => 'http://youtu.be/9xtn36e2shw'
+ video.reload.youtube_ref.should == '9xtn36e2shw'
+ end
+
+ it "should not allow two of same videos attached to a product" do
+ expect{ FactoryGirl.create :video, :product => video.product }.to raise_error(ActiveRecord::RecordInvalid)
+ end
+end
View
@@ -1,13 +1,22 @@
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] ||= 'test'
-require File.expand_path("../test_app/config/environment", __FILE__)
+require File.expand_path("../dummy/config/environment", __FILE__)
require 'rspec/rails'
+require 'factory_girl'
+
+# Requires factories defined in spree_core
+require 'spree/core/testing_support/factories'
+require 'spree/core/testing_support/env'
+require 'spree/core/url_helpers'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+# pull in factories
+Dir["#{File.dirname(__FILE__)}/factories/**"].each {|f| require f}
+
RSpec.configure do |config|
# == Mock Framework
#
@@ -20,11 +29,12 @@
config.fixture_path = "#{::Rails.root}/spec/fixtures"
+ config.include Spree::Core::UrlHelpers
+
#config.include Devise::TestHelpers, :type => :controller
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, comment the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end
-@configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
View
@@ -1,15 +1,15 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_videos'
- s.version = '1.2.1'
- s.summary = 'Adds product videos to Spree commerce'
- s.description = 'Add (optional) gem description here'
+ s.version = '1.2.2'
+ s.summary = 'Adds youtube videos to Spree commerce products'
+ s.description = 'Add multiuple youtube videos, and a thumbnail selector' +
+ 'for those products to a Spree commerce product'
s.required_ruby_version = '>= 1.8.7'
s.author = 'Michael Bianco'
s.email = 'info@cliffsidedev.com'
s.homepage = 'http://mabblog.com/'
- # s.rubyforge_project = 'actionmailer'
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -18,4 +18,14 @@ Gem::Specification.new do |s|
s.add_dependency('spree_core', '>= 1.0.0')
s.add_dependency('youtube_it', '>= 2.1.4')
+
+ # test suite
+ s.add_development_dependency 'shoulda-matchers'
+ s.add_development_dependency 'capybara', '1.0.1'
+ s.add_development_dependency 'factory_girl_rails', '~> 3.0.0'
+ s.add_development_dependency 'rspec-rails', '~> 2.9'
+ s.add_development_dependency 'guard-rspec'
+ s.add_development_dependency 'database_cleaner'
+ s.add_development_dependency 'launchy'
+ s.add_development_dependency 'sqlite3'
end

0 comments on commit eb87363

Please sign in to comment.