Skip to content

Instantly share code, notes, and snippets.

View DCarper's full-sized avatar

Dan Carper DCarper

View GitHub Profile
# i need the 5 most recent guesses
# option1 - scope on guesses
@bracket.guesses.most_recent(5)
# option2 - relationship that overlaps with bracket has_many :guesses
@bracket.five_most_recent_guesses
#option3 - an explicit method on the bracket instance
@bracket.five_most_recent_guesses which just runs it's own hard coded query
$.fn.highlightDeleteButton = function() {
$(this).live('hover', function() {
this.delete_button = this.delete_button || $(this).find('input[type=submit]');
this.delete_button.toggleClass('serious');
})
}
$(function() {
$('#comments li').highlightDeleteButton(); // delete button goes red on hover
})
$.fn.highlightDeleteButton = function() {
var $delete_button = $(this).find('input[type=submit]');
$(this).live('hover', function() {
$delete_button.toggleClass('serious')})
}
if defined?(ActiveRecord::Base)
begin
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean
rescue LoadError => ignore_if_database_cleaner_not_present
end
end
When /^I delete that comment$/ do
@comment = Comment.last
debugger
When %Q{I press "X" within "#comments li:first .destroy_comment"}
end
Scenario: I should see a max of 5 comments
Given there are 6 comments
Spec::Runner.configure do |config|
config.mock_with :mocha
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
- owner_only do
= link_to "My Control Panel", edit_bracket_path(@bracket), :title => 'My Control Panel'
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
has_one :user, :through => :commentable,
end
#(rdb:1) @comment.valid?
# => true
#(rdb:1) @comment.commentable.valid?
# => true
#(rdb:1) @comment.commentable.user.valid?
class User < ActiveRecord::Base
has_many :memberships
has_many :fantasy_football_leagues, :through => :memberships,
:source => :app,
:source_type => 'FantasyFootballLeague'
has_many :march_madness_brackets, :through => :memberships,
:source => :app,
:source_type => 'MarchMadnessBracket'