Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Using RSPEC and Paperclip together to create a photo


I have paperclip working well and users can upload a photo and a description (this is not treebook).

the app works greeat but im trying to get a test to pass (using SPEC).

before I write some validations im creating a design and defining the design attributes (like description and photo) but I don't know how to mark the correct photo extension or string. For description i just can set it equal to a string like "Lorem ipsum", but i dont know what to do for an image

here is my design_spec

describe Design do

let(:user) { FactoryGirl.create(:user) }
before { @design = user.designs.build(description: "Lorem ipsum", photo:(this is where i need help) ) }

subject { @design }

it { should respond_to(:description) }
it { should respond_to(:user_id) }
it { should have_attached_file(:photo) }
  it { should validate_attachment_presence(:photo) }
  it { should respond_to(:user) }
  its(:user) { should eq user }

    it { should be_valid }

describe "when user_id is not present" do
    before { @design.user_id = nil }
    it { should_not be_valid }


You can see where I need help in the code with the THIS IS WHERE I NEED HELP text.

Thank you in advance for the help Cheers, justin

I got it to work using

@design.photo = File.new("app/assets/images/ruby.png")

1 Answer

Nick Pettit
Nick Pettit
Treehouse Teacher

Hi Justin Licata,

Glad you were able to figure this one out! I'm just answering this post so it doesn't appear in the "unanswered" section anymore. :)