diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index 6476a3797..cc0e68ece 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -7,8 +7,8 @@ module Api class IDMismatchError < StandardError; end class IncludeNotSupportedError < StandardError; end class PermissionError < StandardError - attr_reader :klass - attr_reader :mode + attr_reader :klass, :mode + def initialize(klass, mode) @klass = klass @mode = mode diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index b32b561ba..b16712323 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -16,11 +16,11 @@ module Api .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) - render jsonapi: projects, each_serializer: ProjectSerializer + render jsonapi: projects, each_serializer: ProjectSerializer, include: include_params end def show - render jsonapi: @project, serializer: ProjectSerializer + render jsonapi: @project, serializer: ProjectSerializer, include: include_params end def create @@ -64,6 +64,10 @@ module Api params.require(:data).require(:attributes).permit(:name, :visibility, :archived, :project_folder_id) end + def permitted_includes + %w(comments) + end + def load_project_for_managing @project = @team.projects.find(params.require(:id)) raise PermissionError.new(Project, :manage) unless can_manage_project?(@project) diff --git a/app/controllers/api/v1/results_controller.rb b/app/controllers/api/v1/results_controller.rb index b63887ffa..4cd8cbc0d 100644 --- a/app/controllers/api/v1/results_controller.rb +++ b/app/controllers/api/v1/results_controller.rb @@ -12,7 +12,7 @@ module Api .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) render jsonapi: results, each_serializer: ResultSerializer, - include: %i(text table file) + include: (%i(text table file) << include_params).flatten.compact end def create @@ -43,7 +43,7 @@ module Api def show render jsonapi: @result, serializer: ResultSerializer, - include: %i(text table file) + include: (%i(text table file) << include_params).flatten.compact end private @@ -185,6 +185,10 @@ module Api prms end + def permitted_includes + %w(comments) + end + def convert_old_tiny_mce_format(text) text.scan(/\[~tiny_mce_id:(\w+)\]/).flatten.each do |token| old_format = /\[~tiny_mce_id:#{token}\]/ diff --git a/app/controllers/api/v1/tasks_controller.rb b/app/controllers/api/v1/tasks_controller.rb index 635082f88..79ddc02d2 100644 --- a/app/controllers/api/v1/tasks_controller.rb +++ b/app/controllers/api/v1/tasks_controller.rb @@ -20,11 +20,17 @@ module Api .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) - render jsonapi: tasks, each_serializer: TaskSerializer, rte_rendering: render_rte?, team: @team + render jsonapi: tasks, each_serializer: TaskSerializer, + include: include_params, + rte_rendering: render_rte?, + team: @team end def show - render jsonapi: @task, serializer: TaskSerializer, rte_rendering: render_rte?, team: @team + render jsonapi: @task, serializer: TaskSerializer, + include: include_params, + rte_rendering: render_rte?, + team: @team end def create @@ -69,6 +75,10 @@ module Api params.require(:data).require(:attributes).permit(%i(name x y description my_module_status_id)) end + def permitted_includes + %w(comments) + end + def load_task_for_managing @task = @experiment.my_modules.find(params.require(:id)) raise PermissionError.new(MyModule, :manage) unless can_manage_module?(@task) diff --git a/app/serializers/api/v1/activity_serializer.rb b/app/serializers/api/v1/activity_serializer.rb index 63e8af7c9..8f057a86b 100644 --- a/app/serializers/api/v1/activity_serializer.rb +++ b/app/serializers/api/v1/activity_serializer.rb @@ -19,6 +19,8 @@ module Api belongs_to :subject, polymorphic: true belongs_to :owner, key: :user, serializer: UserSerializer + include TimestampableModel + def message if object.old_activity? object.message diff --git a/app/serializers/api/v1/asset_serializer.rb b/app/serializers/api/v1/asset_serializer.rb index ffa66a937..13edf402d 100644 --- a/app/serializers/api/v1/asset_serializer.rb +++ b/app/serializers/api/v1/asset_serializer.rb @@ -9,6 +9,8 @@ module Api attributes :id, :file_name, :file_size, :file_type, :file_url belongs_to :step, serializer: StepSerializer + include TimestampableModel + def file_type object.content_type end diff --git a/app/serializers/api/v1/checklist_item_serializer.rb b/app/serializers/api/v1/checklist_item_serializer.rb index d159c01fe..9cadb8a18 100644 --- a/app/serializers/api/v1/checklist_item_serializer.rb +++ b/app/serializers/api/v1/checklist_item_serializer.rb @@ -5,6 +5,8 @@ module Api class ChecklistItemSerializer < ActiveModel::Serializer type :checklist_items attributes :id, :text, :checked, :position + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/checklist_serializer.rb b/app/serializers/api/v1/checklist_serializer.rb index dd2cc98f2..e46da85fd 100644 --- a/app/serializers/api/v1/checklist_serializer.rb +++ b/app/serializers/api/v1/checklist_serializer.rb @@ -6,6 +6,8 @@ module Api type :checklists attributes :id, :name has_many :checklist_items, serializer: ChecklistItemSerializer + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/comment_serializer.rb b/app/serializers/api/v1/comment_serializer.rb index d369d339c..e53d0c708 100644 --- a/app/serializers/api/v1/comment_serializer.rb +++ b/app/serializers/api/v1/comment_serializer.rb @@ -26,6 +26,8 @@ module Api serializer: ResultSerializer, if: -> { object.class == ResultComment && !instance_options[:hide_result] } + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/connection_serializer.rb b/app/serializers/api/v1/connection_serializer.rb index 143f440e9..1860f2f88 100644 --- a/app/serializers/api/v1/connection_serializer.rb +++ b/app/serializers/api/v1/connection_serializer.rb @@ -11,6 +11,8 @@ module Api belongs_to :to, key: :output_task, serializer: TaskSerializer, class_name: 'MyModule' + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/experiment_serializer.rb b/app/serializers/api/v1/experiment_serializer.rb index bff94ffc1..61660cb2f 100644 --- a/app/serializers/api/v1/experiment_serializer.rb +++ b/app/serializers/api/v1/experiment_serializer.rb @@ -5,6 +5,8 @@ module Api class ExperimentSerializer < ActiveModel::Serializer type :experiments attributes :id, :name, :description, :archived + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/inventory_cell_serializer.rb b/app/serializers/api/v1/inventory_cell_serializer.rb index 27c617581..629f9a706 100644 --- a/app/serializers/api/v1/inventory_cell_serializer.rb +++ b/app/serializers/api/v1/inventory_cell_serializer.rb @@ -7,6 +7,8 @@ module Api attributes :id, :value_type, :value attribute :repository_column_id, key: :column_id + include TimestampableModel + def value ActiveModelSerializers::SerializableResource.new( object.value, diff --git a/app/serializers/api/v1/inventory_checklist_item_serializer.rb b/app/serializers/api/v1/inventory_checklist_item_serializer.rb index 6054b30ea..79aa77121 100644 --- a/app/serializers/api/v1/inventory_checklist_item_serializer.rb +++ b/app/serializers/api/v1/inventory_checklist_item_serializer.rb @@ -5,6 +5,8 @@ module Api class InventoryChecklistItemSerializer < ActiveModel::Serializer type :inventory_checklist_items attributes :id, :data + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/inventory_column_serializer.rb b/app/serializers/api/v1/inventory_column_serializer.rb index 3f6ad2d75..1f99332b3 100644 --- a/app/serializers/api/v1/inventory_column_serializer.rb +++ b/app/serializers/api/v1/inventory_column_serializer.rb @@ -30,6 +30,8 @@ module Api !instance_options[:hide_list_items] end) + include TimestampableModel + def data_type Extends::API_REPOSITORY_DATA_TYPE_MAPPINGS[object.data_type] end diff --git a/app/serializers/api/v1/inventory_item_serializer.rb b/app/serializers/api/v1/inventory_item_serializer.rb index 37d3db1f2..9864a2078 100644 --- a/app/serializers/api/v1/inventory_item_serializer.rb +++ b/app/serializers/api/v1/inventory_item_serializer.rb @@ -13,6 +13,8 @@ module Api serializer: InventorySerializer, class_name: 'Repository', if: -> { instance_options[:show_repository] } + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/inventory_list_item_serializer.rb b/app/serializers/api/v1/inventory_list_item_serializer.rb index 6220983f4..4c5bc7e3c 100644 --- a/app/serializers/api/v1/inventory_list_item_serializer.rb +++ b/app/serializers/api/v1/inventory_list_item_serializer.rb @@ -5,6 +5,8 @@ module Api class InventoryListItemSerializer < ActiveModel::Serializer type :inventory_list_items attribute :data + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/inventory_serializer.rb b/app/serializers/api/v1/inventory_serializer.rb index 88752ecf3..71ace83f0 100644 --- a/app/serializers/api/v1/inventory_serializer.rb +++ b/app/serializers/api/v1/inventory_serializer.rb @@ -6,6 +6,8 @@ module Api type :inventories attributes :id, :name belongs_to :created_by, serializer: UserSerializer + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/inventory_status_item_serializer.rb b/app/serializers/api/v1/inventory_status_item_serializer.rb index fdc86869c..228bd3ba4 100644 --- a/app/serializers/api/v1/inventory_status_item_serializer.rb +++ b/app/serializers/api/v1/inventory_status_item_serializer.rb @@ -5,6 +5,8 @@ module Api class InventoryStatusItemSerializer < ActiveModel::Serializer type :inventory_status_items attributes :status, :icon + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/project_folder_serializer.rb b/app/serializers/api/v1/project_folder_serializer.rb index a78e2a35c..764ce8f05 100644 --- a/app/serializers/api/v1/project_folder_serializer.rb +++ b/app/serializers/api/v1/project_folder_serializer.rb @@ -10,6 +10,8 @@ module Api belongs_to :parent_folder, serializer: ProjectFolderSerializer has_many :projects, serializer: ProjectSerializer has_many :project_folders, serializer: ProjectFolderSerializer + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/project_serializer.rb b/app/serializers/api/v1/project_serializer.rb index 90d4ae054..dc9b3c795 100644 --- a/app/serializers/api/v1/project_serializer.rb +++ b/app/serializers/api/v1/project_serializer.rb @@ -7,6 +7,9 @@ module Api attributes :name, :visibility, :start_date, :archived belongs_to :project_folder, serializer: ProjectFolderSerializer + has_many :project_comments, key: :comments, serializer: CommentSerializer + + include TimestampableModel def start_date object.created_at diff --git a/app/serializers/api/v1/protocol_keyword_serializer.rb b/app/serializers/api/v1/protocol_keyword_serializer.rb index 1f8f838d6..096519535 100644 --- a/app/serializers/api/v1/protocol_keyword_serializer.rb +++ b/app/serializers/api/v1/protocol_keyword_serializer.rb @@ -5,6 +5,8 @@ module Api class ProtocolKeywordSerializer < ActiveModel::Serializer type :protocol_keywords attributes :id, :name + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/protocol_serializer.rb b/app/serializers/api/v1/protocol_serializer.rb index 69dbeda20..97df41546 100644 --- a/app/serializers/api/v1/protocol_serializer.rb +++ b/app/serializers/api/v1/protocol_serializer.rb @@ -17,6 +17,8 @@ module Api has_many :steps, serializer: StepSerializer, if: -> { object.steps.any? } belongs_to :parent, serializer: ProtocolSerializer, if: -> { object.parent.present? } + include TimestampableModel + def description if instance_options[:rte_rendering] custom_auto_link(object.tinymce_render(:description), diff --git a/app/serializers/api/v1/report_serializer.rb b/app/serializers/api/v1/report_serializer.rb index 487fea145..870a05230 100644 --- a/app/serializers/api/v1/report_serializer.rb +++ b/app/serializers/api/v1/report_serializer.rb @@ -15,6 +15,8 @@ module Api belongs_to :project, serializer: ProjectSerializer, unless: -> { instance_options[:hide_project] } + include TimestampableModel + def pdf_file_size object.pdf_file.blob.byte_size end diff --git a/app/serializers/api/v1/repository_asset_value_serializer.rb b/app/serializers/api/v1/repository_asset_value_serializer.rb index b55e08664..f946a9e0f 100644 --- a/app/serializers/api/v1/repository_asset_value_serializer.rb +++ b/app/serializers/api/v1/repository_asset_value_serializer.rb @@ -5,6 +5,8 @@ module Api class RepositoryAssetValueSerializer < ActiveModel::Serializer attributes :file_id, :file_name, :file_size, :url + include TimestampableModel + def file_id object.asset&.id end diff --git a/app/serializers/api/v1/repository_checklist_value_serializer.rb b/app/serializers/api/v1/repository_checklist_value_serializer.rb index c881a5288..f340c5467 100644 --- a/app/serializers/api/v1/repository_checklist_value_serializer.rb +++ b/app/serializers/api/v1/repository_checklist_value_serializer.rb @@ -9,6 +9,8 @@ module Api attribute :inventory_checklist_item_names do object.repository_checklist_items.pluck(:data) end + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/repository_date_range_value_serializer.rb b/app/serializers/api/v1/repository_date_range_value_serializer.rb index 7b86c7a62..23372a99b 100644 --- a/app/serializers/api/v1/repository_date_range_value_serializer.rb +++ b/app/serializers/api/v1/repository_date_range_value_serializer.rb @@ -5,6 +5,8 @@ module Api class RepositoryDateRangeValueSerializer < ActiveModel::Serializer attribute :date_range + include TimestampableModel + def date_range { from: object.start_time.to_date, diff --git a/app/serializers/api/v1/repository_date_time_range_value_serializer.rb b/app/serializers/api/v1/repository_date_time_range_value_serializer.rb index e346a70f5..9d48273af 100644 --- a/app/serializers/api/v1/repository_date_time_range_value_serializer.rb +++ b/app/serializers/api/v1/repository_date_time_range_value_serializer.rb @@ -5,6 +5,8 @@ module Api class RepositoryDateTimeRangeValueSerializer < ActiveModel::Serializer attribute :date_time_range + include TimestampableModel + def date_time_range { from: object.start_time, diff --git a/app/serializers/api/v1/repository_date_time_value_serializer.rb b/app/serializers/api/v1/repository_date_time_value_serializer.rb index be9414cdf..4921be6bb 100644 --- a/app/serializers/api/v1/repository_date_time_value_serializer.rb +++ b/app/serializers/api/v1/repository_date_time_value_serializer.rb @@ -5,6 +5,8 @@ module Api class RepositoryDateTimeValueSerializer < ActiveModel::Serializer attribute :date_time + include TimestampableModel + def date_time object.data end diff --git a/app/serializers/api/v1/repository_date_value_serializer.rb b/app/serializers/api/v1/repository_date_value_serializer.rb index 4ec81dd1e..50b9b3330 100644 --- a/app/serializers/api/v1/repository_date_value_serializer.rb +++ b/app/serializers/api/v1/repository_date_value_serializer.rb @@ -5,6 +5,8 @@ module Api class RepositoryDateValueSerializer < ActiveModel::Serializer attribute :date + include TimestampableModel + def date object.data.to_date end diff --git a/app/serializers/api/v1/repository_list_value_serializer.rb b/app/serializers/api/v1/repository_list_value_serializer.rb index a073ca300..bd02fad0d 100644 --- a/app/serializers/api/v1/repository_list_value_serializer.rb +++ b/app/serializers/api/v1/repository_list_value_serializer.rb @@ -5,6 +5,8 @@ module Api class RepositoryListValueSerializer < ActiveModel::Serializer attribute :repository_list_item_id, key: :inventory_list_item_id attribute :formatted, key: :inventory_list_item_name + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/repository_status_value_serializer.rb b/app/serializers/api/v1/repository_status_value_serializer.rb index 21b2ca2f7..a1d26af50 100644 --- a/app/serializers/api/v1/repository_status_value_serializer.rb +++ b/app/serializers/api/v1/repository_status_value_serializer.rb @@ -10,6 +10,8 @@ module Api attribute :inventory_status_item_name do object.repository_status_item.status end + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/repository_text_value_serializer.rb b/app/serializers/api/v1/repository_text_value_serializer.rb index 62dab6b2b..b577dc778 100644 --- a/app/serializers/api/v1/repository_text_value_serializer.rb +++ b/app/serializers/api/v1/repository_text_value_serializer.rb @@ -4,6 +4,8 @@ module Api module V1 class RepositoryTextValueSerializer < ActiveModel::Serializer attribute :formatted, key: :text + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/repository_time_range_value_serializer.rb b/app/serializers/api/v1/repository_time_range_value_serializer.rb index 3be5d79d7..447aad8d4 100644 --- a/app/serializers/api/v1/repository_time_range_value_serializer.rb +++ b/app/serializers/api/v1/repository_time_range_value_serializer.rb @@ -5,6 +5,8 @@ module Api class RepositoryTimeRangeValueSerializer < ActiveModel::Serializer attribute :time_range + include TimestampableModel + def time_range { from: object.start_time.strftime('%H:%M:%S.%3NZ'), diff --git a/app/serializers/api/v1/repository_time_value_serializer.rb b/app/serializers/api/v1/repository_time_value_serializer.rb index a98a3cbed..0babd918b 100644 --- a/app/serializers/api/v1/repository_time_value_serializer.rb +++ b/app/serializers/api/v1/repository_time_value_serializer.rb @@ -5,6 +5,8 @@ module Api class RepositoryTimeValueSerializer < ActiveModel::Serializer attribute :time + include TimestampableModel + def time object.data.strftime('%H:%M:%S.%3NZ') end diff --git a/app/serializers/api/v1/result_serializer.rb b/app/serializers/api/v1/result_serializer.rb index ea0f4b334..bf042a40d 100644 --- a/app/serializers/api/v1/result_serializer.rb +++ b/app/serializers/api/v1/result_serializer.rb @@ -18,6 +18,9 @@ module Api serializer: ResultAssetSerializer, class_name: 'ResultAsset', if: -> { object.is_asset } + has_many :result_comments, key: :comments, serializer: CommentSerializer + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/step_serializer.rb b/app/serializers/api/v1/step_serializer.rb index a6aae74dd..7e109f29d 100644 --- a/app/serializers/api/v1/step_serializer.rb +++ b/app/serializers/api/v1/step_serializer.rb @@ -8,7 +8,7 @@ module Api include InputSanitizeHelper type :steps - attributes :id, :name, :description, :created_at, :position, :completed + attributes :id, :name, :description, :position, :completed attribute :completed_on, if: -> { object.completed? } belongs_to :user, serializer: UserSerializer belongs_to :protocol, serializer: ProtocolSerializer @@ -17,6 +17,8 @@ module Api has_many :tables, serializer: TableSerializer has_many :step_comments, key: :comments, serializer: CommentSerializer + include TimestampableModel + def description if instance_options[:rte_rendering] custom_auto_link(object.tinymce_render(:description), diff --git a/app/serializers/api/v1/table_serializer.rb b/app/serializers/api/v1/table_serializer.rb index f969bf032..ee5dc474a 100644 --- a/app/serializers/api/v1/table_serializer.rb +++ b/app/serializers/api/v1/table_serializer.rb @@ -6,6 +6,8 @@ module Api type :tables attributes :id, :name, :contents + include TimestampableModel + def contents object.contents&.force_encoding(Encoding::UTF_8) end diff --git a/app/serializers/api/v1/tag_serializer.rb b/app/serializers/api/v1/tag_serializer.rb index d30f92ade..45b08d977 100644 --- a/app/serializers/api/v1/tag_serializer.rb +++ b/app/serializers/api/v1/tag_serializer.rb @@ -5,6 +5,8 @@ module Api class TagSerializer < ActiveModel::Serializer type :tags attributes :id, :name, :color + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/task_group_serializer.rb b/app/serializers/api/v1/task_group_serializer.rb index 2b7579e8f..92806a487 100644 --- a/app/serializers/api/v1/task_group_serializer.rb +++ b/app/serializers/api/v1/task_group_serializer.rb @@ -9,6 +9,8 @@ module Api serializer: TaskSerializer, class_name: 'MyModule', unless: -> { object.my_modules.empty? } + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/task_serializer.rb b/app/serializers/api/v1/task_serializer.rb index cf99f2535..67df9dc10 100644 --- a/app/serializers/api/v1/task_serializer.rb +++ b/app/serializers/api/v1/task_serializer.rb @@ -16,6 +16,9 @@ module Api has_many :input_tasks, key: :inputs, serializer: TaskSerializer, class_name: 'MyModule' + has_many :task_comments, key: :comments, serializer: CommentSerializer + + include TimestampableModel def status_id object.my_module_status_id diff --git a/app/serializers/api/v1/team_serializer.rb b/app/serializers/api/v1/team_serializer.rb index 225d1a6e2..5d820e15e 100644 --- a/app/serializers/api/v1/team_serializer.rb +++ b/app/serializers/api/v1/team_serializer.rb @@ -6,6 +6,8 @@ module Api attributes :id, :name, :description, :space_taken belongs_to :created_by, serializer: UserSerializer + include TimestampableModel + def space_taken object.storage_used.to_i end diff --git a/app/serializers/api/v1/user_identity_serializer.rb b/app/serializers/api/v1/user_identity_serializer.rb index 137596bd4..19e3597e6 100644 --- a/app/serializers/api/v1/user_identity_serializer.rb +++ b/app/serializers/api/v1/user_identity_serializer.rb @@ -2,6 +2,8 @@ module Api module V1 class UserIdentitySerializer < ActiveModel::Serializer attributes :provider, :uid + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/user_project_serializer.rb b/app/serializers/api/v1/user_project_serializer.rb index e2e138232..d809f3520 100644 --- a/app/serializers/api/v1/user_project_serializer.rb +++ b/app/serializers/api/v1/user_project_serializer.rb @@ -5,8 +5,9 @@ module Api class UserProjectSerializer < ActiveModel::Serializer type :user_projects attributes :id, :role - belongs_to :user, serializer: UserSerializer + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/user_serializer.rb b/app/serializers/api/v1/user_serializer.rb index 22c3f262d..e397b76c2 100644 --- a/app/serializers/api/v1/user_serializer.rb +++ b/app/serializers/api/v1/user_serializer.rb @@ -9,6 +9,8 @@ module Api attribute :avatar_file_size, if: -> { object.avatar.attached? } attribute :avatar_url, if: -> { object.avatar.attached? } + include TimestampableModel + def avatar_file_name object.avatar.blob.filename end diff --git a/app/serializers/api/v1/workflow_serializer.rb b/app/serializers/api/v1/workflow_serializer.rb index 8488ceb4c..53d7bab25 100644 --- a/app/serializers/api/v1/workflow_serializer.rb +++ b/app/serializers/api/v1/workflow_serializer.rb @@ -4,8 +4,9 @@ module Api module V1 class WorkflowSerializer < ActiveModel::Serializer type :workflows - attributes :id, :name, :description, :visibility, :team_id + + include TimestampableModel end end end diff --git a/app/serializers/api/v1/workflow_status_serializer.rb b/app/serializers/api/v1/workflow_status_serializer.rb index a20e8fa49..ead7f523b 100644 --- a/app/serializers/api/v1/workflow_status_serializer.rb +++ b/app/serializers/api/v1/workflow_status_serializer.rb @@ -4,8 +4,9 @@ module Api module V1 class WorkflowStatusSerializer < ActiveModel::Serializer type :workflow_statuses - attributes :id, :name, :description, :color, :previous_status_id + + include TimestampableModel end end end diff --git a/app/serializers/concerns/timestampable_model.rb b/app/serializers/concerns/timestampable_model.rb new file mode 100644 index 000000000..5e7be9316 --- /dev/null +++ b/app/serializers/concerns/timestampable_model.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module TimestampableModel + extend ActiveSupport::Concern + + included do + attributes :created_at, :updated_at + end +end diff --git a/spec/requests/api/v1/experiments_controller_spec.rb b/spec/requests/api/v1/experiments_controller_spec.rb index b9a88fa14..a1a36f283 100644 --- a/spec/requests/api/v1/experiments_controller_spec.rb +++ b/spec/requests/api/v1/experiments_controller_spec.rb @@ -32,10 +32,12 @@ RSpec.describe "Api::V1::ExperimentsController", type: :request do project_id: @valid_project), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_project.experiments, - each_serializer: Api::V1::ExperimentSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_project.experiments, + each_serializer: Api::V1::ExperimentSerializer) + .to_json + )['data'] ) end @@ -75,10 +77,12 @@ RSpec.describe "Api::V1::ExperimentsController", type: :request do headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( + JSON.parse( ActiveModelSerializers::SerializableResource .new(@valid_project.experiments.first, serializer: Api::V1::ExperimentSerializer) - .as_json[:data] + .to_json + )['data'] ) end diff --git a/spec/requests/api/v1/inventories_controller_spec.rb b/spec/requests/api/v1/inventories_controller_spec.rb index a71ec6b65..ae29e011b 100644 --- a/spec/requests/api/v1/inventories_controller_spec.rb +++ b/spec/requests/api/v1/inventories_controller_spec.rb @@ -31,10 +31,11 @@ RSpec.describe 'Api::V1::InventoriesController', type: :request do headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@teams.first.repositories, - each_serializer: Api::V1::InventorySerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@teams.first.repositories, each_serializer: Api::V1::InventorySerializer) + .to_json + )['data'] ) end @@ -72,10 +73,11 @@ RSpec.describe 'Api::V1::InventoriesController', type: :request do expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@teams.first.repositories.first, - serializer: Api::V1::InventorySerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@teams.first.repositories.first, serializer: Api::V1::InventorySerializer) + .to_json + )['data'] ) end @@ -127,10 +129,10 @@ RSpec.describe 'Api::V1::InventoriesController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(Repository.last, - serializer: Api::V1::InventorySerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource.new(Repository.last, serializer: Api::V1::InventorySerializer) + .to_json + )['data'] ) end @@ -222,7 +224,7 @@ RSpec.describe 'Api::V1::InventoriesController', type: :request do headers: @valid_headers expect(response).to have_http_status 200 expect { hash_body = json }.not_to raise_exception - expect(hash_body.to_json).to match(updated_inventory.to_json) + expect(hash_body['data']['attributes']['name']).to match(updated_inventory[:data][:attributes][:name]) end it 'When invalid request, inventory does not belong to team' do diff --git a/spec/requests/api/v1/inventory_cells_controller_spec.rb b/spec/requests/api/v1/inventory_cells_controller_spec.rb index 89d0cd2ea..aca76209d 100644 --- a/spec/requests/api/v1/inventory_cells_controller_spec.rb +++ b/spec/requests/api/v1/inventory_cells_controller_spec.rb @@ -413,10 +413,11 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_item.repository_cells.first, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_item.repository_cells.first, serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -459,10 +460,11 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryCell.last, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryCell.last, serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -477,10 +479,11 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryCell.last, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryCell.last, serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -495,10 +498,11 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryCell.last, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryCell.last, serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -513,10 +517,11 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryCell.last, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryCell.last, serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -531,10 +536,11 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryCell.last, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryCell.last, serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -568,10 +574,11 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryCell.last, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryCell.last, serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -586,10 +593,11 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryCell.last, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryCell.last, serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -623,10 +631,11 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryCell.last, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryCell.last, serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -641,10 +650,11 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryCell.last, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryCell.last, serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -659,10 +669,11 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryCell.last, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryCell.last, serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -677,10 +688,11 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryCell.last, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryCell.last, serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -748,10 +760,12 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 200 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_item.repository_cells.where(repository_column: @text_column).first, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_item.repository_cells.where(repository_column: @text_column).first, + serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -766,10 +780,12 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 200 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_item.repository_cells.where(repository_column: @list_column).first, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_item.repository_cells.where(repository_column: @list_column).first, + serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -784,10 +800,12 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 200 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_item.repository_cells.where(repository_column: @status_column).first, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_item.repository_cells.where(repository_column: @status_column).first, + serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -803,10 +821,12 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 200 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_item.repository_cells.where(repository_column: @checklist_column).first, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_item.repository_cells.where(repository_column: @checklist_column).first, + serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -821,10 +841,12 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 200 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_item.repository_cells.where(repository_column: @file_column).first, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_item.repository_cells.where(repository_column: @file_column).first, + serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -859,10 +881,12 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 200 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_item.repository_cells.where(repository_column: @time_column).first, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_item.repository_cells.where(repository_column: @time_column).first, + serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -917,10 +941,12 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 200 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_item.repository_cells.where(repository_column: @time_range_column).first, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_item.repository_cells.where(repository_column: @time_range_column).first, + serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -935,10 +961,12 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 200 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_item.repository_cells.where(repository_column: @date_time_range_column).first, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_item.repository_cells.where(repository_column: @date_time_range_column).first, + serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -953,10 +981,12 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 200 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_item.repository_cells.where(repository_column: @number_column).first, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_item.repository_cells.where(repository_column: @number_column).first, + serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end @@ -971,10 +1001,12 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do expect(response).to have_http_status 200 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_item.repository_cells.where(repository_column: @number_column).first, - serializer: Api::V1::InventoryCellSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_item.repository_cells.where(repository_column: @number_column).first, + serializer: Api::V1::InventoryCellSerializer) + .to_json + )['data'] ) end diff --git a/spec/requests/api/v1/inventory_checklist_items_controller_spec.rb b/spec/requests/api/v1/inventory_checklist_items_controller_spec.rb index 4287d82b5..0e7d8082b 100644 --- a/spec/requests/api/v1/inventory_checklist_items_controller_spec.rb +++ b/spec/requests/api/v1/inventory_checklist_items_controller_spec.rb @@ -41,10 +41,12 @@ RSpec.describe 'Api::V1::InventoryChecklistItemsController', type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@checklist_column.repository_checklist_items.limit(10), - each_serializer: Api::V1::InventoryChecklistItemSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@checklist_column.repository_checklist_items.limit(10), + each_serializer: Api::V1::InventoryChecklistItemSerializer) + .to_json + )['data'] ) end @@ -108,10 +110,12 @@ RSpec.describe 'Api::V1::InventoryChecklistItemsController', type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@checklist_column.repository_checklist_items.first, - serializer: Api::V1::InventoryChecklistItemSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@checklist_column.repository_checklist_items.first, + serializer: Api::V1::InventoryChecklistItemSerializer) + .to_json + )['data'] ) end @@ -163,10 +167,11 @@ RSpec.describe 'Api::V1::InventoryChecklistItemsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryChecklistItem.last, - serializer: Api::V1::InventoryChecklistItemSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryChecklistItem.last, serializer: Api::V1::InventoryChecklistItemSerializer) + .to_json + )['data'] ) end @@ -273,10 +278,12 @@ RSpec.describe 'Api::V1::InventoryChecklistItemsController', type: :request do expect(response).to have_http_status 200 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@checklist_column.repository_checklist_items.find(item_id), - serializer: Api::V1::InventoryChecklistItemSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@checklist_column.repository_checklist_items.find(item_id), + serializer: Api::V1::InventoryChecklistItemSerializer) + .to_json + )['data'] ) expect(@checklist_column.repository_checklist_items.find(item_id).data).to match('Updated') end diff --git a/spec/requests/api/v1/inventory_columns_controller_spec.rb b/spec/requests/api/v1/inventory_columns_controller_spec.rb index e926cfa18..18dda5415 100644 --- a/spec/requests/api/v1/inventory_columns_controller_spec.rb +++ b/spec/requests/api/v1/inventory_columns_controller_spec.rb @@ -40,11 +40,13 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_inventory.repository_columns.limit(10), - each_serializer: Api::V1::InventoryColumnSerializer, - hide_list_items: true) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_inventory.repository_columns.limit(10), + each_serializer: Api::V1::InventoryColumnSerializer, + hide_list_items: true) + .to_json + )['data'] ) end @@ -93,10 +95,11 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(text_column, - serializer: Api::V1::InventoryColumnSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(text_column, serializer: Api::V1::InventoryColumnSerializer) + .to_json + )['data'] ) expect(hash_body[:data]).not_to include('relationships') end @@ -111,18 +114,21 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(list_column, - serializer: Api::V1::InventoryColumnSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(list_column, serializer: Api::V1::InventoryColumnSerializer) + .to_json + )['data'] ) expect(hash_body[:data]).to include('relationships') expect(hash_body[:included]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_inventory.repository_columns.limit(10), - each_serializer: Api::V1::InventoryColumnSerializer, - include: :inventory_list_items) - .as_json[:included] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_inventory.repository_columns.limit(10), + each_serializer: Api::V1::InventoryColumnSerializer, + include: :inventory_list_items) + .to_json + )['included'] ) end @@ -136,18 +142,21 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(status_column, - serializer: Api::V1::InventoryColumnSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(status_column, serializer: Api::V1::InventoryColumnSerializer) + .to_json + )['data'] ) expect(hash_body[:data]).to include('relationships') expect(hash_body[:included]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_inventory.repository_columns.limit(10), - each_serializer: Api::V1::InventoryColumnSerializer, - include: :inventory_status_items) - .as_json[:included] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_inventory.repository_columns.limit(10), + each_serializer: Api::V1::InventoryColumnSerializer, + include: :inventory_status_items) + .to_json + )['included'] ) end @@ -161,10 +170,11 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(file_column, - serializer: Api::V1::InventoryColumnSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(file_column, serializer: Api::V1::InventoryColumnSerializer) + .to_json + )['data'] ) expect(hash_body[:data]).not_to include('relationships') end @@ -221,11 +231,11 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryColumn.last, - serializer: Api::V1::InventoryColumnSerializer, - include: :inventory_cells) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryColumn.last, serializer: Api::V1::InventoryColumnSerializer, include: :inventory_cells) + .to_json + )['data'] ) end @@ -397,7 +407,7 @@ RSpec.describe 'Api::V1::InventoryColumnsController', type: :request do headers: @valid_headers expect(response).to have_http_status 200 expect { hash_body = json }.not_to raise_exception - expect(hash_body.to_json).to match(returned_inventory_column.to_json) + expect(hash_body['data']['attributes']['name']).to match(returned_inventory_column[:data][:attributes][:name]) end it 'Invalid request, wrong team' do diff --git a/spec/requests/api/v1/inventory_items_controller_spec.rb b/spec/requests/api/v1/inventory_items_controller_spec.rb index 553ae8bf0..a6a8a7a3d 100644 --- a/spec/requests/api/v1/inventory_items_controller_spec.rb +++ b/spec/requests/api/v1/inventory_items_controller_spec.rb @@ -68,11 +68,13 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_inventory.repository_rows.limit(10), - each_serializer: Api::V1::InventoryItemSerializer, - include: :inventory_cells) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_inventory.repository_rows.limit(10), + each_serializer: Api::V1::InventoryItemSerializer, + include: :inventory_cells) + .to_json + )['data'] ) expect(hash_body).not_to include('included') end @@ -86,18 +88,22 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_inventory.repository_rows.limit(10), - each_serializer: Api::V1::InventoryItemSerializer, - include: :inventory_cells) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_inventory.repository_rows.limit(10), + each_serializer: Api::V1::InventoryItemSerializer, + include: :inventory_cells) + .to_json + )['data'] ) expect(hash_body[:included]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_inventory.repository_rows.limit(10), - each_serializer: Api::V1::InventoryItemSerializer, - include: :inventory_cells) - .as_json[:included] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_inventory.repository_rows.limit(10), + each_serializer: Api::V1::InventoryItemSerializer, + include: :inventory_cells) + .to_json + )['included'] ) end @@ -109,11 +115,13 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do ), params: { page: { size: 100 } }, headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_inventory.repository_rows.limit(100), - each_serializer: Api::V1::InventoryItemSerializer, - include: :inventory_cells) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_inventory.repository_rows.limit(100), + each_serializer: Api::V1::InventoryItemSerializer, + include: :inventory_cells) + .to_json + )['data'] ) expect(hash_body).not_to include('included') end @@ -227,18 +235,18 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryRow.last, - serializer: Api::V1::InventoryItemSerializer, - include: :inventory_cells) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryRow.last, serializer: Api::V1::InventoryItemSerializer, include: :inventory_cells) + .to_json + )['data'] ) expect(hash_body[:included]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryRow.last, - serializer: Api::V1::InventoryItemSerializer, - include: :inventory_cells) - .as_json[:included] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryRow.last, serializer: Api::V1::InventoryItemSerializer, include: :inventory_cells) + .to_json + )['included'] ) end @@ -288,8 +296,8 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do it 'Response with correctly updated inventory item for name field' do hash_body = nil - updated_inventory_item = @inventory_item.as_json[:data] - updated_inventory_item[:attributes][:name] = Faker::Name.unique.name + updated_inventory_item = JSON.parse(@inventory_item.to_json)['data'] + updated_inventory_item['attributes']['name'] = Faker::Name.unique.name patch api_v1_team_inventory_item_path( id: RepositoryRow.last.id, team_id: @teams.first.id, @@ -298,7 +306,7 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do headers: @valid_headers expect(response).to have_http_status 200 expect { hash_body = json }.not_to raise_exception - expect(hash_body[:data].to_json).to match(updated_inventory_item.to_json) + expect(hash_body['data']['attributes']['name']).to match(updated_inventory_item['attributes']['name']) end end end diff --git a/spec/requests/api/v1/inventory_list_items_controller_spec.rb b/spec/requests/api/v1/inventory_list_items_controller_spec.rb index c3ee56b38..43e3d0ef3 100644 --- a/spec/requests/api/v1/inventory_list_items_controller_spec.rb +++ b/spec/requests/api/v1/inventory_list_items_controller_spec.rb @@ -41,10 +41,11 @@ RSpec.describe 'Api::V1::InventoryListItemsController', type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@list_column.repository_list_items.limit(10), - each_serializer: Api::V1::InventoryListItemSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@list_column.repository_list_items.limit(10), each_serializer: Api::V1::InventoryListItemSerializer) + .to_json + )['data'] ) end @@ -108,10 +109,11 @@ RSpec.describe 'Api::V1::InventoryListItemsController', type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@list_column.repository_list_items.first, - serializer: Api::V1::InventoryListItemSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@list_column.repository_list_items.first, serializer: Api::V1::InventoryListItemSerializer) + .to_json + )['data'] ) end @@ -163,10 +165,11 @@ RSpec.describe 'Api::V1::InventoryListItemsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(RepositoryListItem.last, - serializer: Api::V1::InventoryListItemSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(RepositoryListItem.last, serializer: Api::V1::InventoryListItemSerializer) + .to_json + )['data'] ) end @@ -273,10 +276,11 @@ RSpec.describe 'Api::V1::InventoryListItemsController', type: :request do expect(response).to have_http_status 200 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@list_column.repository_list_items.find(item_id), - serializer: Api::V1::InventoryListItemSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@list_column.repository_list_items.find(item_id), serializer: Api::V1::InventoryListItemSerializer) + .to_json + )['data'] ) expect(@list_column.repository_list_items.find(item_id).data).to match('Updated') end diff --git a/spec/requests/api/v1/results_controller_spec.rb b/spec/requests/api/v1/results_controller_spec.rb index f7db289a7..99d0ebce4 100644 --- a/spec/requests/api/v1/results_controller_spec.rb +++ b/spec/requests/api/v1/results_controller_spec.rb @@ -69,9 +69,11 @@ RSpec.describe 'Api::V1::ResultsController', type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_task.results, each_serializer: Api::V1::ResultSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_task.results, each_serializer: Api::V1::ResultSerializer) + .to_json + )['data'] ) end @@ -153,16 +155,18 @@ RSpec.describe 'Api::V1::ResultsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(Result.last, - serializer: Api::V1::ResultSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(Result.last, serializer: Api::V1::ResultSerializer) + .to_json + )['data'] ) expect(hash_body[:included]).to match( - ActiveModelSerializers::SerializableResource - .new(Result.last, serializer: Api::V1::ResultSerializer, - include: :text) - .as_json[:included] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(Result.last, serializer: Api::V1::ResultSerializer, include: :text) + .to_json + )['included'] ) end @@ -177,15 +181,18 @@ RSpec.describe 'Api::V1::ResultsController', type: :request do expect(response).to have_http_status 201 expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(Result.last, serializer: Api::V1::ResultSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(Result.last, serializer: Api::V1::ResultSerializer) + .to_json + )['data'] ) expect(hash_body[:included]).to match( - ActiveModelSerializers::SerializableResource - .new(Result.last, serializer: Api::V1::ResultSerializer, - include: :text) - .as_json[:included] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(Result.last, serializer: Api::V1::ResultSerializer, include: :text) + .to_json + )['included'] ) expect(ResultText.last.text).to include "data-mce-token=\"#{Base62.encode(TinyMceAsset.last.id)}\"" end @@ -343,9 +350,11 @@ RSpec.describe 'Api::V1::ResultsController', type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@valid_task.results.first, serializer: Api::V1::ResultSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@valid_task.results.first, serializer: Api::V1::ResultSerializer) + .to_json + )['data'] ) end diff --git a/spec/requests/api/v1/teams_controller_spec.rb b/spec/requests/api/v1/teams_controller_spec.rb index 08be10b94..76f122452 100644 --- a/spec/requests/api/v1/teams_controller_spec.rb +++ b/spec/requests/api/v1/teams_controller_spec.rb @@ -18,9 +18,11 @@ RSpec.describe 'Api::V1::TeamsController', type: :request do get api_v1_teams_path, headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@user.teams, each_serializer: Api::V1::TeamSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@user.teams, each_serializer: Api::V1::TeamSerializer) + .to_json + )['data'] ) end end @@ -31,9 +33,11 @@ RSpec.describe 'Api::V1::TeamsController', type: :request do get api_v1_team_path(id: @teams.second.id), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@teams.second, serializer: Api::V1::TeamSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@teams.second, serializer: Api::V1::TeamSerializer) + .to_json + )['data'] ) end diff --git a/spec/requests/api/v1/user_identities_controller_spec.rb b/spec/requests/api/v1/user_identities_controller_spec.rb index 6a2bf00c4..ddeb3fcfe 100644 --- a/spec/requests/api/v1/user_identities_controller_spec.rb +++ b/spec/requests/api/v1/user_identities_controller_spec.rb @@ -19,10 +19,11 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@user1.user_identities, - each_serializer: Api::V1::UserIdentitySerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@user1.user_identities, each_serializer: Api::V1::UserIdentitySerializer) + .to_json + )['data'] ) end @@ -57,10 +58,11 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@user1.user_identities.order(:id).last, - serializer: Api::V1::UserIdentitySerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@user1.user_identities.order(:id).last, serializer: Api::V1::UserIdentitySerializer) + .to_json + )['data'] ) end end @@ -73,10 +75,11 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@user1.user_identities.order(:id).last, - serializer: Api::V1::UserIdentitySerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@user1.user_identities.order(:id).last, serializer: Api::V1::UserIdentitySerializer) + .to_json + )['data'] ) end end @@ -94,10 +97,11 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@user1.user_identities.order(:id).last, - serializer: Api::V1::UserIdentitySerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@user1.user_identities.order(:id).last, serializer: Api::V1::UserIdentitySerializer) + .to_json + )['data'] ) end end diff --git a/spec/requests/api/v1/user_projects_controller_spec.rb b/spec/requests/api/v1/user_projects_controller_spec.rb index 48448facb..d7d033d3b 100644 --- a/spec/requests/api/v1/user_projects_controller_spec.rb +++ b/spec/requests/api/v1/user_projects_controller_spec.rb @@ -24,9 +24,11 @@ RSpec.describe "Api::V1::UserProjectsController", type: :request do headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@own_project.user_projects, each_serializer: Api::V1::UserProjectSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@own_project.user_projects, each_serializer: Api::V1::UserProjectSerializer) + .to_json + )['data'] ) end @@ -56,9 +58,11 @@ RSpec.describe "Api::V1::UserProjectsController", type: :request do ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@own_project.user_projects.first, serializer: Api::V1::UserProjectSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@own_project.user_projects.first, serializer: Api::V1::UserProjectSerializer) + .to_json + )['data'] ) end diff --git a/spec/requests/api/v1/users_controller_spec.rb b/spec/requests/api/v1/users_controller_spec.rb index 508b471ec..d91a9d4e7 100644 --- a/spec/requests/api/v1/users_controller_spec.rb +++ b/spec/requests/api/v1/users_controller_spec.rb @@ -24,9 +24,11 @@ RSpec.describe 'Api::V1::UsersController', type: :request do get api_v1_user_path(id: @user2.id), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(@user2, serializer: Api::V1::UserSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(@user2, serializer: Api::V1::UserSerializer) + .to_json + )['data'] ) end diff --git a/spec/requests/api/v1/workflow_statuses_controller_spec.rb b/spec/requests/api/v1/workflow_statuses_controller_spec.rb index 4810cf508..73e8fa34e 100644 --- a/spec/requests/api/v1/workflow_statuses_controller_spec.rb +++ b/spec/requests/api/v1/workflow_statuses_controller_spec.rb @@ -18,10 +18,11 @@ RSpec.describe 'Api::V1::WrokflowStatusesController', type: :request do get api_v1_workflow_workflow_statuses_path(workflow_id: MyModuleStatusFlow.first.id), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(MyModuleStatusFlow.first.my_module_statuses, - each_serializer: Api::V1::WorkflowStatusSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(MyModuleStatusFlow.first.my_module_statuses, each_serializer: Api::V1::WorkflowStatusSerializer) + .to_json + )['data'] ) end end diff --git a/spec/requests/api/v1/workflows_controller_spec.rb b/spec/requests/api/v1/workflows_controller_spec.rb index c0c9a405c..24c6c3c1f 100644 --- a/spec/requests/api/v1/workflows_controller_spec.rb +++ b/spec/requests/api/v1/workflows_controller_spec.rb @@ -18,10 +18,11 @@ RSpec.describe 'Api::V1::WrokflowsController', type: :request do get api_v1_workflows_path, headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(MyModuleStatusFlow.all, - each_serializer: Api::V1::WorkflowSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(MyModuleStatusFlow.all, each_serializer: Api::V1::WorkflowSerializer) + .to_json + )['data'] ) end end @@ -32,10 +33,11 @@ RSpec.describe 'Api::V1::WrokflowsController', type: :request do get api_v1_workflow_path(id: MyModuleStatusFlow.all.first), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( - ActiveModelSerializers::SerializableResource - .new(MyModuleStatusFlow.all.first, - serializer: Api::V1::WorkflowSerializer) - .as_json[:data] + JSON.parse( + ActiveModelSerializers::SerializableResource + .new(MyModuleStatusFlow.all.first, serializer: Api::V1::WorkflowSerializer) + .to_json + )['data'] ) end diff --git a/spec/support/api/schemas/project_folders/item.json b/spec/support/api/schemas/project_folders/item.json index b06bd1c9b..cf36c42bc 100644 --- a/spec/support/api/schemas/project_folders/item.json +++ b/spec/support/api/schemas/project_folders/item.json @@ -13,6 +13,12 @@ "properties": { "name": { "type": "string" + }, + "created_at": { + "type": "string" + }, + "updated_at": { + "type": "string" } }, "additionalProperties": false, @@ -43,7 +49,3 @@ "additionalProperties": false, "required": ["id", "type", "attributes"] } - - - - diff --git a/spec/support/api/schemas/status_items/item.json b/spec/support/api/schemas/status_items/item.json index 4907a22d6..37307d879 100644 --- a/spec/support/api/schemas/status_items/item.json +++ b/spec/support/api/schemas/status_items/item.json @@ -16,6 +16,12 @@ }, "status": { "type": "string" + }, + "created_at": { + "type": "string" + }, + "updated_at": { + "type": "string" } }, "additionalProperties": false, @@ -28,7 +34,3 @@ "additionalProperties": false, "required": ["id", "type", "attributes"] } - - - -