Skip to content

Commit

Permalink
remove friendly id gem
Browse files Browse the repository at this point in the history
  • Loading branch information
muzsuvie committed Sep 10, 2024
1 parent 368cbce commit 9d99e47
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 20 deletions.
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ gemspec
group :development do
gem "sqlite3"
end
gem "activestorage"
gem "friendly_id"

group :test do
gem "activestorage"
end

gem "pry", group: [:development, :test], require: false
gem "rails", "~> 6.1.7.4", group: [:development, :test], require: false
6 changes: 1 addition & 5 deletions app/controllers/rake_ui/rake_task_logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module RakeUi
class RakeTaskLogsController < ApplicationController
before_action :get_rake_task_log, only: [:show]

RAKE_TASK_LOG_ATTRS = [:id,
:name,
Expand All @@ -26,6 +25,7 @@ def index
end

def show
@rake_task_log = klass.find_by_id(params[:id])
@rake_task_log_content = @rake_task_log.file_contents.gsub("\n", "<br />")
@rake_task_log_content_url = rake_task_log_path(@rake_task_log.id, format: :json)
@is_rake_task_log_finished = @rake_task_log.finished?
Expand Down Expand Up @@ -59,9 +59,5 @@ def klass
RakeUi.configuration.active_storage ? ::RakeTaskLog : RakeUi::RakeTaskLog
end

def get_rake_task_log
@rake_task_log = RakeUi.configuration.active_storage ? ::RakeTaskLog.friendly.find(params[:id]) :
RakeUi::RakeTaskLog.find_by_id(params[:id])
end
end
end
5 changes: 1 addition & 4 deletions app/models/rake_task_log.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class RakeTaskLog < ApplicationRecord
include RakeTaskLogs
extend FriendlyId
friendly_id :name, use: :slugged

ATTRIBUTES_TO_SHOW = %w[id name date args environment rake_command rake_definition_file log_file_name log_file_full_path]
has_one_attached :log_file
Expand All @@ -24,8 +22,7 @@ def self.generate_file_content(log_file_full_path:)
def self.create_rake_task_log(name:, args:, environment:, rake_command:, rake_definition_file:, raker_id:)
attributes = generate_task_attributes(raker_id:)

::RakeTaskLog.create(slug: attributes[:id],
name:,
::RakeTaskLog.create(name:,
args:,
environment:,
rake_command:,
Expand Down
3 changes: 0 additions & 3 deletions lib/generators/rake_ui/templates/create_rake_task_logs.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class CreateRakeTaskLogs < ActiveRecord::Migration[7.0]
def change
create_table :rake_task_logs do |t|
t.string :slug, unique: true
t.integer :status, default: 0
t.string :name
t.string :args
Expand All @@ -13,7 +12,5 @@ def change
t.string :raker_id
t.timestamps
end

add_index :rake_task_logs, :slug, unique: true
end
end
3 changes: 0 additions & 3 deletions test/dummy/db/migrate/20240906183058_create_rake_task_logs.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class CreateRakeTaskLogs < ActiveRecord::Migration[6.1]
def change
create_table :rake_task_logs do |t|
t.string :slug, unique: true
t.integer :status, default: 0
t.string :name
t.string :args
Expand All @@ -13,7 +12,5 @@ def change
t.string :raker_id
t.timestamps
end

add_index :rake_task_logs, :slug, unique: true
end
end
2 changes: 0 additions & 2 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
end

create_table "rake_task_logs", force: :cascade do |t|
t.string "slug"
t.integer "status", default: 0
t.string "name"
t.string "args"
Expand All @@ -53,7 +52,6 @@
t.string "raker_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["slug"], name: "index_rake_task_logs_on_slug", unique: true
end

add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class RakeTaskLogsRequestWithActiveRecordTest < ActionDispatch::IntegrationTest

@file = Rack::Test::UploadedFile.new(Rails.root.join('fixtures/sample_log.txt'), 'text/plain')
@rake_task_log = ::RakeTaskLog.create!(
slug: 'test-file',
status: 1,
name: 'Test Rake Task',
args: 'arg1,arg2',
Expand Down

0 comments on commit 9d99e47

Please sign in to comment.