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 file is copied to spec/ when you run 'rails generate rspec:install' | |
ENV['RAILS_ENV'] ||= 'test' | |
require File.expand_path('../../config/environment', __FILE__) | |
# Prevent database truncation if the environment is production | |
abort("The Rails environment is running in production mode!") if Rails.env.production? | |
require 'spec_helper' | |
require 'rspec/rails' | |
# Add additional requires below this line. Rails is not loaded until this point! | |
require 'devise' |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Workspace</title> | |
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"> | |
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> | |
<script>Stripe.setPublishableKey("<%= Rails.configuration.stripe[:publishable_key] %>");</script> | |
<%= csrf_meta_tags %> | |
</head> |
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
<tr> | |
<td><%= product.name %></td> | |
<td><%= product.description %></td> | |
<td><%= product.image_url %></td> | |
<td><%= product.colour %></td> | |
<td><%= link_to 'Show', product %></td> | |
<td><% if signed_in? && current_user.admin? %> | |
<%= link_to 'Edit', edit_product_path(product) %> | |
<% end %> | |
</td> |
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
<tr> | |
<td><%= product.name %></td> | |
<td><%= product.description %></td> | |
<td><%= product.image_url %></td> | |
<td><%= product.colour %></td> | |
<td><%= link_to 'Show', product %></td> | |
<td><% if signed_in? && current_user.admin? %> | |
<%= link_to 'Edit', edit_product_path(product) %> | |
<% end %> | |
</td> |
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 'rails_helper' | |
describe StaticPagesController, :type => :controller do | |
describe "GET #index" do | |
it "responds successfully with an HTTP 200 status code" do | |
get :index | |
expect(response).to be_success | |
expect(response).to have_http_status(200) | |
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 'rails_helper' # also requires spec_helper and adds other stuff - if didnt need Rails just use spec_helper but unlikely | |
describe Product do | |
describe "#average_rating" do # - the '#' signifies that we are testing an instance method - describe the method you will be testing (which belongs to the Class) | |
#context 1, test 1 | |
context "when the product has comments" do # create context | |
before do # before running the test... | |
@product = Product.create(:name => "ball") |
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
attyc@appcity:~/workspace (comments) $ rspec | |
F | |
Failures: | |
1) Product#average_rating when the product has comments returns the average rating of all comments | |
Failure/Error: @product.comments.create!(:rating => 1, :user_id => 10, :body => "hello") | |
ActiveRecord::RecordInvalid: | |
Validation failed: User can't be blank | |
# /usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.1/lib/active_record/validations.rb:79:in `raise_record_invalid' |
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 Product < ActiveRecord::Base | |
has_many :orders | |
has_many :comments | |
def average_rating | |
comments.average(:rating).to_f | |
end | |
validates :name, presence: true | |
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
Rails.application.routes.draw do | |
get 'static_pages/about' | |
get 'static_pages/contact' | |
get 'static_pages/index' | |
# The priority is based upon order of creation: first created -> highest priority. | |
# See how all your routes lay out with "rake routes". |
NewerOlder