Skip to content

Commit

Permalink
Try to test issue with optional dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
felipefreitag committed Jul 3, 2020
1 parent 4a2a7ed commit 91838e4
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 1 deletion.
42 changes: 42 additions & 0 deletions spec/todos/notes/index_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

require 'rails_helper'

describe 'GET /notes', type: :request do
subject { response }

let(:project) do
current_user.projects.create! name: 'Foo'
end

let(:list) do
project.lists.create! name: 'Foo'
end

let(:task) do
list.tasks.create! name: 'Foo'
end

let(:assignment) do
task.assignments.create! user: current_user
end

let(:note) do
list.notes.create!(text: 'foo', assignment: assignment)
end

let(:notes) do
list.notes.order(:created_at)
end

context 'with valid request' do
before do
note.update!(assignment: nil)

get "/notes?list_id=#{list.id}"
end

it { is_expected.to have_http_status(:ok) }
it { expect(response.body).to eq_json(notes) }
end
end
10 changes: 10 additions & 0 deletions spec/todos/notes/notes_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Note, type: :model do
it { is_expected.to belong_to(:assignment).optional }
it { is_expected.to belong_to(:list) }
it { is_expected.to validate_presence_of(:text) }
end
13 changes: 13 additions & 0 deletions todos/app/resources/notes/model.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Notes
module Model
extend ActiveSupport::Concern

included do
belongs_to :assignments, optional: true

schema_validations auto_create: false
end
end
end
7 changes: 7 additions & 0 deletions todos/app/resources/notes/resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module Notes
class Resource < ApplicationResource
filter_by :list
end
end
1 change: 1 addition & 0 deletions todos/config/initializers/croods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:lists,
:tasks,
:assignments,
:notes,
multi_tenancy_by: :organization
)

Expand Down
11 changes: 11 additions & 0 deletions todos/db/migrate/20200626135719_create_notes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateNotes < ActiveRecord::Migration[5.2]
def change
create_table :notes do |t|
t.references :assignment
t.references :list, null: false
t.text :text, null: false

t.timestamps
end
end
end
10 changes: 9 additions & 1 deletion todos/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_06_25_150646) do
ActiveRecord::Schema.define(version: 2020_06_26_135719) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -84,4 +84,12 @@
t.datetime "updated_at", :null=>false
end

create_table "notes", force: :cascade do |t|
t.bigint "assignment_id", :foreign_key=>{:references=>"assignments", :name=>"fk_notes_assignment_id", :on_update=>:no_action, :on_delete=>:no_action}, :index=>{:name=>"fk__notes_assignment_id"}
t.bigint "list_id", :null=>false, :foreign_key=>{:references=>"lists", :name=>"fk_notes_list_id", :on_update=>:no_action, :on_delete=>:no_action}, :index=>{:name=>"fk__notes_list_id"}
t.text "text", :null=>false
t.datetime "created_at", :null=>false
t.datetime "updated_at", :null=>false
end

end

0 comments on commit 91838e4

Please sign in to comment.