diff --git a/.rspec b/.rspec index c99d2e73..82b8369c 100644 --- a/.rspec +++ b/.rspec @@ -1 +1 @@ ---require spec_helper +--require spec_helper \ No newline at end of file diff --git a/Gemfile b/Gemfile index 2e64df9a..6b5a321c 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ ruby '2.3.3' gem 'rails', '5.0.0' # Postgres -gem 'pg', '~> 0.21' # Rails does not work with pg 1.0.0 (fixed in Rails 5.1.5) +gem 'pg', '~> 0.20.0' # Rails does not work with pg 1.0.0 (fixed in Rails 5.1.5), pg 0.21 gives constant deprecation warning: https://github.com/rails/rails/issues/29521 gem 'pg_search' # Web server and background processing @@ -63,24 +63,27 @@ group :development do gem 'capistrano-rbenv', require: false gem 'capistrano-sidekiq', require: false, github: 'seuros/capistrano-sidekiq' gem 'capistrano3-puma', require: false, github: 'seuros/capistrano-puma' # TODO: remove github once fixed version is officially deployed + gem 'better_errors' # Better error page for Rack apps + gem 'bullet' # Checks for n+1 queries + gem 'binding_of_caller' # Extends features of better_errors + gem 'meta_request' # Supporting gem for Google Chrome Rails Panel gem 'spring' # Spring speeds up development by keeping your application running in the background gem 'spring-watcher-listen', '~> 2.0.0' + gem 'yard' # Documentation generation tool end group :test do + gem 'capybara' + gem 'faker' + gem 'guard-rspec' + gem 'launchy' gem 'simplecov' - gem 'selenium-webdriver' # TODO: Replace by phantom.js end group :development, :test do - gem 'better_errors' - gem 'bullet' # Checks for n+1 queries - gem 'capybara' gem 'database_cleaner' - gem 'launchy' - gem 'meta_request' # Supporting gem for Google Chrome Rails Panel + gem 'factory_bot_rails' gem 'poltergeist' gem 'rails_best_practices' gem 'rspec-rails' - gem 'yard' # Documentation generation tool end diff --git a/Gemfile.lock b/Gemfile.lock index 3f120ed9..99b0ab2c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -629,6 +629,8 @@ GEM coderay (>= 1.0.0) erubi (>= 1.0.0) rack (>= 0.9.0) + binding_of_caller (0.8.0) + debug_inspector (>= 0.0.1) bio (1.5.1) bootstrap-sass (3.3.7) autoprefixer-rails (>= 5.2.1) @@ -660,8 +662,6 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (>= 2.0, < 4.0) - childprocess (0.9.0) - ffi (~> 1.0, >= 1.0.11) chosen-rails (1.8.3) coffee-rails (>= 3.2) railties (>= 3.0) @@ -683,6 +683,7 @@ GEM connection_pool (2.2.1) crass (1.0.4) database_cleaner (1.7.0) + debug_inspector (0.0.3) devise (4.4.3) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -694,10 +695,32 @@ GEM erubi (1.7.1) erubis (2.7.0) execjs (2.7.0) + factory_bot (4.8.2) + activesupport (>= 3.0.0) + factory_bot_rails (4.8.2) + factory_bot (~> 4.8.2) + railties (>= 3.0.0) + faker (1.8.7) + i18n (>= 0.7) ffi (1.9.23) ffi (1.9.23-x86-mingw32) + formatador (0.2.5) globalid (0.4.1) activesupport (>= 4.2.0) + guard (2.14.2) + formatador (>= 0.2.4) + listen (>= 2.7, < 4.0) + lumberjack (>= 1.0.12, < 2.0) + nenv (~> 0.1) + notiffany (~> 0.0) + pry (>= 0.9.12) + shellany (~> 0.0) + thor (>= 0.18.1) + guard-compat (1.2.1) + guard-rspec (4.7.3) + guard (~> 2.1) + guard-compat (~> 1.1) + rspec (>= 2.99.0, < 4.0) i18n (0.9.5) concurrent-ruby (~> 1.0) jbuilder (2.7.0) @@ -727,6 +750,7 @@ GEM loofah (2.2.2) crass (~> 1.0.2) nokogiri (>= 1.5.9) + lumberjack (1.0.13) mail (2.7.0) mini_mime (>= 0.1.1) meta_request (0.6.0) @@ -743,6 +767,7 @@ GEM minitest (5.11.3) multi_json (1.13.1) mustermann (1.0.2) + nenv (0.3.0) net-scp (1.2.1) net-ssh (>= 2.6.5) net-ssh (4.2.0) @@ -751,6 +776,9 @@ GEM mini_portile2 (~> 2.3.0) nokogiri (1.8.2-x86-mingw32) mini_portile2 (~> 2.3.0) + notiffany (0.1.1) + nenv (~> 0.1) + shellany (~> 0.0) orm_adapter (0.5.0) paperclip (6.0.0) activemodel (>= 4.2.0) @@ -758,8 +786,8 @@ GEM mime-types mimemagic (~> 0.3.0) terrapin (~> 0.6.0) - pg (0.21.0) - pg (0.21.0-x86-mingw32) + pg (0.20.0) + pg (0.20.0-x86-mingw32) pg_search (2.1.2) activerecord (>= 4.2) activesupport (>= 4.2) @@ -768,6 +796,9 @@ GEM capybara (~> 2.1) cliver (~> 0.3.1) websocket-driver (>= 0.2.0) + pry (0.11.3) + coderay (~> 1.1.0) + method_source (~> 0.9.0) public_suffix (3.0.2) puma (3.11.4) rack (2.0.4) @@ -824,6 +855,10 @@ GEM nokogiri roo (>= 2.0.0, < 3) spreadsheet (> 0.9.0) + rspec (3.7.0) + rspec-core (~> 3.7.0) + rspec-expectations (~> 3.7.0) + rspec-mocks (~> 3.7.0) rspec-core (3.7.1) rspec-support (~> 3.7.0) rspec-expectations (3.7.0) @@ -861,10 +896,8 @@ GEM railties (>= 4.0.0) select2-rails (4.0.3) thor (~> 0.14) - selenium-webdriver (3.11.0) - childprocess (~> 0.5) - rubyzip (~> 1.2) sexp_processor (4.11.0) + shellany (0.0.1) sidekiq (5.1.3) concurrent-ruby (~> 1.0) connection_pool (~> 2.2, >= 2.2.0) @@ -943,6 +976,7 @@ DEPENDENCIES aws-sdk bcrypt (~> 3.1.7) better_errors + binding_of_caller bio bootstrap-sass bullet @@ -958,6 +992,9 @@ DEPENDENCIES coffee-rails (~> 4.2) database_cleaner devise + factory_bot_rails + faker + guard-rspec jbuilder (~> 2.5) jquery-datatables-rails! jquery-fileupload-rails @@ -968,7 +1005,7 @@ DEPENDENCIES meta_request mime-types paperclip - pg (~> 0.21) + pg (~> 0.20.0) pg_search poltergeist puma (~> 3.0) @@ -981,7 +1018,6 @@ DEPENDENCIES sass-rails (~> 5.0) scenic select2-rails - selenium-webdriver sidekiq sidekiq-limit_fetch simple_form diff --git a/config/application.rb b/config/application.rb index f5f7f2f2..d76d7b19 100644 --- a/config/application.rb +++ b/config/application.rb @@ -11,7 +11,14 @@ module GBOLapp class Application < Rails::Application config.generators do |g| - g.test_framework :minitest + g.test_framework :rspec, + :fixtures => true, + :view_specs => false, + :helper_specs => false, + :routing_specs => false, + :controller_specs => true, + :request_specs => true + g.fixture_replacement :factory_girl, :dir => 'spec/factories' end # Settings in config/environments/* take precedence over those specified here. diff --git a/config/database.yml b/config/database.yml index 1a6f7811..2e250e75 100644 --- a/config/database.yml +++ b/config/database.yml @@ -16,6 +16,7 @@ test: &test encoding: unicode database: gbol_test pool: 5 + host: localhost timeout: 5000 username: postgres password: passwordpsql diff --git a/config/environments/development.rb b/config/environments/development.rb index be1363c9..e36650eb 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -72,5 +72,4 @@ config.paperclip_defaults = { :storage => 'filesystem' } - end diff --git a/config/environments/test.rb b/config/environments/test.rb index 666724af..80e03495 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -43,10 +43,6 @@ # Raises error for missing translations # config.action_view.raise_on_missing_translations = true - BetterErrors.editor = :subl - - # ENV["REDISTOGO_URL"] = 'redis://redistogo:9f39a5b8a1b376f818dd3edc74c600b6@chubb.redistogo.com:9618/' - Rails.application.configure do config.active_support.test_order = :sorted end diff --git a/db/schema.rb b/db/schema.rb index 5b094c2b..7d4a1b8e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -197,8 +197,8 @@ t.string "revision", limit: 255 t.string "confirmation", limit: 255 t.text "comments" - t.decimal "latitude", precision: 15, scale: 6 - t.decimal "longitude", precision: 15, scale: 6 + t.decimal "latitude", precision: 15, scale: 5 + t.decimal "longitude", precision: 15, scale: 5 end create_table "individuals_projects", id: false, force: :cascade do |t| @@ -618,15 +618,6 @@ add_foreign_key "plant_plates", "lab_racks" add_foreign_key "shelves", "freezers" - create_view "taxa_matview", materialized: true, sql_definition: <<-SQL - SELECT f.name AS family, - o.name AS "order", - hot.name AS higher_order_taxon - FROM ((families f - JOIN orders o ON ((f.order_id = o.id))) - JOIN higher_order_taxa hot ON ((o.higher_order_taxon_id = hot.id))); - SQL - create_view "overview_all_taxa_matviews", materialized: true, sql_definition: <<-SQL SELECT f.name AS family, count(sp.family_id) AS species_cnt diff --git a/spec/factories/freezers.rb b/spec/factories/freezers.rb new file mode 100644 index 00000000..2512b9cf --- /dev/null +++ b/spec/factories/freezers.rb @@ -0,0 +1,7 @@ +require 'faker' + +FactoryBot.define do + factory :freezer do |f| + f.freezercode { Faker::Types.string } + end +end \ No newline at end of file diff --git a/spec/models/freezer_spec.rb b/spec/models/freezer_spec.rb new file mode 100644 index 00000000..5ca2bd85 --- /dev/null +++ b/spec/models/freezer_spec.rb @@ -0,0 +1,29 @@ +require 'rails_helper' + +RSpec.describe Freezer do + subject { FactoryBot.create(:freezer) } + + it "is valid with valid attributes" do + should be_valid + end + + it "is not valid without a freezercode" do + subject.freezercode = nil + should_not be_valid + end + + it "has one lab" do + assc = described_class.reflect_on_association(:lab) + expect(assc.macro).to eq :belongs_to + end + + it "has many lab racks" do + assc = described_class.reflect_on_association(:lab_racks) + expect(assc.macro).to eq :has_many + end + + it "has many shelves" do + assc = described_class.reflect_on_association(:shelves) + expect(assc.macro).to eq :has_many + end +end \ No newline at end of file diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 679dac9e..9801bbd1 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -6,7 +6,8 @@ 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! -require 'rspec/capybara' + +require 'capybara/rspec' require 'capybara/poltergeist' Capybara.javascript_driver = :poltergeist diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d676eab9..9c9c7d0d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,7 @@ # 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