Add ConnectedApp model

This commit is contained in:
Maikel Linke
2023-12-13 14:44:19 +11:00
parent ca7b02d3ee
commit 2346f03b6f
4 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
# frozen_string_literal: true
# An enterprise can be connected to other apps.
#
# Here we store keys and links to access the app.
class ConnectedApp < ApplicationRecord
belongs_to :enterprise
end

View File

@@ -0,0 +1,12 @@
# frozen_string_literal: true
class CreateConnectedApps < ActiveRecord::Migration[7.0]
def change
create_table :connected_apps do |t|
t.belongs_to :enterprise, foreign_key: true
t.json :data
t.timestamps
end
end
end

View File

@@ -63,6 +63,14 @@ ActiveRecord::Schema[7.0].define(version: 20231003000823494) do
t.index ["user_id", "action_name", "column_name"], name: "index_column_prefs_on_user_id_and_action_name_and_column_name", unique: true
end
create_table "connected_apps", force: :cascade do |t|
t.bigint "enterprise_id"
t.json "data"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["enterprise_id"], name: "index_connected_apps_on_enterprise_id"
end
create_table "coordinator_fees", id: :serial, force: :cascade do |t|
t.integer "order_cycle_id", null: false
t.integer "enterprise_fee_id", null: false
@@ -1101,6 +1109,7 @@ ActiveRecord::Schema[7.0].define(version: 20231003000823494) do
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "adjustment_metadata", "enterprises", name: "adjustment_metadata_enterprise_id_fk"
add_foreign_key "adjustment_metadata", "spree_adjustments", column: "adjustment_id", name: "adjustment_metadata_adjustment_id_fk", on_delete: :cascade
add_foreign_key "connected_apps", "enterprises"
add_foreign_key "coordinator_fees", "enterprise_fees", name: "coordinator_fees_enterprise_fee_id_fk"
add_foreign_key "coordinator_fees", "order_cycles", name: "coordinator_fees_order_cycle_id_fk"
add_foreign_key "custom_tabs", "enterprises", on_delete: :cascade

View File

@@ -0,0 +1,21 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ConnectedApp, type: :model do
it { is_expected.to belong_to :enterprise }
it "stores data as json hash" do
# This functionality is just Rails and would usually not warrant a spec but
# it's the first time we use the json datatype in this codebase and
# therefore it's a nice example to see how it works.
expect(subject.data).to eq nil
subject.enterprise = create(:enterprise)
subject.data = { link: "https://example.net" }
subject.save!
subject.reload
expect(subject.data).to eq({ "link" => "https://example.net" })
end
end