Merge branch 'rails4'

Upgrade all dependencies, then rails from 3.x to 4.0.
This commit is contained in:
Thibault Jouan 2014-04-01 10:07:56 +00:00
commit 92ac87c54e
49 changed files with 208 additions and 355 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
/Gemfile-custom.rb
/Gemfile.lock
/config/database.yml
/data/
/log/*.log

16
Gemfile
View File

@ -1,16 +1,18 @@
source 'http://rubygems.org'
gem 'rails', '~> 3.1'
gem 'pg', '~> 0.11'
gem 'haml', '~> 3.1'
gem 'bcrypt-ruby', '~> 3.0'
gem 'rails', '~> 4.0'
gem 'pg', '~> 0.17'
gem 'haml', '~> 4.0'
gem 'bcrypt', '~> 3.0'
gem 'rabl', '~> 0.6'
gem 'protected_attributes', '~> 1.0'
group :development, :test do
gem 'rspec-rails', '~> 2.6'
gem 'capybara', '~> 1.1'
gem 'factory_girl_rails', '~> 1.2'
gem 'shoulda-matchers', '~> 1.0'
gem 'capybara', '~> 2.2'
gem 'factory_girl_rails', '~> 4.4'
gem 'shoulda-matchers', '~> 2.5'
end
eval File.read('Gemfile-custom.rb') if File.exist?('Gemfile-custom.rb')

View File

@ -1,151 +0,0 @@
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.2.2)
actionpack (= 3.2.2)
mail (~> 2.4.0)
actionpack (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
rack-cache (~> 1.1)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
activemodel (3.2.2)
activesupport (= 3.2.2)
builder (~> 3.0.0)
activerecord (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
activesupport (3.2.2)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
bcrypt-ruby (3.0.1)
builder (3.0.0)
capybara (1.1.2)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
childprocess (0.3.1)
ffi (~> 1.0.6)
diff-lcs (1.1.3)
erubis (2.7.0)
factory_girl (2.6.4)
activesupport (>= 2.3.9)
factory_girl_rails (1.7.0)
factory_girl (~> 2.6.0)
railties (>= 3.0.0)
ffi (1.0.11)
guard (0.10.0)
ffi (>= 0.5.0)
thor (~> 0.14.6)
guard-rspec (0.6.0)
guard (>= 0.10.0)
guard-spork (0.5.2)
guard (>= 0.10.0)
spork (>= 0.8.4)
haml (3.1.4)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
json (1.6.5)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
multi_json (1.1.0)
nokogiri (1.5.2)
pg (0.13.2)
polyglot (0.3.3)
rabl (0.6.1)
activesupport (>= 2.3.14)
multi_json (~> 1.1.0)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.2.2)
actionmailer (= 3.2.2)
actionpack (= 3.2.2)
activerecord (= 3.2.2)
activeresource (= 3.2.2)
activesupport (= 3.2.2)
bundler (~> 1.0)
railties (= 3.2.2)
railties (3.2.2)
actionpack (= 3.2.2)
activesupport (= 3.2.2)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
rspec (2.9.0)
rspec-core (~> 2.9.0)
rspec-expectations (~> 2.9.0)
rspec-mocks (~> 2.9.0)
rspec-core (2.9.0)
rspec-expectations (2.9.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.9.0)
rspec-rails (2.9.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.9.0)
rubyzip (0.9.6.1)
selenium-webdriver (2.20.0)
childprocess (>= 0.2.5)
ffi (~> 1.0)
multi_json (~> 1.0)
rubyzip
shoulda-matchers (1.0.0)
spork (0.9.0)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.32)
xpath (0.1.4)
nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
bcrypt-ruby (~> 3.0)
capybara (~> 1.1)
factory_girl_rails (~> 1.2)
guard (~> 0.8)
guard-rspec (~> 0.4)
guard-spork (~> 0.2)
haml (~> 3.1)
pg (~> 0.11)
rabl (~> 0.6)
rails (~> 3.1)
rspec-rails (~> 2.6)
shoulda-matchers (~> 1.0)
spork (~> 0.9.0.rc)

View File

@ -3,6 +3,8 @@ require 'fileutils'
class Sound < ActiveRecord::Base
belongs_to :track
attr_accessible :file
validates_presence_of :sha256
validates_presence_of :mime_type

4
bin/bundle Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')

5
bin/rails Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'

5
bin/rake Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run

View File

@ -2,12 +2,9 @@ require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Scube
class Application < Rails::Application
@ -15,16 +12,6 @@ module Scube
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
@ -32,31 +19,5 @@ module Scube
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# BestStandardsSupport is setting this fucking X-UA-Compatible header...
config.middleware.delete ActionDispatch::BestStandardsSupport
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
# config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
end
end

View File

@ -1,6 +1,4 @@
require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])

View File

@ -1,5 +1,5 @@
# Load the rails application
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the rails application
# Initialize the Rails application.
Scube::Application.initialize!

View File

@ -1,37 +1,29 @@
Scube::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Raise an error on page load if there are pending migrations
config.active_record.migration_error = :page_load
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
end

View File

@ -1,67 +1,80 @@
Scube::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests
# Code is not reloaded between requests.
config.cache_classes = true
# Full error reports are disabled and caching is turned on
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Don't fallback to assets pipeline if a precompiled asset is missed
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs
# Generate digests for assets URLs.
config.assets.digest = true
# Defaults to Rails.root.join("public/assets")
# config.assets.manifest = YOUR_PATH
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
# Specifies the header that your server uses for sending files
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# See everything in the log (default is :info)
# config.log_level = :debug
# Set to :debug to see everything in the log.
config.log_level = :info
# Prepend all log lines with the following tags
# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# config.assets.precompile += %w( search.js )
# Disable delivery errors, bad email addresses will be ignored
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
# the I18n.default_locale when a translation can not be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
end

View File

@ -1,5 +1,5 @@
Scube::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
@ -7,21 +7,23 @@ Scube::Application.configure do
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Configure static asset server for tests with Cache-Control for performance
# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
# Log error messages when you accidentally call methods on nil
config.whiny_nils = true
# Show full error reports and disable caching
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates
# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
@ -29,9 +31,6 @@ Scube::Application.configure do
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Print deprecation notices to the stderr
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
end

View File

@ -0,0 +1,4 @@
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [:password]

View File

@ -1,16 +1,17 @@
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
#
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections do |inflect|
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.acronym 'RESTful'
# end

View File

@ -1,7 +1,12 @@
# Be sure to restart your server when you modify this file.
# Your secret key for verifying the integrity of signed cookies.
# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
Scube::Application.config.secret_token = '1bc686843bfcf76e9ab8c057e11dbc14b9cec8574d4b189720223fc1faa18b4eadf98cb27fa8b4b224f373013ab3828c6874878a679b050c90ca839a5f731bfa'
# You can use `rake secret` to generate a secure secret key.
# Make sure your secret_key_base is kept private
# if you're sharing your code publicly.
Scube::Application.config.secret_key_base = 'd0fb5028d03e9030435af05646555d948bbb65cef3910016c9dc34f5799a5bc6c8d41a248e02df21a27fef348eecc9dc5f9662dc277e0c17210a7cfc513200aa'

View File

@ -1,8 +1,3 @@
# Be sure to restart your server when you modify this file.
#Scube::Application.config.session_store :cookie_store, :key => '_scube_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
Scube::Application.config.session_store :active_record_store
Scube::Application.config.session_store :cookie_store, key: '_scube_session'

View File

@ -1,14 +1,14 @@
# Be sure to restart your server when you modify this file.
#
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json]
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
end
# Disable root element in JSON by default.
# To enable root element in JSON for ActiveRecord objects.
ActiveSupport.on_load(:active_record) do
self.include_root_in_json = false
self.include_root_in_json = true
end

View File

@ -1,5 +1,23 @@
# Sample localization file for English. Add more files in this directory for other locales.
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
# <%= t('hello') %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html.
en:
hello: "Hello world"

View File

@ -1,6 +0,0 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'

View File

@ -9,7 +9,7 @@ describe API::ApplicationController do
context 'CORS: Cross-Origin Ressource Sharing' do
before do
request.env['Origin'] = 'http://origin.example/'
request.headers['Origin'] = 'http://origin.example/'
end
context 'preflight' do
@ -18,7 +18,7 @@ describe API::ApplicationController do
end
def options(action)
process action, nil, nil, nil, 'OPTIONS'
process action, 'OPTIONS'
end
it 'sets Access-Control-Allow-Methods header' do
@ -43,8 +43,8 @@ describe API::ApplicationController do
it 'sets Access-Control-Allow-Origin header' do
get :index
response.headers['Access-Control-Allow-Origin'].should ==
request.env['Origin']
response.headers['Access-Control-Allow-Origin']
.should == request.headers['Origin']
end
end
end

View File

@ -8,9 +8,11 @@ describe API::PlaylistsController do
end
describe 'GET index' do
render_views
before do
playlist_1 = Factory.create(:playlist, :name => 'Playlist 1')
playlist_2 = Factory.create(:playlist, :name => 'Playlist 2')
playlist_1 = FactoryGirl.create(:playlist, :name => 'Playlist 1')
playlist_2 = FactoryGirl.create(:playlist, :name => 'Playlist 2')
end
def do_get
@ -35,7 +37,7 @@ describe API::PlaylistsController do
def do_create
post :create,
:format => :json,
:playlist => Factory.attributes_for(:playlist)
:playlist => FactoryGirl.attributes_for(:playlist)
end
it 'creates a new playlist for the current user' do

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe API::SessionsController do
describe 'POST create' do
let(:user) { Factory.create(:user) }
let(:user) { FactoryGirl.create(:user) }
def do_create
post :create, :format => :json, :session => {

View File

@ -8,9 +8,11 @@ describe API::TracksController do
end
describe 'GET index' do
render_views
before do
Factory.create(:track_with_sound)
Factory.create(:track_with_sound)
FactoryGirl.create(:track_with_sound)
FactoryGirl.create(:track_with_sound)
end
def do_get

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe ApplicationController do
let(:user) { Factory.create(:user) }
let(:user) { FactoryGirl.create(:user) }
describe '#current_user=' do
it 'stores the user id in the session as :user_id' do

View File

@ -9,14 +9,14 @@ describe HomeController do
describe 'GET index' do
it 'assigns all playlists as @playlists' do
playlist = Factory.create(:playlist)
playlist = FactoryGirl.create(:playlist)
get :index
assigns[:playlists].should == [playlist]
end
it 'assigns latest tracks as @tracks' do
track1 = Factory.create(:track, :created_at => '2011-07-27 19:13:42')
track2 = Factory.create(:track, :created_at => '2011-07-27 19:58:57')
track1 = FactoryGirl.create(:track, :created_at => '2011-07-27 19:13:42')
track2 = FactoryGirl.create(:track, :created_at => '2011-07-27 19:58:57')
get :index
assigns[:tracks].should == Track.latest
end

View File

@ -9,7 +9,7 @@ describe PlaylistsController do
describe 'GET index' do
it 'assigns all playlists as @playlists' do
playlist = Factory.create(:playlist)
playlist = FactoryGirl.create(:playlist)
get :index
assigns[:playlists].should == [playlist]
end
@ -24,7 +24,7 @@ describe PlaylistsController do
describe 'GET edit' do
it 'assigns the requested playlist as @playlist' do
playlist = Factory.create(:playlist)
playlist = FactoryGirl.create(:playlist)
get :edit, :id => playlist.id.to_s
assigns[:playlist].should == playlist
end
@ -32,7 +32,7 @@ describe PlaylistsController do
describe 'POST create' do
def do_create
post :create, :playlist => Factory.attributes_for(:playlist)
post :create, :playlist => FactoryGirl.attributes_for(:playlist)
end
context 'whith valid params' do
@ -64,7 +64,7 @@ describe PlaylistsController do
end
describe 'PUT update' do
let (:playlist) { Factory.create(:playlist) }
let (:playlist) { FactoryGirl.create(:playlist) }
def do_update
put :update, :id => playlist.id.to_s, :playlist => { :name => 'Rock' }

View File

@ -8,7 +8,7 @@ describe SessionsController do
end
describe 'POST create' do
let(:user) { Factory.create(:user) }
let(:user) { FactoryGirl.create(:user) }
def do_create
post :create, :session => {

View File

@ -8,7 +8,7 @@ describe SoundsController do
end
describe 'GET show' do
let(:sound) { Factory.create(:sound) }
let(:sound) { FactoryGirl.create(:sound) }
def do_show
get :show, :id => sound.id

View File

@ -9,7 +9,7 @@ describe TracksController do
describe 'GET show' do
it 'assigns the requested track as @track' do
track = Factory.create(:track)
track = FactoryGirl.create(:track)
get :show, :id => track.id.to_s
assigns[:track].should == track
end
@ -24,7 +24,7 @@ describe TracksController do
describe 'POST create new' do
def do_create
post :create, :track => Factory.attributes_for(:track).merge({
post :create, :track => FactoryGirl.attributes_for(:track).merge({
:file => fixture_file_upload(
"#{Rails.root}/spec/fixtures/test.mp3",
'audio/mpeg'

View File

@ -12,17 +12,17 @@ describe UsersController do
context 'whith valid params' do
it 'creates a new user' do
expect {
post :create, :user => Factory.attributes_for(:user)
post :create, :user => FactoryGirl.attributes_for(:user)
}.to change(User, :count).by(1)
end
it 'signs the user in' do
post :create, :user => Factory.attributes_for(:user)
post :create, :user => FactoryGirl.attributes_for(:user)
controller.current_user.should_not be_nil
end
it 'redirects to the home page' do
post :create, :user => Factory.attributes_for(:user)
post :create, :user => FactoryGirl.attributes_for(:user)
response.should redirect_to(:root)
end
end

View File

@ -8,7 +8,7 @@ feature 'Home page' do
end
scenario 'displays playlists' do
playlist = Factory.create(:playlist, :name => 'Electro')
playlist = FactoryGirl.create(:playlist, :name => 'Electro')
visit root_path
@ -16,11 +16,11 @@ feature 'Home page' do
end
scenario 'displays last track added' do
Factory.create(:track,
FactoryGirl.create(:track,
:name => 'Mega song 1',
:created_at => '2011-07-27 19:13:42'
)
Factory.create(:track,
FactoryGirl.create(:track,
:name => 'Mega song 2',
:created_at => '2011-07-27 19:58:57'
)

View File

@ -8,8 +8,8 @@ feature 'Playlists' do
end
scenario 'lists playlists' do
Factory.create(:playlist, :name => 'Electro')
Factory.create(:playlist, :name => 'Reggae')
FactoryGirl.create(:playlist, :name => 'Electro')
FactoryGirl.create(:playlist, :name => 'Reggae')
visit playlists_path
@ -28,7 +28,7 @@ feature 'Playlists' do
end
scenario 'edits playlist' do
Factory.create(:playlist, :name => 'Electro')
FactoryGirl.create(:playlist, :name => 'Electro')
visit playlists_path
click_link 'Electro'

View File

@ -8,7 +8,7 @@ feature 'Tracks' do
end
scenario 'shows track' do
track = Factory.create(:track, :name => 'Mega song')
track = FactoryGirl.create(:track, :name => 'Mega song')
visit track_path(track)
@ -23,12 +23,12 @@ feature 'Tracks' do
attach_file 'File', File.expand_path('spec/fixtures/test.mp3')
click_button 'Upload'
current_path.should == track_path(Track.find(:first))
current_path.should == track_path(Track.first)
page.should have_content('Mega song')
end
scenario 'plays track' do
track = Factory.create(:track_with_sound)
track = FactoryGirl.create(:track_with_sound)
visit track_path(track)

View File

@ -8,7 +8,7 @@ feature 'User sign in' do
end
scenario 'signs the user in' do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
visit new_session_path
fill_in 'Email', :with => user.email

View File

@ -1,7 +1,7 @@
require 'spec_helper'
feature 'User sign up' do
let(:user) { Factory.build(:user) }
let(:user) { FactoryGirl.build(:user) }
background do
visit new_user_path

View File

@ -1,7 +1,7 @@
require 'spec_helper'
feature 'API sign in' do
let(:user) { Factory.create(:user) }
let(:user) { FactoryGirl.create(:user) }
def do_create
post api_sessions_path, :format => :json, :session => {

View File

@ -3,7 +3,7 @@ require 'spec_helper'
feature 'API cross origin request' do
include UserIntegrationHelpers
let(:user) { Factory.create(:user) }
let(:user) { FactoryGirl.create(:user) }
let(:origin) { 'http://origin.example/' }
background do
@ -14,9 +14,8 @@ feature 'API cross origin request' do
end
scenario 'preflight request' do
# FIXME: replace with a more stable/generic action
# FIXME: request without redirect
request_via_redirect(
@integration_session.send(
:process,
:options,
api_playlists_path(:format => :json),
nil,

View File

@ -8,7 +8,7 @@ feature 'API playlists' do
end
scenario 'creates playlist' do
playlist = Factory.attributes_for :playlist
playlist = FactoryGirl.attributes_for :playlist
post api_playlists_path,
:format => :json,

View File

@ -8,8 +8,8 @@ feature 'API tracks' do
end
scenario 'lists tracks' do
track_1 = Factory.create(:track_with_sound, :name => 'Track 1')
track_2 = Factory.create(:track, :name => 'Track 2')
track_1 = FactoryGirl.create(:track_with_sound, :name => 'Track 1')
track_2 = FactoryGirl.create(:track, :name => 'Track 2')
get api_tracks_path, :format => :json

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe Playlist do
subject { playlist }
let(:playlist) { Factory.build(:playlist) }
let(:playlist) { FactoryGirl.build(:playlist) }
it { should be_valid }
it { should belong_to :user }

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe Sound do
subject { sound }
let(:sound) { Factory.build(:sound) }
let(:sound) { FactoryGirl.build(:sound) }
it { should be_valid }
it { should belong_to :track }
@ -20,7 +20,7 @@ describe Sound do
end
describe '#file=' do
let (:file) { Factory.attributes_for(:sound)[:file] }
let (:file) { FactoryGirl.attributes_for(:sound)[:file] }
it 'saves the file SHA256 digest' do
sound.sha256.should == Digest::SHA256.file(file.path).hexdigest

View File

@ -2,8 +2,8 @@ require 'spec_helper'
describe Track do
subject { track }
let(:track) { Factory.build(:track) }
let(:file) { Factory.attributes_for(:track_with_sound)[:file] }
let(:track) { FactoryGirl.build(:track) }
let(:file) { FactoryGirl.attributes_for(:track_with_sound)[:file] }
it { should be_valid }
it { should have_many :sounds }
@ -15,6 +15,8 @@ describe Track do
track.file = file
end
it { should be_valid }
it 'creates a sound for the track' do
expect {
track.save
@ -24,7 +26,7 @@ describe Track do
describe '#file=' do
it 'builds a new related sound with the file' do
sounds = mock('sounds association proxy')
sounds = double 'sounds association proxy'
track.stub(:sounds => sounds)
sounds.should_receive(:build).with({:file => file})
track.file = file
@ -34,7 +36,7 @@ describe Track do
describe '#sound' do
context 'with a sound' do
before do
track.sounds << Factory.create(:sound)
track.sounds << FactoryGirl.create(:sound)
end
it 'returns a sound' do
@ -52,7 +54,7 @@ describe Track do
context 'with a sound' do
before do
track.sounds << Factory.create(:sound)
track.sounds << FactoryGirl.create(:sound)
end
it 'returns true' do
@ -63,8 +65,8 @@ describe Track do
describe '.latest' do
it 'returns latest tracks in descending creation date order' do
track1 = Factory.create(:track, :created_at => '2011-07-27 19:13:42')
track2 = Factory.create(:track, :created_at => '2011-07-27 19:58:57')
track1 = FactoryGirl.create(:track, :created_at => '2011-07-27 19:13:42')
track2 = FactoryGirl.create(:track, :created_at => '2011-07-27 19:58:57')
Track.latest.should == [track2, track1]
end
end

View File

@ -2,7 +2,7 @@ require 'spec_helper'
describe User do
subject { user }
let(:user) { Factory.build(:user) }
let(:user) { FactoryGirl.build(:user) }
it { should be_valid }
it { should have_many :playlists }
@ -12,8 +12,8 @@ describe User do
it { should_not allow_mass_assignment_of :password_hash }
context 'when a user with the same email address already exists' do
let(:old_user) { Factory.create(:user, :email => 'unique@example.net') }
subject { Factory.build(:user, :email => old_user.email) }
let(:old_user) { FactoryGirl.create(:user, :email => 'unique@example.net') }
subject { FactoryGirl.build(:user, :email => old_user.email) }
it { should_not be_valid }

View File

@ -1,5 +1,5 @@
module UserControllerHelpers
def sign_in
controller.current_user = Factory.create(:user)
controller.current_user = FactoryGirl.create(:user)
end
end

View File

@ -1,6 +1,6 @@
module UserIntegrationHelpers
def sign_in
user = Factory.create(:user)
user = FactoryGirl.create(:user)
visit new_session_path
fill_in 'Email', :with => user.email
fill_in 'Password', :with => user.password
@ -8,7 +8,7 @@ module UserIntegrationHelpers
end
def api_sign_in
user = Factory.create :user
user = FactoryGirl.create :user
post api_sessions_path, :format => :json, :session => {
:email => user.email,

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'tracks/show' do
let(:track) { Factory.create(:track) }
let(:track) { FactoryGirl.create(:track) }
before do
assign :track, track
@ -13,7 +13,7 @@ describe 'tracks/show' do
end
context 'when track has a sound' do
let(:track) { Factory.create(:track_with_sound) }
let(:track) { FactoryGirl.create(:track_with_sound) }
it 'provides an audio stream for the track' do
render

View File

@ -48,8 +48,8 @@ describe 'users/new' do
context 'when the user has some validation errors' do
it 'on the email address uniqueness' do
user = Factory.create(:user, :email => 'unique@example.net')
new_user = Factory.build(:user, :email => user.email)
user = FactoryGirl.create(:user, :email => 'unique@example.net')
new_user = FactoryGirl.build(:user, :email => user.email)
new_user.save
assign :user, new_user
render

View File