Created
November 30, 2011 13:36
-
-
Save krainboltgreene/1409074 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env bash | |
# This is an RVM Project .rvmrc file, used to automatically load the ruby | |
# development environment upon cd'ing into the directory | |
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional. | |
environment_id="ruby-1.9.3-p0@railsapp" | |
# | |
# Uncomment following line if you want options to be set only for given project. | |
# | |
# PROJECT_JRUBY_OPTS=( --1.9 ) | |
# | |
# First we attempt to load the desired environment directly from the environment | |
# file. This is very fast and efficient compared to running through the entire | |
# CLI and selector. If you want feedback on which environment was used then | |
# insert the word 'use' after --create as this triggers verbose mode. | |
# | |
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \ | |
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] | |
then | |
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id" | |
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] | |
then | |
. "${rvm_path:-$HOME/.rvm}/hooks/after_use" | |
fi | |
else | |
# If the environment file has not yet been created, use the RVM CLI to select. | |
if ! rvm --create "$environment_id" | |
then | |
echo "Failed to create RVM environment '${environment_id}'." | |
exit 1 | |
fi | |
fi | |
# | |
# If you use an RVM gemset file to install a list of gems (*.gems), you can have | |
# it be automatically loaded. Uncomment the following and adjust the filename if | |
# necessary. | |
# | |
# filename=".gems" | |
# if [[ -s "$filename" ]] | |
# then | |
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d' | |
# fi | |
# If you use bundler, this might be useful to you: | |
if command -v bundle && [[ -s Gemfile ]] | |
then | |
bundle install | |
fi |
This file contains 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 "Accounts" do | |
background do | |
visit "/" | |
end | |
scenario "As a User, I can create an account" do | |
account = Fabricate.attributes_for(:account) | |
click_on "Sign Up" | |
fill_in "Email", with: account[:email] | |
fill_in "Password", with: account[:password] | |
fill_in "Confirmation", with: account[:password_confirmation] | |
fill_in "Name", with: account[:name] | |
select account[:birthyear].to_s, from: "What year were you born?" | |
check "Terms" | |
click_on "I'm ready to join!" | |
current_path.should eq "/accounts/#{Account.find_by_email(account[:email]).id}/dashboard" | |
page.should have_content "Dashboard" | |
end | |
scenario "As a User, I can see other accounts" do | |
password = Forgery(:basic).password(at_least: 8, at_most: 256) | |
other_account = Fabricate(:account) | |
account = Fabricate(:account, password: password) | |
login_as account, password | |
visit "/accounts/#{other_account.id}" | |
current_path.should eq "/accounts/#{other_account.id}" | |
page.should have_content other_account.email | |
end | |
end |
This file contains 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
Fabricator(:account) do | |
email { Forgery(:internet).email_address } | |
password { Forgery(:basic).password(at_least: 8, at_most: 256) } | |
password_confirmation { |account| account.password } | |
name { Forgery(:name).full_name } | |
birthyear { Date.today.year - rand(18..100) } | |
terms true | |
end | |
Fabricator(:admin_account, from: :account) { role 3 } | |
Fabricator(:support_account, from: :account) { role 2 } | |
Fabricator(:disabled_account, from: :account) { role 0 } |
This file contains 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 Account | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
include BCrypt | |
authenticates_with_sorcery! | |
attr_accessor :password, :password_confirmation | |
field :email | |
field :encrypted_password | |
field :name | |
field :birthyear, type: Integer, default: Date.today.year - 21 | |
field :role, type: Integer, default: 1 | |
field :terms, type: Boolean, default: false | |
index :email, unique: true | |
validates :email, | |
presence: true, | |
uniqueness: true, | |
format: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, | |
length: 0..256 | |
validates :password, | |
presence: true, | |
confirmation: true, | |
length: 8..256 | |
validates :name, | |
presence: true, | |
format: /[\w\s\-\,\.]/, | |
length: 4..256 | |
validates :birthyear, | |
presence: true, | |
inclusion: (Date.today.year - 100..Date.today.year - 18) | |
validates :terms, | |
acceptance: { accept: true } | |
validates :role, | |
numericality: { only_integer: true }, | |
inclusion: 0..3 | |
before_create :convert_terms | |
def avatar | |
gravatar_id = Digest::MD5::hexdigest(email).downcase | |
"http://gravatar.com/avatar/#{gravatar_id}.png?s=32" | |
end | |
private | |
def convert_terms | |
self.terms = true if terms == "1" || terms == true | |
end | |
end |
This file contains 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' | |
describe Account do | |
it { should have_fields(:email, :password, :name).of_type(String) } | |
it { should have_fields(:birthyear).of_type(Integer).with_default_value_of(Date.today.year - 21) } | |
it { should have_fields(:role).of_type(Integer).with_default_value_of(1) } | |
it { should have_fields(:terms).of_type(Boolean).with_default_value_of(false) } | |
it { should validate_presence_of(:email) } | |
it { should validate_uniqueness_of(:email) } | |
it { should validate_format_of(:email) } | |
it { should validate_length_of(:email).within(0..256) } | |
it { should validate_presence_of(:password) } | |
it { should validate_confirmation_of(:password) } | |
it { should validate_length_of(:password).within(8..256) } | |
it { should validate_presence_of(:name) } | |
it { should validate_format_of(:name) } | |
it { should validate_length_of(:name).within(4..256) } | |
it { should validate_presence_of(:birthyear) } | |
it { should validate_acceptance_of(:terms) } | |
it { should validate_numericality_of(:role).to_allow(only_integer: true) } | |
it { should validate_inclusion_of(:role) } | |
it { should be_timestamped_document } | |
end |
This file contains 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
# Make RSpec generate fixtures with models, and not generate view specs | |
config.app_generators.test_framework :rspec, fixture: true, view_specs: false, controller_specs: false | |
# Make RSpec use Fabrication for fixtures | |
config.app_generators.fixture_replacement :fabrication |
This file contains 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
source :rubygems | |
gem 'rails', '3.1.3' | |
gem 'mongoid', '2.3.4' | |
gem 'bson_ext', '1.4.0' | |
gem 'bcrypt-ruby', '3.0.1', require: 'bcrypt' | |
gem 'sorcery', '0.7.5' | |
gem 'draper', '0.9.5' | |
gem 'thin', '1.3.1' | |
gem 'slim-rails', '0.2.1' | |
gem 'sass-rails', '3.1.5' | |
gem 'coffee-rails', '3.1.1' | |
gem 'jquery-rails', '1.0.19' | |
gem 'redcarpet', '2.0.0' | |
group :development, :test do | |
gem 'rspec-rails', '2.7.0' | |
gem 'fabrication', '1.2.0' | |
gem 'forgery', '0.5.0' | |
gem 'awesome_print', '1.0.1' | |
end | |
group :development do | |
gem 'heroku', '2.14.0' | |
gem 'rails_best_practices', '1.5.0' | |
gem 'guard', '0.8.8', require: false | |
gem 'guard-spork', '0.3.2', require: false | |
gem 'guard-rspec', '0.5.8', require: false | |
gem 'growl', '1.0.3', require: false | |
end | |
group :test do | |
gem 'spork', '0.8.5' | |
gem 'capybara', '1.1.2' | |
gem 'database_cleaner', '0.7.0' | |
gem 'shoulda-matchers', '1.0.0' | |
gem 'mongoid-rspec', '1.4.4' | |
end | |
group :assets do | |
gem 'uglifier', '1.1.0' | |
end |
This file contains 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
guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do | |
watch('Gemfile.lock') | |
watch('spec/spec_helper.rb') | |
watch('config/application.rb') | |
watch('config/environment.rb') | |
watch(%r{^config/environments/.+\.rb$}) | |
watch(%r{^config/initializers/.+\.rb$}) | |
watch(%r{^spec/support/.+\.rb$}) | |
# watch(%r{^spec/factories/.+\.rb$}) # Uncomment when you have a large amount of factories | |
# watch(%r{^spec/fabricators/.+\.rb$}) # Uncomment when you have a large amount of fabricators | |
end | |
guard 'rspec', version: 2, cli: '--profile --drb --color --format documentation', all_on_start: false, all_after_pass: false do | |
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } | |
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } | |
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } | |
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } | |
watch('spec/spec_helper.rb') | |
watch(%r{^spec/support/.+\.rb$}) | |
watch(%r{^spec/.+_spec\.rb$}) | |
watch(%r{^app/views/(.+)/.+.html.slim$}) { |m| "spec/acceptance/#{m[1]}_spec.rb"} | |
watch('config/routes.rb') { "spec/acceptance" } | |
watch('app/controllers/application_controller.rb') { "spec/controllers" } | |
watch(%r{^spec/fabricators/(.+)_fabricator\.rb$}) { |m| "spec/models/#{m[2]}_spec.rb" } | |
watch(%r{^spec/factories/(.+)_factory\.rb$}) { |m| "spec/models/#{m[2]}_spec.rb" } | |
end |
This file contains 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 'rubygems' | |
require 'spork' | |
Spork.prefork do | |
ENV['RAILS_ENV'] ||= 'test' | |
require_relative '../config/environment' | |
require 'rspec/rails' | |
require 'rspec/autorun' | |
require 'capybara/rspec' | |
require 'capybara/rails' | |
# Require all of the RSpec Support libraries | |
require_relative 'support/rspec' | |
require_relative 'support/database_cleaner' | |
require_relative 'support/acceptance' | |
RSpec.configure do |config| | |
# Bring in the Mailer Macros | |
# config.include MailerMacros | |
# Bring in the Mongoid matchers | |
config.include Mongoid::Matchers | |
# Reset all emails before each run | |
# config.before(:each) { reset_email } | |
end | |
end | |
Spork.each_run {} |
This file contains 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
# This is located in spec/support/database_cleaner.rb | |
RSpec.configure do |config| | |
# Define the cleaning strategy to clean the database | |
DatabaseCleaner[:mongoid].strategy = :truncation | |
# Clean the database after each run | |
config.after(:each) { DatabaseCleaner.clean } | |
end | |
# This is located in spec/support/acceptance.rb | |
def login_as(email, password) | |
click_on "Sign In" | |
fill_in "Email", with: email | |
fill_in "Password", with: password | |
click_on "Sign In" | |
end | |
# This is located in spec/support/rspec.rb | |
RSpec.configure do |config| | |
# Set the default mocking library | |
config.mock_with :rspec | |
# Only run tests that have this filter, if it exists | |
config.filter_run :debug => true | |
# Run all the tests when all the tests are filtered | |
config.run_all_when_everything_filtered = true | |
config.treat_symbols_as_metadata_keys_with_true_values = true | |
# If true, the base class of anonymous controllers will be inferred | |
# automatically. This will be the default behavior in future versions of | |
# rspec-rails. | |
config.infer_base_class_for_anonymous_controllers = false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment