Skip to content

Commit

Permalink
add RSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
mindovermiles262 committed Aug 26, 2017
1 parent dee034a commit b592f72
Show file tree
Hide file tree
Showing 33 changed files with 281 additions and 108 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ group :development, :test do
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
gem 'faker', '~> 1.8', '>= 1.8.4'
gem 'rspec-rails', '~> 3.6', '>= 3.6.1'
gem 'factory_girl_rails', '~> 4.8'
end

group :development do
Expand All @@ -31,6 +33,11 @@ group :development do
gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
gem 'database_cleaner', '~> 1.6', '>= 1.6.1'
gem 'launchy', '~> 2.4', '>= 2.4.3'
end

group :production do
gem 'pg', '~> 0.21.0'
end
Expand Down
30 changes: 30 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@ GEM
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.0.5)
database_cleaner (1.6.1)
diff-lcs (1.3)
erubi (1.6.1)
execjs (2.7.0)
factory_girl (4.8.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.8.0)
factory_girl (~> 4.8.0)
railties (>= 3.0.0)
faker (1.8.4)
i18n (~> 0.5)
ffi (1.9.18)
Expand All @@ -81,6 +88,8 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
launchy (2.4.3)
addressable (~> 2.3)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand Down Expand Up @@ -133,6 +142,23 @@ GEM
rb-fsevent (0.10.2)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-rails (3.6.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
ruby_dep (1.5.0)
rubyzip (1.2.1)
sass (3.5.1)
Expand Down Expand Up @@ -191,13 +217,17 @@ DEPENDENCIES
byebug
capybara (~> 2.13)
coffee-rails (~> 4.2)
database_cleaner (~> 1.6, >= 1.6.1)
factory_girl_rails (~> 4.8)
faker (~> 1.8, >= 1.8.4)
jbuilder (~> 2.5)
jquery-rails (~> 4.3, >= 4.3.1)
launchy (~> 2.4, >= 2.4.3)
listen (>= 3.0.5, < 3.2)
pg (~> 0.21.0)
puma (~> 3.7)
rails (~> 5.1.3)
rspec-rails (~> 3.6, >= 3.6.1)
sass-rails (~> 5.0)
selenium-webdriver
spring
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/static_pages.coffee
Original file line number Diff line number Diff line change
@@ -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/
14 changes: 1 addition & 13 deletions app/assets/stylesheets/custom.css.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
/*--- GENERAL ---*/
/*--- TYPOGRAPHY ---*/
h1 {
text-align: center;
}

/* Forms */
input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
margin-bottom: 15px;

}

input {
height: auto !important;
}
16 changes: 16 additions & 0 deletions app/assets/stylesheets/forms.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Forms

input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
margin-bottom: 15px;
}
input {
height: auto !important;
}
.form-buttons {
text-align: center;
}
.form-button {
width: 25%;
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/static_pages.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the StaticPages controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
4 changes: 4 additions & 0 deletions app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class StaticPagesController < ApplicationController
def index
end
end
2 changes: 2 additions & 0 deletions app/helpers/static_pages_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module StaticPagesHelper
end
9 changes: 2 additions & 7 deletions app/views/shared/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="/test_methods">Test Methods <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
Expand All @@ -29,12 +29,7 @@
</ul>
</li>
</ul>
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<!-- Navbar Right -->
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
Expand Down
1 change: 1 addition & 0 deletions app/views/static_pages/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>LIMS</h1>
60 changes: 17 additions & 43 deletions app/views/test_methods/_test_method_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,50 +1,24 @@
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for @test_method do |f| %>
<div class="row">
<div class="col-md-12">
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
</div>
</div>
<%= form_for @test_method do |f| %>
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>

<div class="row">
<div class="col-md-4">
<%= f.label :target_organism %>
<%= f.select :target_organism, @target_organisms %>
</div>
<%= f.label :target_organism %>
<%= f.select :target_organism, @target_organisms, class: 'form-control' %>

<div class="col-md-4">
<%= f.label :reference_method %>
<%= f.select :reference_method, @reference_methods %>
</div>
<%= f.label :reference_method %>
<%= f.select :reference_method, @reference_methods, class: 'form-control' %>

<div class="col-md-4">
<%= f.label :turn_around_time %>
<%= f.number_field :turn_around_time, class: 'form-control' %> Days
</div>
</div>
<%= f.label :turn_around_time %> (Days)
<%= f.number_field :turn_around_time, class: 'form-control' %>

<div class="row">
<div class="col-md-6">
<%= f.label :detection_limit %>
<%= f.number_field :detection_limit, class: 'form-control' %>
</div>
<%= f.label :detection_limit %>
<%= f.number_field :detection_limit, class: 'form-control' %>

<div class="col-md-6">
<%= f.label :unit %>
<%= f.select :unit, @units %>
</div>
</div>
<%= f.label :unit %>
<%= f.select :unit, @units, class: 'form-control' %>

<div class="row">
<div class="col-md-6">
<%= f.submit "Submit", class: 'btn btn-primary' %>
</div>
<div class="col-md-6">
<%= f.submit "Cancel", class: 'btn btn-danger' %>
</div>
</div>
<% end %>
<div class="form-buttons">
<%= f.submit "Submit", class: 'btn btn-primary form-button' %>
<%= f.submit "Cancel", class: 'btn btn-danger form-button' %>
</div>
</div>
<% end %>
4 changes: 3 additions & 1 deletion app/views/test_methods/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h1>Edit Test Method</h1>
<div class="page-header">
<h1>Edit Test Method</h1>
</div>

<%= render 'test_method_form' %>
6 changes: 4 additions & 2 deletions app/views/test_methods/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<h1>Test Methods</h1>
<div class="page-header">
<h1>Test Methods</h1>
</div>

<div class="table-responsive">
<table class="table table-striped">
Expand Down Expand Up @@ -26,6 +28,6 @@

<div class="row">
<div class="col-md-2">
<%= button_to "Add New Method", new_test_method_path, class: 'btn btn-primary', method: :get %>
<%= button_to "Add New Method", new_test_method_path, class: 'btn btn-primary col-md-12', method: :get %>
</div>
</div>
10 changes: 8 additions & 2 deletions app/views/test_methods/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<h1>New Method</h1>
<div class="page-header">
<h1>New Method</h1>
</div>

<%= render 'test_method_form' %>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= render 'test_method_form' %>
</div>
</div>
13 changes: 13 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,18 @@ 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.

config.generators do |g|
g.test_framework :rspec,
fixtures: true,
view_specs: false,
helper_specs: false,
routing_specs: false,
controller_specs: true,
request_specs: false
g.fixture_replacement :factory_girl, dir: "spec/factories"
end


end
end
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
root "static_pages#index"

resources :test_methods, only: [:new, :create, :edit, :update, :index, :destroy]
root "test_methods#index"
end
11 changes: 11 additions & 0 deletions spec/models/test_method_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'rails_helper'

RSpec.describe TestMethod, type: :model do
it "is valid with all fields"
it "is invalid without a name"
it "is invalid without a target organism"
it "is invalid without a reference method"
it "is invalid without a turn around time"
it "is invalid without a detection limit"
it "is invalid without a unit"
end
57 changes: 57 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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', __FILE__)
# 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 migration and applies them 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!

# 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")
end
Loading

0 comments on commit b592f72

Please sign in to comment.