-
Notifications
You must be signed in to change notification settings - Fork 0
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
Part 8. ActiveStorage. #6
Conversation
config/routes.rb
Outdated
@@ -1,4 +1,5 @@ | |||
Rails.application.routes.draw do | |||
get 'files/destroy' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Что это?
Действия на изменение состояния ресурсов никогда нельзя делать через get
. Кто-нибудь на файлообменнике сделает картинку с перебором айдишников на удаление, и посетители этого файлообменника начнут автоматически хакать ваш сайт :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Что это?
Действия на изменение состояния ресурсов никогда нельзя делать через
get
. Кто-нибудь на файлообменнике сделает картинку с перебором айдишников на удаление, и посетители этого файлообменника начнут автоматически хакать ваш сайт :-)
Да, дичь, согласен. По действиям -- я пошагово делал следующее:
- Добавил во вьюшки ссылки на удаление файлов.
- Добавил в эти ссылки метод и ресурс (delete и /files_path(file)).
- Добавил в routes.rb:
resources :files, shallow: true, only: %i[destroy]
- Сгенерировал контроллер:
rails generate controller Files destroy
Именно тогда и прописался маршрут, как я понимаю. Теперь буду обращать внимание))
context "authenticated user" do | ||
before { login(user1) } | ||
|
||
it "deletes users's question attachment" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Этот и следующий тест не гарантируют, что были удалены именно переданные аттачменты.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Этот и следующий тест не гарантируют, что были удалены именно переданные аттачменты.
Добавил проверку на вызов исключения при reload
этих аттачментов.
spec/models/question_spec.rb
Outdated
@@ -12,4 +12,8 @@ | |||
it { should validate_length_of(:body).is_at_least(50) } | |||
|
|||
it { should validate_uniqueness_of(:title).case_insensitive } | |||
|
|||
it 'has many attached files' do | |||
expect(Question.new.files).to be_an_instance_of(ActiveStorage::Attached::Many) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Есть ещё вот такие варианты: thoughtbot/shoulda-matchers#1102
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Есть ещё вот такие варианты: thoughtbot/shoulda-matchers#1102
Исправил, спасибо.
No description provided.