diff --git a/source/example-app/.gitignore b/source/example-app/.gitignore new file mode 100644 index 000000000..25a742dff --- /dev/null +++ b/source/example-app/.gitignore @@ -0,0 +1,16 @@ +# See http://help.github.com/ignore-files/ for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-journal + +# Ignore all logfiles and tempfiles. +/log/*.log +/tmp diff --git a/source/example-app/Gemfile b/source/example-app/Gemfile new file mode 100644 index 000000000..9e6552489 --- /dev/null +++ b/source/example-app/Gemfile @@ -0,0 +1,51 @@ +source 'https://rubygems.org' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '4.0.0' + +# Use postgresql as the database for Active Record +gem 'pg', '~> 0.20.0' + +# Use SCSS for stylesheets +gem 'sass-rails', '~> 4.0.0' + +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' + +# Use CoffeeScript for .js.coffee assets and views +gem 'coffee-rails', '~> 4.0.0' + +# See https://github.com/sstephenson/execjs#readme for more supported runtimes +# gem 'therubyracer', platforms: :ruby + +# Use jquery as the JavaScript library +gem 'jquery-rails' + +# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks +gem 'turbolinks', '~> 1.3' + +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 1.2' + +group :doc do + # bundle exec rake doc:rails generates the API under doc/api. + gem 'sdoc', require: false +end + +group :development, :test do + gem 'rspec-rails', '~> 3.9.1' + gem 'database_cleaner', '1.8.3' + gem 'capybara' +end + +# Use ActiveModel has_secure_password +# gem 'bcrypt-ruby', '~> 3.0.0' + +# Use unicorn as the app server +# gem 'unicorn' + +# Use Capistrano for deployment +# gem 'capistrano', group: :development + +# Use debugger +# gem 'debugger', group: [:development, :test] diff --git a/source/example-app/Gemfile.lock b/source/example-app/Gemfile.lock new file mode 100644 index 000000000..02f032b51 --- /dev/null +++ b/source/example-app/Gemfile.lock @@ -0,0 +1,157 @@ +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.0.0) + actionpack (= 4.0.0) + mail (~> 2.5.3) + actionpack (4.0.0) + activesupport (= 4.0.0) + builder (~> 3.1.0) + erubis (~> 2.7.0) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + activemodel (4.0.0) + activesupport (= 4.0.0) + builder (~> 3.1.0) + activerecord (4.0.0) + activemodel (= 4.0.0) + activerecord-deprecated_finders (~> 1.0.2) + activesupport (= 4.0.0) + arel (~> 4.0.0) + activerecord-deprecated_finders (1.0.4) + activesupport (4.0.0) + i18n (~> 0.6, >= 0.6.4) + minitest (~> 4.2) + multi_json (~> 1.3) + thread_safe (~> 0.1) + tzinfo (~> 0.3.37) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) + arel (4.0.2) + builder (3.1.4) + capybara (2.18.0) + addressable + mini_mime (>= 0.1.3) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (>= 2.0, < 4.0) + coffee-rails (4.0.1) + coffee-script (>= 2.2.0) + railties (>= 4.0.0, < 5.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.1.8) + database_cleaner (1.8.3) + diff-lcs (1.4.4) + erubis (2.7.0) + execjs (2.7.0) + hike (1.2.3) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + jbuilder (1.5.3) + activesupport (>= 3.0.0) + multi_json (>= 1.2.0) + jquery-rails (3.1.5) + railties (>= 3.0, < 5.0) + thor (>= 0.14, < 2.0) + mail (2.5.5) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.25.1) + mini_mime (1.1.0) + mini_portile2 (2.1.0) + minitest (4.7.5) + multi_json (1.15.0) + nokogiri (1.6.8.1) + mini_portile2 (~> 2.1.0) + pg (0.20.0) + polyglot (0.3.5) + public_suffix (2.0.5) + rack (1.5.5) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.0.0) + actionmailer (= 4.0.0) + actionpack (= 4.0.0) + activerecord (= 4.0.0) + activesupport (= 4.0.0) + bundler (>= 1.3.0, < 2.0) + railties (= 4.0.0) + sprockets-rails (~> 2.0.0) + railties (4.0.0) + actionpack (= 4.0.0) + activesupport (= 4.0.0) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (12.3.3) + rdoc (5.1.0) + rspec-core (3.9.3) + rspec-support (~> 3.9.3) + rspec-expectations (3.9.4) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-rails (3.9.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.4) + sass (3.2.19) + sass-rails (4.0.5) + railties (>= 4.0.0, < 5.0) + sass (~> 3.2.2) + sprockets (~> 2.8, < 3.0) + sprockets-rails (~> 2.0) + sdoc (2.1.0) + rdoc (>= 5.0) + sprockets (2.12.5) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sprockets-rails (2.0.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (~> 2.8) + thor (1.1.0) + thread_safe (0.3.6) + tilt (1.4.1) + treetop (1.4.15) + polyglot + polyglot (>= 0.3.1) + turbolinks (1.3.1) + coffee-rails + tzinfo (0.3.60) + uglifier (4.2.0) + execjs (>= 0.3.0, < 3) + xpath (2.1.0) + nokogiri (~> 1.3) + +PLATFORMS + ruby + +DEPENDENCIES + capybara + coffee-rails (~> 4.0.0) + database_cleaner (= 1.8.3) + jbuilder (~> 1.2) + jquery-rails + pg (~> 0.20.0) + rails (= 4.0.0) + rspec-rails (~> 3.9.1) + sass-rails (~> 4.0.0) + sdoc + turbolinks (~> 1.3) + uglifier (>= 1.3.0) + +BUNDLED WITH + 1.17.3 diff --git a/source/example-app/README.rdoc b/source/example-app/README.rdoc new file mode 100644 index 000000000..dd4e97e22 --- /dev/null +++ b/source/example-app/README.rdoc @@ -0,0 +1,28 @@ +== README + +This README would normally document whatever steps are necessary to get the +application up and running. + +Things you may want to cover: + +* Ruby version + +* System dependencies + +* Configuration + +* Database creation + +* Database initialization + +* How to run the test suite + +* Services (job queues, cache servers, search engines, etc.) + +* Deployment instructions + +* ... + + +Please feel free to use a different markup language if you do not plan to run +rake doc:app. diff --git a/source/example-app/Rakefile b/source/example-app/Rakefile new file mode 100644 index 000000000..e67201a82 --- /dev/null +++ b/source/example-app/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) + +ExampleApp::Application.load_tasks diff --git a/source/example-app/app/assets/images/.keep b/source/example-app/app/assets/images/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/app/assets/javascripts/application.js b/source/example-app/app/assets/javascripts/application.js new file mode 100644 index 000000000..d6925fa43 --- /dev/null +++ b/source/example-app/app/assets/javascripts/application.js @@ -0,0 +1,16 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. +// +// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require jquery +//= require jquery_ujs +//= require turbolinks +//= require_tree . diff --git a/source/example-app/app/assets/javascripts/charges.js.coffee b/source/example-app/app/assets/javascripts/charges.js.coffee new file mode 100644 index 000000000..24f83d18b --- /dev/null +++ b/source/example-app/app/assets/javascripts/charges.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/source/example-app/app/assets/javascripts/customers.js.coffee b/source/example-app/app/assets/javascripts/customers.js.coffee new file mode 100644 index 000000000..24f83d18b --- /dev/null +++ b/source/example-app/app/assets/javascripts/customers.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/source/example-app/app/assets/stylesheets/application.css b/source/example-app/app/assets/stylesheets/application.css new file mode 100644 index 000000000..a63edf58d --- /dev/null +++ b/source/example-app/app/assets/stylesheets/application.css @@ -0,0 +1,21 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the top of the + * compiled file, but it's generally better to create a new file per style scope. + * + *= require_self + *= require_tree . + */ + +.danger { + background-color: #FF0000; +} + +.salmon { + background-color: #FF5400; +} \ No newline at end of file diff --git a/source/example-app/app/assets/stylesheets/charges.css.scss b/source/example-app/app/assets/stylesheets/charges.css.scss new file mode 100644 index 000000000..c3a893042 --- /dev/null +++ b/source/example-app/app/assets/stylesheets/charges.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Charges controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/source/example-app/app/assets/stylesheets/customers.css.scss b/source/example-app/app/assets/stylesheets/customers.css.scss new file mode 100644 index 000000000..892b0ad94 --- /dev/null +++ b/source/example-app/app/assets/stylesheets/customers.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the customers controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/source/example-app/app/assets/stylesheets/scaffolds.css.scss b/source/example-app/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 000000000..6ec6a8ff5 --- /dev/null +++ b/source/example-app/app/assets/stylesheets/scaffolds.css.scss @@ -0,0 +1,69 @@ +body { + background-color: #fff; + color: #333; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + &:visited { + color: #666; + } + &:hover { + color: #fff; + background-color: #000; + } +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px; + padding-bottom: 0; + margin-bottom: 20px; + background-color: #f0f0f0; + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + margin-bottom: 0px; + background-color: #c00; + color: #fff; + } + ul li { + font-size: 12px; + list-style: square; + } +} diff --git a/source/example-app/app/controllers/application_controller.rb b/source/example-app/app/controllers/application_controller.rb new file mode 100644 index 000000000..d83690e1b --- /dev/null +++ b/source/example-app/app/controllers/application_controller.rb @@ -0,0 +1,5 @@ +class ApplicationController < ActionController::Base + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception +end diff --git a/source/example-app/app/controllers/charges_controller.rb b/source/example-app/app/controllers/charges_controller.rb new file mode 100644 index 000000000..5c57af40d --- /dev/null +++ b/source/example-app/app/controllers/charges_controller.rb @@ -0,0 +1,74 @@ +class ChargesController < ApplicationController + before_action :set_charge, only: [:show, :edit, :update, :destroy] + + # GET /charges + # GET /charges.json + def index + @charges = Charge.all + end + + # GET /charges/1 + # GET /charges/1.json + def show + end + + # GET /charges/new + def new + @charge = Charge.new + end + + # GET /charges/1/edit + def edit + end + + # POST /charges + # POST /charges.json + def create + @charge = Charge.new(charge_params) + + respond_to do |format| + if @charge.save + format.html { redirect_to @charge, notice: 'Charge was successfully created.' } + format.json { render action: 'show', status: :created, location: @charge } + else + format.html { render action: 'new' } + format.json { render json: @charge.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /charges/1 + # PATCH/PUT /charges/1.json + def update + respond_to do |format| + if @charge.update(charge_params) + format.html { redirect_to @charge, notice: 'Charge was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: 'edit' } + format.json { render json: @charge.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /charges/1 + # DELETE /charges/1.json + def destroy + @charge.destroy + respond_to do |format| + format.html { redirect_to charges_url } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_charge + @charge = Charge.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def charge_params + params.require(:charge).permit(:created, :paid, :amount, :currency, :refunded, :customer_id) + end +end diff --git a/source/example-app/app/controllers/concerns/.keep b/source/example-app/app/controllers/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/app/controllers/customers_controller.rb b/source/example-app/app/controllers/customers_controller.rb new file mode 100644 index 000000000..0210a69a7 --- /dev/null +++ b/source/example-app/app/controllers/customers_controller.rb @@ -0,0 +1,74 @@ +class CustomersController < ApplicationController + before_action :set_customer, only: [:show, :edit, :update, :destroy] + + # GET /customers + # GET /customers.json + def index + @customers = Customer.all + end + + # GET /customers/1 + # GET /customers/1.json + def show + end + + # GET /customers/new + def new + @customer = Customer.new + end + + # GET /customers/1/edit + def edit + end + + # POST /customers + # POST /customers.json + def create + @customer = Customer.new(customer_params) + + respond_to do |format| + if @customer.save + format.html { redirect_to @customer, notice: 'Customer was successfully created.' } + format.json { render action: 'show', status: :created, location: @customer } + else + format.html { render action: 'new' } + format.json { render json: @customer.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /customers/1 + # PATCH/PUT /customers/1.json + def update + respond_to do |format| + if @customer.update(customer_params) + format.html { redirect_to @customer, notice: 'Customer was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: 'edit' } + format.json { render json: @customer.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /customers/1 + # DELETE /customers/1.json + def destroy + @customer.destroy + respond_to do |format| + format.html { redirect_to customers_url } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_customer + @customer = Customer.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def customer_params + params.require(:customer).permit(:first_name, :last_name) + end +end diff --git a/source/example-app/app/helpers/application_helper.rb b/source/example-app/app/helpers/application_helper.rb new file mode 100644 index 000000000..2069138ce --- /dev/null +++ b/source/example-app/app/helpers/application_helper.rb @@ -0,0 +1,9 @@ +module ApplicationHelper + def format_full_name(person) + "#{person.first_name} #{person.last_name}" + end + + def epoch_to_date(epoch) + Time.at(epoch) + end +end diff --git a/source/example-app/app/helpers/charges_helper.rb b/source/example-app/app/helpers/charges_helper.rb new file mode 100644 index 000000000..414ee900f --- /dev/null +++ b/source/example-app/app/helpers/charges_helper.rb @@ -0,0 +1,2 @@ +module ChargesHelper +end diff --git a/source/example-app/app/helpers/customers_helper.rb b/source/example-app/app/helpers/customers_helper.rb new file mode 100644 index 000000000..a07ce2943 --- /dev/null +++ b/source/example-app/app/helpers/customers_helper.rb @@ -0,0 +1,2 @@ +module CustomersHelper +end diff --git a/source/example-app/app/mailers/.keep b/source/example-app/app/mailers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/app/models/.keep b/source/example-app/app/models/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/app/models/charge.rb b/source/example-app/app/models/charge.rb new file mode 100644 index 000000000..9cd227100 --- /dev/null +++ b/source/example-app/app/models/charge.rb @@ -0,0 +1,12 @@ +class Charge < ActiveRecord::Base + belongs_to :customer + + # I'm not fully knowing the conditions to filter the different types + # I can investigate them, but it's going to take me longer to complete the challenge + # + # we can put indexes on columns to make the queries faster + + scope :failed, -> { where(paid: false) } + scope :disputed, -> { where(paid: true, refunded: true) } + scope :successful, -> { where(paid: true, refunded: false) } +end diff --git a/source/example-app/app/models/concerns/.keep b/source/example-app/app/models/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/app/models/customer.rb b/source/example-app/app/models/customer.rb new file mode 100644 index 000000000..047dcb0c0 --- /dev/null +++ b/source/example-app/app/models/customer.rb @@ -0,0 +1,2 @@ +class Customer < ActiveRecord::Base +end diff --git a/source/example-app/app/views/charges/_charge.html.erb b/source/example-app/app/views/charges/_charge.html.erb new file mode 100644 index 000000000..7eff1dcb0 --- /dev/null +++ b/source/example-app/app/views/charges/_charge.html.erb @@ -0,0 +1,12 @@ +
Created | +Paid | +Amount | +Currency | +Refunded | +Customer | ++ | + | + |
---|
Customer | +Amount | +Date | ++ | + | + |
---|
<%= notice %>
+ ++ Created: + <%= @charge.created %> +
+ ++ Paid: + <%= @charge.paid %> +
+ ++ Amount: + <%= @charge.amount %> +
+ ++ Currency: + <%= @charge.currency %> +
+ ++ Refunded: + <%= @charge.refunded %> +
+ ++ Customer: + <%= @charge.customer %> +
+ +<%= link_to 'Edit', edit_charge_path(@charge) %> | +<%= link_to 'Back', charges_path %> diff --git a/source/example-app/app/views/charges/show.json.jbuilder b/source/example-app/app/views/charges/show.json.jbuilder new file mode 100644 index 000000000..8e1676c10 --- /dev/null +++ b/source/example-app/app/views/charges/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @charge, :id, :created, :paid, :amount, :currency, :refunded, :customer_id, :created_at, :updated_at diff --git a/source/example-app/app/views/customers/_form.html.erb b/source/example-app/app/views/customers/_form.html.erb new file mode 100644 index 000000000..f2db3db1e --- /dev/null +++ b/source/example-app/app/views/customers/_form.html.erb @@ -0,0 +1,25 @@ +<%= form_for(@customer) do |f| %> + <% if @customer.errors.any? %> +First name | +Last name | ++ | + | + |
---|---|---|---|---|
<%= customer.first_name %> | +<%= customer.last_name %> | +<%= link_to 'Show', customer %> | +<%= link_to 'Edit', edit_customer_path(customer) %> | +<%= link_to 'Destroy', customer, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ ++ First name: + <%= @customer.first_name %> +
+ ++ Last name: + <%= @customer.last_name %> +
+ +<%= link_to 'Edit', edit_customer_path(@customer) %> | +<%= link_to 'Back', customers_path %> diff --git a/source/example-app/app/views/customers/show.json.jbuilder b/source/example-app/app/views/customers/show.json.jbuilder new file mode 100644 index 000000000..a7698de6a --- /dev/null +++ b/source/example-app/app/views/customers/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @customer, :id, :first_name, :last_name, :created_at, :updated_at diff --git a/source/example-app/app/views/layouts/application.html.erb b/source/example-app/app/views/layouts/application.html.erb new file mode 100644 index 000000000..3a16810af --- /dev/null +++ b/source/example-app/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + +You may have mistyped the address or the page may have moved.
+If you are the application owner check the logs for more information.
+ + diff --git a/source/example-app/public/422.html b/source/example-app/public/422.html new file mode 100644 index 000000000..fbb4b84d7 --- /dev/null +++ b/source/example-app/public/422.html @@ -0,0 +1,58 @@ + + + +Maybe you tried to change something you didn't have access to.
+If you are the application owner check the logs for more information.
+ + diff --git a/source/example-app/public/500.html b/source/example-app/public/500.html new file mode 100644 index 000000000..e9052d35b --- /dev/null +++ b/source/example-app/public/500.html @@ -0,0 +1,57 @@ + + + +If you are the application owner check the logs for more information.
+ + diff --git a/source/example-app/public/favicon.ico b/source/example-app/public/favicon.ico new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/public/robots.txt b/source/example-app/public/robots.txt new file mode 100644 index 000000000..1a3a5e4dd --- /dev/null +++ b/source/example-app/public/robots.txt @@ -0,0 +1,5 @@ +# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/source/example-app/spec/controllers/charges_controller_spec.rb b/source/example-app/spec/controllers/charges_controller_spec.rb new file mode 100644 index 000000000..e2a7f9c4c --- /dev/null +++ b/source/example-app/spec/controllers/charges_controller_spec.rb @@ -0,0 +1,141 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. +# +# Also compared to earlier versions of this generator, there are no longer any +# expectations of assigns and templates rendered. These features have been +# removed from Rails core in Rails 5, but can be added back in via the +# `rails-controller-testing` gem. + +RSpec.describe ChargesController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # Charge. As you add validations to Charge, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # ChargesController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "returns a success response" do + Charge.create! valid_attributes + get :index, {}, valid_session + expect(response).to be_successful + end + end + + describe "GET #show" do + it "returns a success response" do + charge = Charge.create! valid_attributes + get :show, {:id => charge.to_param}, valid_session + expect(response).to be_successful + end + end + + describe "GET #new" do + it "returns a success response" do + get :new, {}, valid_session + expect(response).to be_successful + end + end + + describe "GET #edit" do + it "returns a success response" do + charge = Charge.create! valid_attributes + get :edit, {:id => charge.to_param}, valid_session + expect(response).to be_successful + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Charge" do + expect { + post :create, {:charge => valid_attributes}, valid_session + }.to change(Charge, :count).by(1) + end + + it "redirects to the created charge" do + post :create, {:charge => valid_attributes}, valid_session + expect(response).to redirect_to(Charge.last) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'new' template)" do + post :create, {:charge => invalid_attributes}, valid_session + expect(response).to be_successful + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested charge" do + charge = Charge.create! valid_attributes + put :update, {:id => charge.to_param, :charge => new_attributes}, valid_session + charge.reload + skip("Add assertions for updated state") + end + + it "redirects to the charge" do + charge = Charge.create! valid_attributes + put :update, {:id => charge.to_param, :charge => valid_attributes}, valid_session + expect(response).to redirect_to(charge) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'edit' template)" do + charge = Charge.create! valid_attributes + put :update, {:id => charge.to_param, :charge => invalid_attributes}, valid_session + expect(response).to be_successful + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested charge" do + charge = Charge.create! valid_attributes + expect { + delete :destroy, {:id => charge.to_param}, valid_session + }.to change(Charge, :count).by(-1) + end + + it "redirects to the charges list" do + charge = Charge.create! valid_attributes + delete :destroy, {:id => charge.to_param}, valid_session + expect(response).to redirect_to(charges_url) + end + end + +end diff --git a/source/example-app/spec/controllers/customers_controller_spec.rb b/source/example-app/spec/controllers/customers_controller_spec.rb new file mode 100644 index 000000000..60980a9d4 --- /dev/null +++ b/source/example-app/spec/controllers/customers_controller_spec.rb @@ -0,0 +1,141 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. +# +# Also compared to earlier versions of this generator, there are no longer any +# expectations of assigns and templates rendered. These features have been +# removed from Rails core in Rails 5, but can be added back in via the +# `rails-controller-testing` gem. + +RSpec.describe CustomersController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # Customer. As you add validations to Customer, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # CustomersController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "returns a success response" do + Customer.create! valid_attributes + get :index, {}, valid_session + expect(response).to be_successful + end + end + + describe "GET #show" do + it "returns a success response" do + customer = Customer.create! valid_attributes + get :show, {:id => customer.to_param}, valid_session + expect(response).to be_successful + end + end + + describe "GET #new" do + it "returns a success response" do + get :new, {}, valid_session + expect(response).to be_successful + end + end + + describe "GET #edit" do + it "returns a success response" do + customer = Customer.create! valid_attributes + get :edit, {:id => customer.to_param}, valid_session + expect(response).to be_successful + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Customer" do + expect { + post :create, {:customer => valid_attributes}, valid_session + }.to change(Customer, :count).by(1) + end + + it "redirects to the created customer" do + post :create, {:customer => valid_attributes}, valid_session + expect(response).to redirect_to(Customer.last) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'new' template)" do + post :create, {:customer => invalid_attributes}, valid_session + expect(response).to be_successful + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested customer" do + customer = Customer.create! valid_attributes + put :update, {:id => customer.to_param, :customer => new_attributes}, valid_session + customer.reload + skip("Add assertions for updated state") + end + + it "redirects to the customer" do + customer = Customer.create! valid_attributes + put :update, {:id => customer.to_param, :customer => valid_attributes}, valid_session + expect(response).to redirect_to(customer) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'edit' template)" do + customer = Customer.create! valid_attributes + put :update, {:id => customer.to_param, :customer => invalid_attributes}, valid_session + expect(response).to be_successful + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested customer" do + customer = Customer.create! valid_attributes + expect { + delete :destroy, {:id => customer.to_param}, valid_session + }.to change(Customer, :count).by(-1) + end + + it "redirects to the customers list" do + customer = Customer.create! valid_attributes + delete :destroy, {:id => customer.to_param}, valid_session + expect(response).to redirect_to(customers_url) + end + end + +end diff --git a/source/example-app/spec/features/charges_spec.rb b/source/example-app/spec/features/charges_spec.rb new file mode 100644 index 000000000..4a0535b2a --- /dev/null +++ b/source/example-app/spec/features/charges_spec.rb @@ -0,0 +1,21 @@ +require "rails_helper" + +RSpec.feature "Charges index", :type => :feature do + before(:each) do + visit "/charges/" + end + + describe "User visits the index page of the transactions" do + it "Can see the lists of types of transactions" do + expect(page).to have_text("Successful Charges") + expect(page).to have_text("Failed Charges") + expect(page).to have_text("Disputed Charges") + end + + it "Can see the exact number of transactions in its corresponding list" do + page.assert_selector('#successful-charges .charge-item', count: 10) + page.assert_selector('#failed-charges .charge-item', count: 5) + page.assert_selector('#disputed-charges .charge-item') + end + end +end \ No newline at end of file diff --git a/source/example-app/spec/helpers/charges_helper_spec.rb b/source/example-app/spec/helpers/charges_helper_spec.rb new file mode 100644 index 000000000..0c25eaa8c --- /dev/null +++ b/source/example-app/spec/helpers/charges_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the ChargesHelper. For example: +# +# describe ChargesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe ChargesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/source/example-app/spec/helpers/customers_helper_spec.rb b/source/example-app/spec/helpers/customers_helper_spec.rb new file mode 100644 index 000000000..fa160374f --- /dev/null +++ b/source/example-app/spec/helpers/customers_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the CustomersHelper. For example: +# +# describe CustomersHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe CustomersHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/source/example-app/spec/models/charge_spec.rb b/source/example-app/spec/models/charge_spec.rb new file mode 100644 index 000000000..a99f4cce3 --- /dev/null +++ b/source/example-app/spec/models/charge_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Charge, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/source/example-app/spec/models/customer_spec.rb b/source/example-app/spec/models/customer_spec.rb new file mode 100644 index 000000000..3399b1f56 --- /dev/null +++ b/source/example-app/spec/models/customer_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Customer, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/source/example-app/spec/rails_helper.rb b/source/example-app/spec/rails_helper.rb new file mode 100644 index 000000000..bf60770ed --- /dev/null +++ b/source/example-app/spec/rails_helper.rb @@ -0,0 +1,89 @@ +require 'database_cleaner' + +# This file is copied to spec/ when you run 'rails generate rspec:install' +require 'spec_helper' +ENV['RAILS_ENV'] ||= 'test' + +require File.expand_path('../config/environment', __dir__) + +# Prevent database truncation if the environment is production +abort("The Rails environment is running in production mode!") if Rails.env.production? +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } + +# Checks for pending migrations before tests are run. +# If you are not using ActiveRecord, you can remove these lines. +begin + ActiveRecord::Migration.check_pending! +rescue ActiveRecord::PendingMigrationError => e + puts e.to_s.strip + exit 1 +end +RSpec.configure do |config| + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = false + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, :type => :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") + + config.before(:suite) do + DatabaseCleaner.clean_with(:truncation) + end + + config.before(:each) do + DatabaseCleaner.strategy = :transaction + end + + config.before(:each, js: true) do + DatabaseCleaner.strategy = :truncation + end + + config.before :suite do + load "#{Rails.root}/db/seeds.rb" + end + + config.after(:all) do + DatabaseCleaner.clean + end + + config.after(:suite) do + DatabaseCleaner.clean_with(:truncation) + end +end diff --git a/source/example-app/spec/requests/charges_spec.rb b/source/example-app/spec/requests/charges_spec.rb new file mode 100644 index 000000000..504ef7846 --- /dev/null +++ b/source/example-app/spec/requests/charges_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Charges", type: :request do + describe "GET /charges" do + it "works! (now write some real specs)" do + get charges_path + expect(response).to have_http_status(200) + end + end +end diff --git a/source/example-app/spec/requests/customers_spec.rb b/source/example-app/spec/requests/customers_spec.rb new file mode 100644 index 000000000..081166fb1 --- /dev/null +++ b/source/example-app/spec/requests/customers_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Customers", type: :request do + describe "GET /customers" do + it "works! (now write some real specs)" do + get customers_path + expect(response).to have_http_status(200) + end + end +end diff --git a/source/example-app/spec/routing/charges_routing_spec.rb b/source/example-app/spec/routing/charges_routing_spec.rb new file mode 100644 index 000000000..4b2d9c92f --- /dev/null +++ b/source/example-app/spec/routing/charges_routing_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe ChargesController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(:get => "/charges").to route_to("charges#index") + end + + it "routes to #new" do + expect(:get => "/charges/new").to route_to("charges#new") + end + + it "routes to #show" do + expect(:get => "/charges/1").to route_to("charges#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/charges/1/edit").to route_to("charges#edit", :id => "1") + end + + + it "routes to #create" do + expect(:post => "/charges").to route_to("charges#create") + end + + it "routes to #update via PUT" do + expect(:put => "/charges/1").to route_to("charges#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/charges/1").to route_to("charges#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/charges/1").to route_to("charges#destroy", :id => "1") + end + end +end diff --git a/source/example-app/spec/routing/customers_routing_spec.rb b/source/example-app/spec/routing/customers_routing_spec.rb new file mode 100644 index 000000000..622cd626a --- /dev/null +++ b/source/example-app/spec/routing/customers_routing_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe CustomersController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(:get => "/customers").to route_to("customers#index") + end + + it "routes to #new" do + expect(:get => "/customers/new").to route_to("customers#new") + end + + it "routes to #show" do + expect(:get => "/customers/1").to route_to("customers#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/customers/1/edit").to route_to("customers#edit", :id => "1") + end + + + it "routes to #create" do + expect(:post => "/customers").to route_to("customers#create") + end + + it "routes to #update via PUT" do + expect(:put => "/customers/1").to route_to("customers#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/customers/1").to route_to("customers#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/customers/1").to route_to("customers#destroy", :id => "1") + end + end +end diff --git a/source/example-app/spec/spec_helper.rb b/source/example-app/spec/spec_helper.rb new file mode 100644 index 000000000..ce33d66df --- /dev/null +++ b/source/example-app/spec/spec_helper.rb @@ -0,0 +1,96 @@ +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end diff --git a/source/example-app/spec/views/charges/_charge.html.erb b/source/example-app/spec/views/charges/_charge.html.erb new file mode 100644 index 000000000..76d341137 --- /dev/null +++ b/source/example-app/spec/views/charges/_charge.html.erb @@ -0,0 +1,12 @@ +Created | +Paid | +Amount | +Currency | +Refunded | +Customer | ++ | + | + |
---|
" do + render + expect(rendered).to match(/2/) + expect(rendered).to match(/false/) + expect(rendered).to match(/9.99/) + expect(rendered).to match(/Currency/) + expect(rendered).to match(/false/) + expect(rendered).to match(//) + end +end diff --git a/source/example-app/spec/views/customers/edit.html.erb_spec.rb b/source/example-app/spec/views/customers/edit.html.erb_spec.rb new file mode 100644 index 000000000..35f127c2c --- /dev/null +++ b/source/example-app/spec/views/customers/edit.html.erb_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe "customers/edit", type: :view do + before(:each) do + @customer = assign(:customer, Customer.create!( + :first_name => "MyString", + :last_name => "MyString" + )) + end + + it "renders the edit customer form" do + render + + assert_select "form[action=?][method=?]", customer_path(@customer), "post" do + + assert_select "input#customer_first_name[name=?]", "customer[first_name]" + + assert_select "input#customer_last_name[name=?]", "customer[last_name]" + end + end +end diff --git a/source/example-app/spec/views/customers/index.html.erb_spec.rb b/source/example-app/spec/views/customers/index.html.erb_spec.rb new file mode 100644 index 000000000..76a42155b --- /dev/null +++ b/source/example-app/spec/views/customers/index.html.erb_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +RSpec.describe "customers/index", type: :view do + before(:each) do + assign(:customers, [ + Customer.create!( + :first_name => "First Name", + :last_name => "Last Name" + ), + Customer.create!( + :first_name => "First Name", + :last_name => "Last Name" + ) + ]) + end + + it "renders a list of customers" do + render + assert_select "tr>td", :text => "First Name".to_s, :count => 2 + assert_select "tr>td", :text => "Last Name".to_s, :count => 2 + end +end diff --git a/source/example-app/spec/views/customers/new.html.erb_spec.rb b/source/example-app/spec/views/customers/new.html.erb_spec.rb new file mode 100644 index 000000000..bb26fd937 --- /dev/null +++ b/source/example-app/spec/views/customers/new.html.erb_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +RSpec.describe "customers/new", type: :view do + before(:each) do + assign(:customer, Customer.new( + :first_name => "MyString", + :last_name => "MyString" + )) + end + + it "renders new customer form" do + render + + assert_select "form[action=?][method=?]", customers_path, "post" do + + assert_select "input#customer_first_name[name=?]", "customer[first_name]" + + assert_select "input#customer_last_name[name=?]", "customer[last_name]" + end + end +end diff --git a/source/example-app/spec/views/customers/show.html.erb_spec.rb b/source/example-app/spec/views/customers/show.html.erb_spec.rb new file mode 100644 index 000000000..28ce03fd9 --- /dev/null +++ b/source/example-app/spec/views/customers/show.html.erb_spec.rb @@ -0,0 +1,16 @@ +require 'rails_helper' + +RSpec.describe "customers/show", type: :view do + before(:each) do + @customer = assign(:customer, Customer.create!( + :first_name => "First Name", + :last_name => "Last Name" + )) + end + + it "renders attributes in
" do + render + expect(rendered).to match(/First Name/) + expect(rendered).to match(/Last Name/) + end +end diff --git a/source/example-app/vendor/assets/javascripts/.keep b/source/example-app/vendor/assets/javascripts/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/source/example-app/vendor/assets/stylesheets/.keep b/source/example-app/vendor/assets/stylesheets/.keep new file mode 100644 index 000000000..e69de29bb