Skip to content

Commit

Permalink
Add configuration_template column to resource actions
Browse files Browse the repository at this point in the history
  • Loading branch information
bzwei committed Jan 25, 2017
1 parent 0893aaa commit 6cf4ec2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
1 change: 1 addition & 0 deletions app/models/resource_action.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ResourceAction < ApplicationRecord
belongs_to :resource, :polymorphic => true
belongs_to :configuration_template, :polymorphic => true
belongs_to :dialog

serialize :ae_attributes, Hash
Expand Down
3 changes: 2 additions & 1 deletion app/models/resource_action_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ResourceActionSerializer < Serializer
EXCLUDED_ATTRIBUTES = %w(created_at updated_at id dialog_id resource_id)
EXCLUDED_ATTRIBUTES = %w(created_at updated_at id dialog_id resource_id
configuration_template_id configuration_template_type).freeze

def serialize(resource_action)
included_attributes(resource_action.attributes)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddConfigurationTemplateToResourceActions < ActiveRecord::Migration[5.0]
def change
add_column :resource_actions, :configuration_template_id, :bigint
add_column :resource_actions, :configuration_template_type, :string
end
end
2 changes: 2 additions & 0 deletions db/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6221,6 +6221,8 @@ resource_actions:
- ae_instance
- ae_message
- ae_attributes
- configuration_template_id
- configuration_template_type
resource_groups:
- id
- name
Expand Down
21 changes: 5 additions & 16 deletions spec/models/resource_action_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,22 @@
let(:resource_action_serializer) { described_class.new }

describe "#serialize" do
let(:resource_action) do
ResourceAction.new(
:dialog_id => 123,
:resource_id => 321,
:created_at => Time.now,
:updated_at => Time.now,
:resource_type => "DialogField",
:ae_namespace => "Customer/Sample",
:ae_class => "Methods",
:ae_instance => "Testing"
)
end
let(:resource_action) { ResourceAction.new(expected_serialized_values) }

let(:expected_serialized_values) do
{
"action" => nil,
"resource_type" => "DialogField",
"ae_namespace" => "Customer/Sample",
"ae_class" => "Methods",
"ae_instance" => "Testing",
"ae_message" => nil,
"ae_attributes" => {}
}
end

it "serializes the resource_action" do
expect(resource_action_serializer.serialize(resource_action)).to eq(expected_serialized_values)
serialized = resource_action_serializer.serialize(resource_action)
expect(serialized).to have_attributes(expected_serialized_values)
expect(serialized.keys).to include("action", "ae_attributes", "ae_message")
expect(serialized.keys).not_to include(*described_class::EXCLUDED_ATTRIBUTES)
end
end
end

0 comments on commit 6cf4ec2

Please sign in to comment.