diff --git a/app/javascript/src/components/actions/TeamsActions.js b/app/javascript/src/components/actions/TeamsActions.js index 8daeb6cc2..c9d70824b 100644 --- a/app/javascript/src/components/actions/TeamsActions.js +++ b/app/javascript/src/components/actions/TeamsActions.js @@ -8,7 +8,7 @@ import type { Dispatch } from "redux-thunk"; import { getTeams, changeCurrentTeam, - fetchCurrentTeam + getCurrentTeam as fetchCurrentTeam } from "../../services/api/teams_api"; import { GET_LIST_OF_TEAMS, SET_CURRENT_TEAM } from "../../config/action_types"; diff --git a/app/javascript/src/services/api/teams_api.js b/app/javascript/src/services/api/teams_api.js index 5015ed68c..af362cded 100644 --- a/app/javascript/src/services/api/teams_api.js +++ b/app/javascript/src/services/api/teams_api.js @@ -36,5 +36,5 @@ export const leaveTeam = (teamID: number, userTeamID: number): Promise<*> => { return axiosInstance.delete(teamUrl).then(({ data }) => data.teams); }; -export const fetchCurrentTeam = (): Promise<*> => +export const getCurrentTeam = (): Promise<*> => axiosInstance.get(CURRENT_TEAM_PATH).then(({ data }) => data.team); diff --git a/app/models/datatables/datatables_team.rb b/app/models/datatables/datatables_team.rb deleted file mode 100644 index 1c22f8388..000000000 --- a/app/models/datatables/datatables_team.rb +++ /dev/null @@ -1,14 +0,0 @@ -module Datatables - class DatatablesTeam < ApplicationRecord - belongs_to :user - default_scope { order(name: :asc) } - - private - - # this isn't strictly necessary, but it will prevent - # rails from calling save, which would fail anyway. - def readonly? - true - end - end -end diff --git a/app/models/user.rb b/app/models/user.rb index 32b990722..96afe98b2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -198,7 +198,7 @@ class User < ApplicationRecord has_many :user_notifications, inverse_of: :user has_many :notifications, through: :user_notifications has_many :zip_exports, inverse_of: :user, dependent: :destroy - has_many :datatables_teams, class_name: '::Datatables::DatatablesTeam' + has_many :datatables_teams, class_name: '::Views::Datatables::DatatablesTeam' # If other errors besides parameter "avatar" exist, # they will propagate to "avatar" also, so remove them diff --git a/app/models/views/datatables/datatables_team.rb b/app/models/views/datatables/datatables_team.rb new file mode 100644 index 000000000..3caac3f06 --- /dev/null +++ b/app/models/views/datatables/datatables_team.rb @@ -0,0 +1,16 @@ +module Views + module Datatables + class DatatablesTeam < ApplicationRecord + belongs_to :user + default_scope { order(name: :asc) } + + private + + # this isn't strictly necessary, but it will prevent + # rails from calling save, which would fail anyway. + def readonly? + true + end + end + end +end diff --git a/spec/models/datatables/teams_spec.rb b/spec/models/views/datatables/teams_spec.rb similarity index 70% rename from spec/models/datatables/teams_spec.rb rename to spec/models/views/datatables/teams_spec.rb index c69c8a82a..cc4095b8d 100644 --- a/spec/models/datatables/teams_spec.rb +++ b/spec/models/views/datatables/teams_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Datatables::DatatablesTeam, type: :model do +RSpec.describe Views::Datatables::DatatablesTeam, type: :model do describe 'Database table' do it { should have_db_column :id } it { should have_db_column :name } @@ -15,9 +15,9 @@ RSpec.describe Datatables::DatatablesTeam, type: :model do let(:user) { create :user } it do expect { - Datatables::DatatablesTeam.create!(user_id: user.id) + Views::Datatables::DatatablesTeam.create!(user_id: user.id) }.to raise_error(ActiveRecord::ReadOnlyRecord, - 'Datatables::DatatablesTeam is marked as readonly') + 'Views::Datatables::DatatablesTeam is marked as readonly') end end end diff --git a/spec/services/client_api/teams_service_spec.rb b/spec/services/client_api/teams_service_spec.rb index fc1f355ff..40025f951 100644 --- a/spec/services/client_api/teams_service_spec.rb +++ b/spec/services/client_api/teams_service_spec.rb @@ -57,7 +57,9 @@ describe ClientApi::TeamsService do it 'should return an array of valid teams' do create :user_team, user: user_one, team: team_one - expect(team_service.teams_data).to match_response_schema('teams') + expect(team_service.teams_data).to( + match_response_schema('datatables_teams') + ) end end diff --git a/spec/support/api/schemas/teams.json b/spec/support/api/schemas/datatables_teams.json similarity index 100% rename from spec/support/api/schemas/teams.json rename to spec/support/api/schemas/datatables_teams.json