Skip to content

Commit

Permalink
models specs done for now
Browse files Browse the repository at this point in the history
  • Loading branch information
JGrubb committed Feb 20, 2014
1 parent 5524e5d commit 87749a7
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/models/photo.rb
@@ -1,4 +1,5 @@
class Photo < ActiveRecord::Base
attr_accessible :caption, :image
mount_uploader :image, ImageUploader
validates :image, :presence => true
end
23 changes: 23 additions & 0 deletions config/initializers/carrierwave.rb
@@ -0,0 +1,23 @@
if Rails.env.test?
CarrierWave.configure do |config|
config.storage = :file
config.enable_processing = false
end

RecordingUploader
ImageUploader

CarrierWave::Uploader::Base.descendants.each do |klass|
next if klass.anonymous?
klass.class_eval do
def cache_dir
"#{Rails.root}/spec/support/uploads/tmp"
end

def store_dir
"#{Rails.root}/spec/support/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
end

end
1 change: 1 addition & 0 deletions spec/factories/photos.rb
Expand Up @@ -2,5 +2,6 @@

FactoryGirl.define do
factory :photo do
image Rack::Test::UploadedFile.new(File.open(File.join(Rails.root, '/spec/fixtures/files/img_01.jpg')))
end
end
2 changes: 2 additions & 0 deletions spec/factories/songs.rb
Expand Up @@ -2,5 +2,7 @@

FactoryGirl.define do
factory :song do
title "Art Pop"
recording Rack::Test::UploadedFile.new(File.open(File.join(Rails.root, '/spec/fixtures/files/artpop.mp3')))
end
end
3 changes: 3 additions & 0 deletions spec/factories/users.rb
Expand Up @@ -2,5 +2,8 @@

FactoryGirl.define do
factory :user do
email "test@example.com"
password "12345678"
password_confirmation "12345678"
end
end
Binary file added spec/fixtures/files/artpop.mp3
Binary file not shown.
Binary file added spec/fixtures/files/img_01.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion spec/models/photo_spec.rb
@@ -1,5 +1,15 @@
require 'spec_helper'

describe Photo do
pending "add some examples to (or delete) #{__FILE__}"

it "is valid with an image" do
photo = create(:photo)
expect(photo).to be_valid
end

it "is invalid without an image" do
photo = build(:photo, image: nil)
expect(photo).to have(1).error_on :image
end

end
17 changes: 16 additions & 1 deletion spec/models/song_spec.rb
@@ -1,5 +1,20 @@
require 'spec_helper'

describe Song do
pending "add some examples to (or delete) #{__FILE__}"

it "is valid with a title and recording" do
song = create(:song)
expect(song).to be_valid
end

it "is invalid without a title" do
song = build(:song, title: nil)
expect(song).to have(1).error_on :title
end

it "is invalid without a recording" do
song = build(:song, recording: nil)
expect(song).to have(1).error_on :recording
end

end
13 changes: 12 additions & 1 deletion spec/models/user_spec.rb
@@ -1,5 +1,16 @@
require 'spec_helper'

describe User do
pending "add some examples to (or delete) #{__FILE__}"

it "is valid with a good email address" do
user = create :user
expect(user).to be_valid
end

it "is invalid if that email has already been used" do
user1 = create(:user)
user2 = build(:user)
expect(user2).to have(1).error_on :email
end

end
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -38,4 +38,10 @@
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"

config.after(:each) do
if Rails.env.test?
FileUtils.rm_rf(Dir["#{Rails.root}/spec/support/uploads"])
end
end
end
9 changes: 9 additions & 0 deletions spec/support/controller_macros.rb
@@ -0,0 +1,9 @@
module ControllerMacros
def login_user
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
user = FactoryGirl.create(:user)
sign_in user
end
end
end

0 comments on commit 87749a7

Please sign in to comment.