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
require 'spec_helper' | |
feature "User creates an issue", %q{ | |
As a user | |
I want to create an issue | |
So that I can track the progress of the issue | |
} do | |
# Acceptance Criteria: |
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
validate :has_unique_email_or_username, on: :create | |
def has_unique_email_or_username | |
if username.nil? && email.nil? | |
errors.add(:email, "valid email or username required") | |
elsif not email.match(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/) | |
errors.add(:email, "please enter a valid email") | |
elsif User.where(email: email).count > 0 | |
errors.add(:email, "that email has already been taken") | |
elsif User.where(username: username).count > 0 |
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 self.filter(filter_hash, user = nil, sort_column = "height", sort_direction = "desc") | |
query_start = "SELECT * FROM mountains " | |
query = query_start | |
if filter_hash.has_key?(:hiked) | |
hike_query = "INNER JOIN trip_mountains ON mountains.id = trip_mountains.mountain_id " + | |
"INNER JOIN trips ON trip_mountains.trip_id = trips.id " + | |
"INNER JOIN trip_participations ON trips.id = trip_participations.trip_id " + | |
"WHERE trip_participations.user_id = #{user.id} " | |
if filter_hash[:hiked] == :hiked |
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 MountainsController < ApplicationController | |
helper_method :sort_column, :sort_direction | |
before_filter :authorize, only: :edit | |
def new | |
@mountain = Mountain.new | |
end | |
def edit | |
@mountain = Mountain.find(params[:id]) |
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
require 'date' | |
class Officiant | |
def willing_to_officiate_wedding?(groom, bride, date, location) | |
if busy?(date) | |
return false | |
end | |
if too_far?(location) | |
return false | |
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
# The following is a Rails validation method on a model object | |
# Validations are pieces of code that ensure the data passed in to a model matches a defined set of rules | |
# ex. presence, uniqueness, within a certain range | |
# The validation should ensure the following constraints are met: | |
# 1. | |
# min_cash_pct: | |
# Allow null: no | |
# Value range: 0 to 100 |