Skip to content

Commit

Permalink
chore(CE): add feedback model (#403)
Browse files Browse the repository at this point in the history
Co-authored-by: afthab vp <[email protected]>
  • Loading branch information
github-actions[bot] and afthabvp authored Oct 8, 2024
1 parent c1494db commit 0737717
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1 deletion.
14 changes: 14 additions & 0 deletions server/app/models/feedback.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

class Feedback < ApplicationRecord
validates :data_app_id, presence: true
validates :visual_component_id, presence: true
validates :model_id, presence: true
validates :reaction, presence: true

belongs_to :data_app
belongs_to :visual_component
belongs_to :model

enum reaction: { positive: 0, negative: 1 }
end
2 changes: 2 additions & 0 deletions server/app/models/visual_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ class VisualComponent < ApplicationRecord
belongs_to :workspace
belongs_to :data_app
belongs_to :model

has_many :feedbacks, dependent: :destroy
end
14 changes: 14 additions & 0 deletions server/db/migrate/20241007070931_create_feedbacks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateFeedbacks < ActiveRecord::Migration[7.1]
def change
create_table :feedbacks do |t|
t.integer :workspace_id, null: false
t.integer :data_app_id, null: false
t.integer :visual_component_id, null: false
t.integer :model_id, null: false
t.integer :reaction, null: false
t.text :feedback_content

t.timestamps
end
end
end
13 changes: 12 additions & 1 deletion server/db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions server/spec/models/feedback_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Feedback, type: :model do
describe "associations" do
it { should belong_to(:data_app) }
it { should belong_to(:visual_component) }
it { should belong_to(:model) }
end

describe "validations" do
it { should validate_presence_of(:data_app_id) }
it { should validate_presence_of(:visual_component_id) }
it { should validate_presence_of(:model_id) }
it { should validate_presence_of(:reaction) }
end

describe "enum" do
it { should define_enum_for(:reaction).with_values(positive: 0, negative: 1) }
end
end
1 change: 1 addition & 0 deletions server/spec/models/visual_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
it { should belong_to(:workspace) }
it { should belong_to(:data_app) }
it { should belong_to(:model) }
it { should have_many(:feedbacks).dependent(:destroy) }
end

0 comments on commit 0737717

Please sign in to comment.