Skip to content

Commit

Permalink
Configure rails_example
Browse files Browse the repository at this point in the history
  • Loading branch information
mwoods79 committed Aug 26, 2015
1 parent bd48e5c commit 10b1b89
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 158 deletions.
2 changes: 2 additions & 0 deletions spec/fixtures/rails_example/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
41 changes: 3 additions & 38 deletions spec/fixtures/rails_example/Gemfile
Original file line number Diff line number Diff line change
@@ -1,45 +1,10 @@
source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'active_model_serializers'
gem 'rack-cors', :require => 'rack/cors'
gem 'rails', '4.2.3'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/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'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'

# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'rspec-rails'
end

80 changes: 27 additions & 53 deletions spec/fixtures/rails_example/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ GEM
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
active_model_serializers (0.9.3)
activemodel (>= 3.2)
activejob (4.2.3)
activesupport (= 4.2.3)
globalid (>= 0.3.0)
Expand All @@ -37,30 +39,12 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.2)
byebug (6.0.2)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.9.1.1)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.6.0)
globalid (0.3.6)
activesupport (>= 4.1.0)
i18n (0.7.0)
jbuilder (2.3.1)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
jquery-rails (4.0.4)
rails-dom-testing (~> 1.0)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
loofah (2.0.3)
nokogiri (>= 1.5.9)
Expand All @@ -69,10 +53,10 @@ GEM
mime-types (2.6.1)
mini_portile (0.6.2)
minitest (5.8.0)
multi_json (1.11.2)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
rack (1.6.4)
rack-cors (0.4.0)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.3)
Expand Down Expand Up @@ -100,18 +84,23 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
rdoc (4.2.0)
sass (3.4.17)
sass-rails (5.0.3)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (~> 1.1)
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
spring (1.3.6)
rspec-core (3.3.2)
rspec-support (~> 3.3.0)
rspec-expectations (3.3.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-mocks (3.3.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-rails (3.3.3)
actionpack (>= 3.0, < 4.3)
activesupport (>= 3.0, < 4.3)
railties (>= 3.0, < 4.3)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
sprockets (3.3.3)
rack (~> 1.0)
sprockets-rails (2.3.2)
Expand All @@ -121,33 +110,18 @@ GEM
sqlite3 (1.3.10)
thor (0.19.1)
thread_safe (0.3.5)
tilt (1.4.1)
turbolinks (2.5.3)
coffee-rails
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (2.7.1)
execjs (>= 0.3.0)
json (>= 1.8.0)
web-console (2.2.1)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)

PLATFORMS
ruby

DEPENDENCIES
byebug
coffee-rails (~> 4.1.0)
jbuilder (~> 2.0)
jquery-rails
active_model_serializers
rack-cors
rails (= 4.2.3)
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
spring
rspec-rails
sqlite3
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0)

BUNDLED WITH
1.10.6
11 changes: 11 additions & 0 deletions spec/fixtures/rails_example/app/controllers/todos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class TodosController < ApplicationController
def index
render json: todos
end

private

def todos
Todo.all
end
end
2 changes: 2 additions & 0 deletions spec/fixtures/rails_example/app/models/todo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Todo < ActiveRecord::Base
end
22 changes: 9 additions & 13 deletions spec/fixtures/rails_example/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@

module RailsExample
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.

# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de

# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
config.middleware.insert_before 0, "Rack::Cors", :debug => true, :logger => (-> { Rails.logger }) do
allow do
origins '*'
resource '*',
:headers => :any,
:methods => [:get, :post, :delete, :put, :options, :head],
:max_age => 0
end
end
end
end
55 changes: 1 addition & 54 deletions spec/fixtures/rails_example/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,56 +1,3 @@
Rails.application.routes.draw do
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

# You can have the root of your site routed with "root"
# root 'welcome#index'

# Example of regular route:
# get 'products/:id' => 'catalog#view'

# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products

# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end

# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end

# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end

# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable

# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
resources :todos, only: :index
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CreateTodos < ActiveRecord::Migration
def change
create_table :todos do |t|
t.string :title
end
end
end
20 changes: 20 additions & 0 deletions spec/fixtures/rails_example/db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150826031001) do

create_table "todos", force: :cascade do |t|
t.string "title"
end

end
52 changes: 52 additions & 0 deletions spec/fixtures/rails_example/spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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!

# 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 this line.
ActiveRecord::Migration.maintain_test_schema!

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 = true

# 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!
end
24 changes: 24 additions & 0 deletions spec/fixtures/rails_example/spec/requests/todos_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "rails_helper"

RSpec.describe "Todos", :type => :request do

# letBANG because `before {expected_todos}` looks funny
let!(:expected_todos) do
3.times.map do |i|
Todo.create(title: "Todo #{i+1}")
end
end

it "lists all todos" do
get "/todos"
todos = extract_key_from_response("todos", response)
expect(todos.count).to eq expected_todos.count
end

def extract_key_from_response(key, response)
json_response = JSON.parse(response.body)
expect(json_response).to have_key key
json_response[key]
end

end
Loading

0 comments on commit 10b1b89

Please sign in to comment.