-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CE): data app model changes (#353)
Co-authored-by: afthab vp <[email protected]>
- Loading branch information
1 parent
529e56b
commit 50d3e08
Showing
8 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class DataApp < ApplicationRecord | ||
validates :workspace_id, presence: true | ||
validates :status, presence: true | ||
validates :name, presence: true | ||
|
||
enum :status, %i[inactive active draft] | ||
|
||
belongs_to :workspace | ||
has_many :visual_components, dependent: :destroy | ||
has_many :models, through: :visual_components | ||
|
||
after_initialize :set_default_status, if: :new_record? | ||
|
||
private | ||
|
||
def set_default_status | ||
self.status ||= :draft | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class VisualComponent < ApplicationRecord | ||
validates :workspace_id, presence: true | ||
validates :component_type, presence: true | ||
validates :model_id, presence: true | ||
validates :data_app_id, presence: true | ||
|
||
enum :component_type, %i[pie bar data_table] | ||
|
||
belongs_to :workspace | ||
belongs_to :data_app | ||
belongs_to :model | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe DataApp, type: :model do | ||
it { should validate_presence_of(:workspace_id) } | ||
it { should validate_presence_of(:status) } | ||
it { should validate_presence_of(:name) } | ||
|
||
it { should define_enum_for(:status).with_values(inactive: 0, active: 1, draft: 2) } | ||
|
||
it { should belong_to(:workspace) } | ||
it { should have_many(:visual_components).dependent(:destroy) } | ||
it { should have_many(:models).through(:visual_components) } | ||
|
||
describe "#set_default_status" do | ||
let(:data_app) { DataApp.new } | ||
|
||
it "sets default status" do | ||
expect(data_app.status).to eq("draft") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe VisualComponent, type: :model do | ||
it { should validate_presence_of(:workspace_id) } | ||
it { should validate_presence_of(:component_type) } | ||
it { should validate_presence_of(:model_id) } | ||
it { should validate_presence_of(:data_app_id) } | ||
|
||
it { should define_enum_for(:component_type).with_values(pie: 0, bar: 1, data_table: 2) } | ||
|
||
it { should belong_to(:workspace) } | ||
it { should belong_to(:data_app) } | ||
it { should belong_to(:model) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters