Skip to content

Commit

Permalink
try079
Browse files Browse the repository at this point in the history
Add negative scopes for all enum values
rails/rails#35381
  • Loading branch information
suketa committed Aug 31, 2019
1 parent 3ffee39 commit 915d7db
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 7 deletions.
3 changes: 3 additions & 0 deletions app/models/child.rb
@@ -0,0 +1,3 @@
class Child < ApplicationRecord
enum generation: %i[baby toddler preschool gradeschool teen young_adult]
end
10 changes: 10 additions & 0 deletions db/migrate/20190831005217_create_children.rb
@@ -0,0 +1,10 @@
class CreateChildren < ActiveRecord::Migration[6.0]
def change
create_table :children do |t|
t.string :name
t.integer :generation

t.timestamps
end
end
end
25 changes: 25 additions & 0 deletions db/schema.rb
@@ -0,0 +1,25 @@
# 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.
#
# This file is the source Rails uses to define your schema when running `rails
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_08_31_005217) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "children", force: :cascade do |t|
t.string "name"
t.integer "generation"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

end
14 changes: 7 additions & 7 deletions db/seeds.rb
@@ -1,7 +1,7 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
Child.create(
[
{ name: 'Andy', generation: :baby },
{ name: 'Bob', generation: :toddler },
{ name: 'Cindy', generation: :preschool }
]
)
9 changes: 9 additions & 0 deletions test/fixtures/children.yml
@@ -0,0 +1,9 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
name: MyString
generation: 1

two:
name: MyString
generation: 1
7 changes: 7 additions & 0 deletions test/models/child_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class ChildTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 915d7db

Please sign in to comment.