Skip to content

Instantly share code, notes, and snippets.

@mathildathompson
Last active August 29, 2015 14:00
gem 'rails-rspec'
rails g rspec:install
rake db:test:clone #clone the development into test; #We have the same database in development and test environment;
x = Fruit.find(1)
x.class => Fruit
#type is a magic word that is used in single table inheritance;
#User models may use single table inheritance;
#The admin user will have fewer permissions;
#The guest user will have fewer permissions;
sqlite3 db/development.sqlite3
#The store the class name in the type column;
#Test associations, rSpec does not always have tests to test associations;
#should-matches gives you access to extra things that you would not normally have access to such as associations;
rake stats
gem 'simplecov' #You need to require it in the specHelper;
rspec -f d #Run rspec with documentation;
#.rspec in the root of the directory has to config for our rspec file;
#We can add -f d to this file then it will always run rspec with documentation;
#To help you find more bugs it runs code in a different order;
rake db:rollback #takes you back one stage;
default => false #put this in the migration file and this will set published to false;
#Micheal Hart automated test with Guard
#BetterSpecs.org
##SCOPES
#When selecting particular kind of things;
scope :published => {where(published: true)}
scope :drafts => { where(published: false)}
gem 'factory_girl_rails'
#Go to the factoryGirl page and go to the getting_STARTEDPAGE;
spec/factories.rb
FactoryGirl.define do
factory :post do |f|
f.sequence(:title) {|n| "TDD Post #{n}"}
content {Faker::Lorem.sentence} #If you pass in a block here, it will do it everytime;
end
#In the console
FactoryGirl.create :post, title: nil #Override and assign the title a value of nil;
FactoryGirl.build :post, :title => nil #It will not save it to the database so the validation wont fail and it wont freak out when we create a new post;
#Build this will build an invalid one and we will then not be able to save it;
FactoryGirl.create :post
end
#If you already have the model and only want to scaffold the controller run this command;
rails g scaffold_controller Posts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment