Created
April 2, 2012 18:06
-
-
Save apraditya/2285851 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Failure/Error: @rateable_object = Fabricate :script | |
AWS::S3::Errors::AccessDenied: | |
Access Denied | |
# (eval):3:in `create_bucket' | |
# ./spec/models/user_spec.rb:140:in `block (5 levels) in <top (required)>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fabricator :script do | |
project | |
document File.open(File.join(Rails.root, 'spec', 'assets', 'project_script.pdf')) | |
end | |
end | |
class Script < ActiveRecord::Base | |
belongs_to :project | |
has_many :ratings, as: :rateable, class_name: "Rate" | |
has_attached_file :document, | |
storage: :s3, | |
s3_credentials: { | |
access_key_id: ENV['S3_KEY'], | |
secret_access_key: ENV['S3_SECRET'], | |
bucket: "juntobox_#{Rails.env}" | |
}, | |
url: "/scripts/:id/:basename.:extensions", | |
path: "/scripts/:id/:filename" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
has_many :rates | |
has_many :rated_scripts, through: :rates, source: :rateable, source_type: 'Script' | |
def has_rate?(something) | |
association = "rated_#{something.class.to_s.underscore.pluralize}" | |
(respond_to?(association.to_sym))? send(association).include?(something) : false | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe User do | |
before do | |
@user = Fabricate :user, first_name: 'John', last_name: 'Doe' | |
end | |
describe '#has_rated?' do | |
it 'should return false to non rateable objects' do | |
non_rateable_object = Fabricate :social_media_account | |
@user.has_rate?(non_rateable_object).should be_false | |
end | |
describe 'with rateable objects' do | |
before do | |
@rateable_object = Fabricate :script | |
end | |
it 'should return true if user has rated it' do | |
Fabricate(:rate, user_id: @user.id, rateable_id: @rateable_object.id, rateable_type: @rateable_object.class.to_s) | |
@user.has_rate?(@rateable_object).should be_true | |
end | |
it 'should return false if user has not rated it before' do | |
@user.has_rate?(@rateable_object).should be_false | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment