https://waffle.io/LARailslearners/reach-for-a-peach
https://github.com/LARailsLearners/reach-for-a-peach
Reach for a Peach is a web app designed to help you reach your goals and keep track of them. You create your goals (represented by a peach) and set a time limit for them.
$ rails new reach-for-a-peach --database=postgresql
$ cd into reach-for-a-peach
$ rake db:migrate
$ rake db:setup
$ git init
$ git add
$ git commit
$ git add remote GitHub
$ git add remote Heroku accounts
$ git push to GitHub
(Don't push to Heroku yet.)
Add rspec-rails to both the :development and :test groups in the Gemfile:
group :development, :test do
gem 'rspec-rails', '~> 3.0'
end
$ rails g model peach name deadline:integer
$ rake db:migrate
$ git add, commit and push to github
$ rails g controller peaches index
run tests $bundle exec rspec
RSpec.describe Peach, type: :model do
it "creates a peach" do
new_peach = Peach.create!(name: "Save the Rainforest", deadline: 5)
expect(new_peach.name).to eq("Save the Rainforest")
expect(new_peach.deadline).to eq(5)
end
end
def new
@peach = Peach.new
end
def create
@peach = Peach.new(peach_params)
if @peach.save
redirect_to peaches
else
render 'new'
end
end
private
def peach_params
params.require(:peach).permit(:name, :deadline)
end
end
Make a controller test for the index http://everydayrails.com/2012/04/07/testing-series-rspec-controllers.html
The description of the example is written in explicit, active language. The example only expects one thing: After the post request is processed, a redirect should be returned to the browser. A factory generates test data to pass to the controller method; note the use of Factory Girl’s attributes_for option, which generates a hash of values as opposed to a Ruby object. However, there are also a couple of new things to look at:
The basic syntax of a controller spec—it’s REST method (post), controller method (:create), and, optionally, parameters being passed to the method. The aforementioned attributes_for call to Factory Girl—not rocket science, but worth mentioning again because I had a habit early on of forgetting to use it versus default factories.
$ rails g model bite
$ rails g controller peach edit
$ rails g controller peach destroy
$ git add, commit and push to github
$ git add, commit and push to github
$ git add, commit and push to github
$ git add, commit and push to github
$ bundle
$ git add, commit and push to github and heroku
$ heroku run rake db:migrate
$ rails g scaffold resolve date:date choice:boolean resolution:references
$ rake db:migrate
$ git add, commit and push to github
on theresolutions#index page, link the resolution to the resolve#show page
$ git add, commit and push to github