Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/rename project auth #211

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def authenticate_user
end

def authenticate_project
project_auth = ProjectAuth.find_by(key: project_auth_key)
project_auth = ProjectReport.find_by(key: project_auth_key)
return user_invalid! unless project_auth

@current_project = project_auth.project
Expand Down
1 change: 1 addition & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Project < ApplicationRecord
has_many :issues, dependent: :destroy
has_many :statement_of_works, dependent: :destroy
has_many :dynamic_datasets, dependent: :destroy
has_one :project_report, dependent: :destroy

validates :name, presence: true, uniqueness: { case_sensitive: false }
validates :billable, inclusion: { in: [true, false] }
Expand Down
6 changes: 3 additions & 3 deletions app/models/project_auth.rb → app/models/project_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# == Schema Information
#
# Table name: project_auths
# Table name: project_reports
#
# id :bigint not null, primary key
# key :string
Expand All @@ -12,13 +12,13 @@
#
# Indexes
#
# index_project_auths_on_project_id (project_id)
# index_project_reports_on_project_id (project_id)
#
# Foreign Keys
#
# fk_rails_... (project_id => projects.id)
#
class ProjectAuth < ApplicationRecord
class ProjectReport < ApplicationRecord
belongs_to :project

before_create :generate_key, unless: :key_present?
Expand Down
2 changes: 2 additions & 0 deletions app/views/projects/_project.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ end
json.extract! project, :id, :name, :billable, :slack_channel, :metadata, :slug, :logo_url,
:sync_source_control, :sync_ticket_tracking_system, :logo_background_color,
:display_code_metrics, :display_tasks_metrics

json.report_key project.project_report&.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class RenameProjectAuthToProjectReport < ActiveRecord::Migration[7.0]
def change
rename_table :project_auths, :project_reports
end
end
8 changes: 4 additions & 4 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions spec/controllers/projects_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@

expect(response.parsed_body['customer']['id']).to eq(project.customer.id)
end

it 'returns a report key if it has a project_report' do
project = Project.create! valid_attributes
project.project_report = ProjectReport.create!(project:, key: '123')

get :show, params: { id: project.to_param }, format: :json
expect(response.parsed_body['report_key']).to eq('123')
end
end

describe 'POST #create' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#
require 'rails_helper'

RSpec.describe ProjectAuth, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
RSpec.describe ProjectReport, type: :model do
context 'associations' do
it { should belong_to(:project) }
end
end
1 change: 1 addition & 0 deletions spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@
it { should have_many(:issues).dependent(:destroy) }
it { should have_many(:statement_of_works).dependent(:destroy) }
it { should have_many(:dynamic_datasets).dependent(:destroy) }
it { should have_one(:project_report) }
end
end
Loading