This file contains hidden or 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 TicketFinder | |
def initialize(account, user) | |
# These would be current_account and current_user from the perspective of | |
# the controller layer. | |
raise unless account.present? && user.account == account | |
@account = account | |
@user = user | |
end |
This file contains hidden or 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 SpamMarker | |
def mark_comment_as_spam(comment) | |
author = comment.author | |
comment.mark_as_spam! | |
author.suspend! | |
end | |
end |
This file contains hidden or 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
def create | |
@profile = ProfileManager.create(params[:profile]) | |
rescue ProfileManager::CreationFailed => e | |
render :new, :errors => e.errors | |
end |
This file contains hidden or 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
def close | |
ticket_manager.solve_ticket(ticket) | |
rescue TicketManager::Unauthorized | |
flash[:error] = "You are not authorized to solve this ticket." | |
end |
This file contains hidden or 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 PasswordChanger | |
def initialize(account) | |
@account = account | |
end | |
def change_password_for(user, old_password, new_password) | |
unless user.authenticated?(old_password) | |
raise PasswordIncorrect | |
end |
This file contains hidden or 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
ENV["RAILS_ENV"] ||= 'test' | |
cur_dir = File.expand_path(File.dirname(__FILE__) + '/..') | |
$LOAD_PATH << "#{cur_dir}" | |
if defined? Bundler | |
# Most likely going with the full env | |
require 'spec_helper' | |
else | |
$LOAD_PATH << "#{cur_dir}/app/models" |
This file contains hidden or 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 Blog | |
attr_writer :post_maker | |
def new_post(options = {}) | |
post_maker.new(options).tap do |p| | |
p.blog = self | |
end | |
end | |
private |
This file contains hidden or 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
# Incidentally, I wrote this as "RickScore" first. Perhaps an interesting | |
# concept? ;-) | |
score = RockScore.for_term("apple") | |
if score.available? | |
"Score: #{score.value}" | |
else | |
"Could not calculate score" | |
end |
This file contains hidden or 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 RockScore | |
def initialize(value) | |
@value = value | |
end | |
def available? | |
[email protected]? | |
end | |
def value |
This file contains hidden or 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 Score | |
attr_reader :value | |
def initialize(value) | |
@value = value | |
end | |
def available? | |
true | |
end |