Commit 641f8081 authored by Florian Hübsch's avatar Florian Hübsch
Browse files

Update collections table, add shared scope on Collection model.

parent 497904be
......@@ -54,6 +54,6 @@ group :development, :test do
end
group :test do
# Factories for testing
gem 'factory_girl_rails'
gem 'database_cleaner'
end
......@@ -70,6 +70,7 @@ GEM
columnize (0.9.0)
connection_pool (2.2.0)
daemons (1.2.2)
database_cleaner (1.3.0)
debug_inspector (0.0.2)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
......@@ -257,6 +258,7 @@ DEPENDENCIES
bootstrap-sass (~> 3.3.5)
browserify-rails
byebug
database_cleaner
devise
factory_girl_rails
grape
......
......@@ -5,6 +5,8 @@ class Collection < ActiveRecord::Base
has_many :collections_samples
has_many :samples, through: :collections_samples
scope :shared, -> { where(is_shared: true) }
def is_all_collection?
label == 'All'
end
......
......@@ -5,6 +5,13 @@ class CreateCollections < ActiveRecord::Migration
t.string :ancestry, index: true
t.text :label, null: false
# permission/sharing specific attributes
t.boolean :is_shared, default: false
t.integer :permission_level
t.integer :sample_detail_level
t.integer :reaction_detail_level
t.integer :wellplate_detail_level
t.timestamps null: false
end
......
......@@ -17,11 +17,16 @@ ActiveRecord::Schema.define(version: 20150728120436) do
enable_extension "plpgsql"
create_table "collections", force: :cascade do |t|
t.integer "user_id", null: false
t.integer "user_id", null: false
t.string "ancestry"
t.text "label", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "label", null: false
t.boolean "is_shared", default: false
t.integer "permission_level"
t.integer "sample_detail_level"
t.integer "reaction_detail_level"
t.integer "wellplate_detail_level"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "collections", ["ancestry"], name: "index_collections_on_ancestry", using: :btree
......
FactoryGirl.define do
factory :collection do
user_id 1
sequence(:label) { |i| "Collection #{i}" }
is_shared false
permission_level 0
sample_detail_level 0
reaction_detail_level 0
wellplate_detail_level 0
end
end
require 'rails_helper'
RSpec.describe Collection, type: :model do
describe 'creation' do
let(:collection) { create(:collection) }
it 'is possible to create a valid collection' do
expect(collection.valid?).to be(true)
end
end
describe 'scopes' do
describe 'shared scope' do
let(:collection_1) { create(:collection, is_shared: false) }
let(:collection_2) { create(:collection, is_shared: true) }
it 'returns shared collections' do
expect(Collection.shared).to match_array [collection_2]
end
end
end
end
......@@ -18,21 +18,10 @@ require 'rspec/rails'
# 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 }
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
RSpec.configure do |config|
# 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.use_transactional_fixtures = false
config.infer_spec_type_from_file_location!
end
# 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.
#
# The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
require 'factory_girl_rails'
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.include FactoryGirl::Syntax::Methods
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
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
# These two settings work together to allow 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.
config.filter_run :focus
config.run_all_when_everything_filtered = true
# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
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
RSpec.configure do |config|
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(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment