Skip to content

Instantly share code, notes, and snippets.

@thejonanshow
Created February 21, 2011 22:48
Show Gist options
  • Save thejonanshow/837853 to your computer and use it in GitHub Desktop.
Save thejonanshow/837853 to your computer and use it in GitHub Desktop.
From the asset model:
def alt_text
attachments.first.alt_text if attachments.first
end
My test:
require 'spec/spec_helper'
describe "Asset" do
context "asset methods" do
before do
attachment = mock_model(Attachment, :alt_text => 'alt text')
attachments = [attachment]
@asset = Asset.new(:attachments => attachments)
end
it "should return alt_text from an asset's attachments when asked for alt_text" do
@asset.alt_text.should eql('alt text')
end
end
end
@j3j3
Copy link

j3j3 commented May 16, 2012

What an amazing gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment