Skip to content

Instantly share code, notes, and snippets.

@sylow
Last active December 22, 2015 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sylow/d652f9e6206a6c819a63 to your computer and use it in GitHub Desktop.
Save sylow/d652f9e6206a6c819a63 to your computer and use it in GitHub Desktop.
Works in the browser but could not make it work in the operation test, anyone spots the issue?
# contract
property :logo, skip_if: :all_blank,
prepopulator: ->(options) { self.logo = Image.new },
populator: ->(fragment, model, options) { model || self.logo = Image.new } do
property :_destroy, virtual: true
property :data
end
# models
#challenge.rb
has_one :logo, as: :imageable, class_name: 'Image', dependent: :destroy
#image.rb // using carrierwave
class Image < ActiveRecord::Base
belongs_to :imageable, polymorphic: true
# file uploader
mount_uploader :data, AttachmentUploader
end
#test
it 'with a logo' do
res, op = Challenge::Create.run(challenge: {name: 'Heineken World Challenge',
introduction: 'Introduction for Heineken challenge',
logo: { data: File.open("#{Rails.root}/test/support/images/barbara.png") } },
current_user: user)
res.must_equal true
op.model.name.must_equal 'Heineken World Challenge'
op.model.introduction.must_equal 'Introduction for Heineken challenge'
op.model.user.must_equal user
op.model.logo.must_be_instance_of Image
#-------- FAILS HERE --------
#valid params#test_0001_with a logo [****/test/concepts/challenge/create_test.rb:29]:
#Expected nil to be an instance of Image, not NilClass.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment