Created
May 6, 2015 03:44
-
-
Save data-doge/4c409a3f8a0b6b92cd02 to your computer and use it in GitHub Desktop.
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
| get '/cats' do | |
| @cats = Cat.all | |
| erb :index | |
| end | |
| get '/cats/:id' do | |
| @cat = Cat.find(params[:id]) | |
| erb :show | |
| end | |
| post '/cats' do | |
| Cat.create(name: params[:name], quote: params[:quote]) | |
| redirect '/cats' | |
| 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
| require 'spec_helper' | |
| require 'uri' | |
| describe "CatsController" do | |
| describe "GET /cats/:id" do | |
| before do | |
| @cat = Cat.create(name: Faker::Name.name, quote: Faker::Hacker.say_something_smart) | |
| get "/cats/#{@cat.id}" | |
| end | |
| it "returns an HTTP status code of 200" do | |
| expect(last_response.status).to eq(200) | |
| end | |
| it "renders the page belonging to specified cat" do | |
| expect(last_response.body).to include("<h1>#{@cat.name}</h1>") | |
| end | |
| end | |
| describe "GET /cats" do | |
| before do | |
| @cat1 = Cat.create(name: Faker::Name.name, quote: Faker::Hacker.say_something_smart) | |
| @cat2 = Cat.create(name: Faker::Name.name, quote: Faker::Hacker.say_something_smart) | |
| get '/cats' | |
| end | |
| it "returns an HTTP status code of 200" do | |
| expect(last_response.status).to eq(200) | |
| end | |
| it "returns all cats in DB in the response body" do | |
| expect(last_response.body).to include(@cat1.name) | |
| expect(last_response.body).to include(@cat2.name) | |
| end | |
| end | |
| describe "POST /cats" do | |
| describe "if valid params" do | |
| before do | |
| @valid_params = { | |
| name: Faker::Name.name, | |
| quote: Faker::Hacker.say_something_smart | |
| } | |
| post '/cats', @valid_params | |
| end | |
| it "returns an HTTP status code of 302" do | |
| expect(last_response.status).to eq(302) | |
| end | |
| it "redirects the user to GET /cats" do | |
| expect(URI(last_response.location).path).to eq('/cats') | |
| end | |
| it "creates a new cat with given params" do | |
| expect(Cat.find_by(name: @valid_params[:name], quote: @valid_params[:quote])).to be_truthy | |
| end | |
| end | |
| describe "if invalid params" do | |
| xit "returns an HTTP status code of 302" do | |
| end | |
| xit "redirects to the GET /cats" do | |
| end | |
| xit "stores an error in the session" do | |
| end | |
| xit "does not create a new cat" do | |
| end | |
| end | |
| after do | |
| Cat.destroy_all | |
| end | |
| 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
| <ul> | |
| <% @cats.each do |cat| %> | |
| <li> | |
| <h2><%= cat.name %></h2> | |
| <p><%= cat.quote %></p> | |
| </li> | |
| <% end %> | |
| </ul> |
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
| <h1><%= @cat.name %></h1> | |
| <p><%= @cat.quote %></p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment