8000 Ruby 3 compatibility by Luana-de-Oliveira · Pull Request #617 · refile/refile · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Ruby 3 compatibility #617

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

Closed
wants to merge 9 commits into from
Closed
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
3 changes: 2 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
-r refile/spec_helper
-r refile/spec_helper --format=documentation --color

51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Use uma imagem base com Ruby que suporta ARM64
FROM ruby:3.0

# Instale dependências do sistema
RUN apt-get update && apt-get install -y \
curl \
unzip \
wget \
gnupg \
libxi6 \
libgconf-2-4 \
libnss3 \
libx11-xcb1 \
libxcomposite1 \
libxdamage1 \
libxrandr2 \
libxss1 \
libxtst6 \
libgtk-3-0 \
libatspi2.0-0 \
libnspr4 \
libgbm1 \
libasound2 \
&& rm -rf /var/lib/apt/lists/*

# Adicione o repositório do Chromium e instale o Chromium
RUN apt-get update && apt-get install -y \
chromium \
&& rm -rf /var/lib/apt/lists/*

# Instale o ChromeDriver
RUN CHROMEDRIVER_VERSION=$(curl -sSL https://chromedriver.storage.googleapis.com/LATEST_RELEASE) \
&& curl -sSL https://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip -o chromedriver.zip \
&& unzip chromedriver.zip \
&& mv chromedriver /usr/local/bin/ \
&& chmod +x /usr/local/bin/chromedriver \
&& rm chromedriver.zip

# Defina o diretório de tra 10000 balho
WORKDIR /app

# Copie o restante da aplicação
COPY . /app

ENV BUNDLE_GEMFILE=./gemfiles/Gemfile_Rails_6_1

# Instale as gems
RUN bundle install

# Comando padrão para rodar os testes
CMD ["bundle", "exec", "rake", "test"]
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.8'
services:
app:
build: .
platform: linux/arm64
container_name: refile
volumes:
- .:/app
environment:
BUNDLE_GEMFILE: ./gemfiles/Gemfile_Rails_6_1
command: sleep infinity
23 changes: 0 additions & 23 deletions gemfiles/Gemfile_Rails_5_2

This file was deleted.

27 changes: 27 additions & 0 deletions gemfiles/Gemfile_Rails_6_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
source "https://rubygems.org"

gemspec path: '../'

gem "webmock", "~> 3.13.0" # Compatível com Rails 6.1
gem "bundler" # Rails 6.1 geralmente utiliza Bundler 2.x
gem "rake", "~> 13.0" # Rake 13 é a versão utilizada no Rails 6.1
gem "rspec", "~> 3.10" # Atualizado para ser compatível com Rails 6.1
gem "rspec-rails", "~> 4.0" # Compatível com Rails 6.1
gem "jquery-rails", "~> 4.4" # Versão recomendada para Rails 6.1
gem "capybara", "~> 3.35" # Compatível com Rails 6.1
gem "aws-sdk-s3", "~> 1.86" # Compatível com Rails 6.1
gem "rack-test", "~> 1.1" # Versão compatível com o Rack utilizado no Rails 6.1
gem "rails", "~> 6.1" # Atualizado para Rails 6.1
gem "sqlite3", "~> 1.4", platforms: [:ruby] # Versão recomendada para Rails 6.1
gem "activerecord-jdbcsqlite3-adapter", "~> 61.0", platforms: [:jruby] # Compatível com ActiveRecord 6.1
gem "poltergeist", "~> 1.18" # Última versão disponível, mas considere trocar para outra solução de driver
gem "yard", "~> 0.9" # Compatível com Rails 6.1
gem "rubocop", "~> 1.0" # Compatível com o estilo do Rails 6.1
gem "puma", "~> 5.0" # Compatível com Rails 6.1
gem "mini_magick", "~> 4.11" # Compatível com Rails 6.1
gem "simple_form", "~> 5.1" # Compatível com Rails 6.1
gem "i18n", "~> 1.8", "< 2.0" # Versão compatível com Rails 6.1

gem 'selenium-webdriver'
gem 'webdrivers' # Opcional, mas útil para gerenciar as versões do ChromeDriver
gem 'byebug'
3 changes: 2 additions & 1 deletion lib/refile/attachment/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def attachment(name, raise_errors: false, destroy: true, **options)
send(attacher).valid?
errors = send(attacher).errors
errors.each do |error|
self.errors.add(name, *error)
type, errors = error
self.errors.add(name, type, **errors.to_h)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/refile/rails/attachment_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ module FormBuilder
# @see AttachmentHelper#attachment_field
def attachment_field(method, options = {})
self.multipart = true
@template.attachment_field(@object_name, method, objectify_options(options))
@template.attachment_field(@object_name, method, **objectify_options(options))
end

# @see AttachmentHelper#attachment_cache_field
def attachment_cache_field(method, options = {})
self.multipart = true
@template.attachment_cache_field(@object_name, method, objectify_options(options))
@template.attachment_cache_field(@object_name, method, **objectify_options(options))
end
end

Expand Down
7 changes: 6 additions & 1 deletion spec/refile/active_record_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
require "active_record"

# Configure I18n
I18n.enforce_available_locales = true
I18n.available_locales = [:en] # Add other locales if needed
I18n.load_path.clear
I18n.load_path += Dir[File.join('.', 'config', 'locales', '**', '*.{rb,yml}')]
I18n.default_locale = :en

ActiveRecord::Base.establish_connection(
adapter: "sqlite3",
Expand Down Expand Up @@ -32,4 +37,4 @@ def self.up
end
end

TestMigration.up
TestMigration.up
4 changes: 2 additions & 2 deletions spec/refile/attachment/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def self.name
user = users_class.create!
post = klass.create!(user_id: user.id, document: Refile::FileDouble.new("foo"))

user.update_attributes!(post_attributes: { id: post.id, remove_document: true })
user.update!(post_attributes: { id: post.id, remove_document: true })

expect(post.reload.document).to be_nil
end
Expand Down Expand Up @@ -457,7 +457,7 @@ def self.name
user = users_class.create!
post = klass.create!(user_id: user.id, document: Refile::FileDouble.new("foo"))

user.update_attributes!(posts_attributes: { id: post.id, remove_document: true })
user.update!(posts_attributes: { id: post.id, remove_document: true })

expect(post.reload.document).to be_nil
end
Expand Down
2 changes: 1 addition & 1 deletion spec/refile/attachment_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def self.name
end

describe "#attachment_field" do
subject(:field) { attachment_field("post", :document, field_options) }
subject(:field) { attachment_field("post", :document, **field_options) }
let(:field_options) { { object: klass.new } }
let(:html) { Capybara.string(field) }
let(:expected_field_name) { "post[0][document]" }
Expand Down
2 changes: 1 addition & 1 deletion spec/refile/attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ def initialize(attributes)

def save!; end

def update_attributes!(attributes)
def update!(attributes)
attributes.each { |k, v| public_send("#{k}=", v) }
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/refile/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ENV["RACK_ENV"] = "test"

require 'byebug'
require "refile"
require "refile/backend_examples"
require "webmock/rspec"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Refile::FileDouble.new("world", content_type: "image/jpeg")
]
post.save!
post.update_attributes! documents_files: [
post.update! documents_files: [
Refile::FileDouble.new("foo", content_type: "image/jpeg")
]

Expand Down Expand Up @@ -118,7 +118,7 @@
Refile::FileDouble.new("world", content_type: "image/jpeg")
]
post.save!
post.update_attributes! documents_files: [
post.update! documents_files: [
Refile::FileDouble.new("foo", content_type: "image/jpeg")
]

Expand All @@ -134,7 +134,7 @@
Refile::FileDouble.new("world", content_type: "image/jpeg")
]
post.save!
post.update_attributes! documents_files: [
post.update! documents_files: [
[{
id: Refile.cache.upload(Refile::FileDouble.new("hello world")).id,
filename: "some.jpg",
Expand Down
24 changes: 13 additions & 11 deletions spec/refile/test_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

module Refile
class TestApp < Rails::Application
config.load_defaults 6.1

config.middleware.delete "ActionDispatch::Cookies"
config.middleware.delete "ActionDispatch::Session::CookieStore"
config.middleware.delete "ActionDispatch::Flash"
Expand All @@ -27,22 +29,22 @@ class TestApp < Rails::Application
require "capybara/rspec"
require "refile/spec_helper"
require "refile/active_record_helper"
require "capybara/poltergeist"
require 'selenium/webdriver'

if ENV["SAUCE_BROWSER"]
Capybara.register_driver :selenium do |app|
url = "http://#{ENV["SAUCE_USERNAME"]}:#{ENV["SAUCE_ACCESS_KEY"]}@localhost:4445/wd/hub"
capabilities = { browserName: ENV["SAUCE_BROWSER"], version: ENV["SAUCE_VERSION"] }
driver = Capybara::Selenium::Driver.new(app, browser: :remote, url: url, desired_capabilities: capabilities)
driver.browser.file_detector = ->(args) { args.first if File.exist?(args.first) }
driver
end
Capybara.register_driver :headless_chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('headless')
options.add_argument('disable-gpu') # Necessário em alguns ambientes
options.add_argument('no-sandbox') # Pode ser necessário em ambientes Docker
options.add_argument('disable-dev-shm-usage') # Pode ser necessário em ambientes Docker

Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end

Capybara.javascript_driver = :poltergeist
Capybara.javascript_driver = :headless_chrome

Capybara.configure do |config|
config.server_port = 56_120
config.server_port = 56120
end

module TestAppHelpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def edit
def update
@post = Post.find(params[:id])

if @post.update_attributes(post_params)
if @post.update(post_params)
redirect_to [:normal, @post]
else
render :form
Expand Down
2851
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def create
def update
@post = Post.find(params[:id])

if @post.update_attributes(post_params)
if @post.update(post_params)
redirect_to [:normal, @post]
else
render :edit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def edit
def update
@post = Post.find(params[:id])

if @post.update_attributes(post_params)
if @post.update(post_params)
redirect_to [:normal, @post]
else
render :form
Expand Down
0