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

Part 8. ActiveStorage. #6

Merged
merged 12 commits into from Jun 30, 2019
Merged

Part 8. ActiveStorage. #6

merged 12 commits into from Jun 30, 2019

Conversation

metacorn
Copy link
Owner

No description provided.

config/routes.rb Outdated
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
get 'files/destroy'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Что это?

Действия на изменение состояния ресурсов никогда нельзя делать через get. Кто-нибудь на файлообменнике сделает картинку с перебором айдишников на удаление, и посетители этого файлообменника начнут автоматически хакать ваш сайт :-)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Что это?

Действия на изменение состояния ресурсов никогда нельзя делать через get. Кто-нибудь на файлообменнике сделает картинку с перебором айдишников на удаление, и посетители этого файлообменника начнут автоматически хакать ваш сайт :-)

Да, дичь, согласен. По действиям -- я пошагово делал следующее:

  1. Добавил во вьюшки ссылки на удаление файлов.
  2. Добавил в эти ссылки метод и ресурс (delete и /files_path(file)).
  3. Добавил в routes.rb:
resources :files, shallow: true, only: %i[destroy]
  1. Сгенерировал контроллер:
rails generate controller Files destroy

Именно тогда и прописался маршрут, как я понимаю. Теперь буду обращать внимание))

context "authenticated user" do
before { login(user1) }

it "deletes users's question attachment" do
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот и следующий тест не гарантируют, что были удалены именно переданные аттачменты.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот и следующий тест не гарантируют, что были удалены именно переданные аттачменты.

Добавил проверку на вызов исключения при reload этих аттачментов.

@@ -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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Есть ещё вот такие варианты: thoughtbot/shoulda-matchers#1102

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Есть ещё вот такие варианты: thoughtbot/shoulda-matchers#1102

Исправил, спасибо.

@metacorn metacorn merged commit c305ff6 into master Jun 30, 2019
@metacorn metacorn changed the title Part 7. ActiveStorage. Part 8. ActiveStorage. Jul 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants