-
Notifications
You must be signed in to change notification settings - Fork 35
Add endpoint for accessing variant screenshots #233
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
base: main
Are you sure you want to change the base?
Changes from all commits
2b04d72
93e1b0d
225f3b2
b23a8f2
be430fc
183c79a
6b18a0d
0a73ca1
75bf50b
d2d831d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class Admin::ScreenshotsController < ApplicationController | ||
| def show | ||
| split = Split.find(params[:split_id]) | ||
| variant_detail = split.variant_details.find_by!(variant: variant) | ||
| raise ActiveRecord::RecordNotFound unless variant_detail.screenshot_file_name? | ||
|
|
||
| redirect_to variant_detail.screenshot.expiring_url(300) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| end | ||
|
|
||
| private | ||
|
|
||
| def variant | ||
| params.fetch(:id).split('.').first | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| Rails.application.configure do | ||
| # Settings specified here will take precedence over those in config/application.rb. | ||
|
|
||
| config.hosts << "testtrack.test" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A conventional hostname for local dev. (I used |
||
|
|
||
| # In the development environment your application's code is reloaded any time | ||
| # it changes. This slows down response time but is perfect for development | ||
| # since you don't have to restart the web server when you make code changes. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,12 @@ | |
| puts "Ensured #{app_name} app" | ||
| end | ||
| end | ||
|
|
||
| require 'active_record/fixtures' | ||
| fixtures_dir = File.join(Rails.root, 'db/seeds') | ||
| fixture_files = Dir.glob('db/seeds/*.yml').map { |f| File.basename(f, '.yml') } | ||
|
|
||
| ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_files) | ||
|
Comment on lines
+12
to
+16
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See here |
||
| end | ||
|
|
||
| test_track_app = App.find_or_create_by!(name: 'TestTrack') do |app| | ||
|
|
@@ -17,3 +23,8 @@ | |
| IdentifierType.find_or_create_by!(name: 'app_id') do |identifier_type| | ||
| identifier_type.owner_app = test_track_app | ||
| end | ||
|
|
||
| Admin.find_or_create_by!(email: 'admin@example.org') do |user| | ||
| user.password = 'password' | ||
| user.password_confirmation = 'password' | ||
| end | ||
|
Comment on lines
+27
to
+30
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seed the development DB with an admin user. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ def storage_settings | |
| end | ||
|
|
||
| def max_size | ||
| ENV['ATTACHMENT_MAX_SIZE'] || 512.kilobytes | ||
| ENV['ATTACHMENT_MAX_SIZE']&.to_i || 1.megabyte | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Increasing the default to 1 megabyte (screen resolutions have gotten a bit bigger since 2017!) Also casting the max size value to an int, since it would otherwise come in as a string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is 1mb a reasonable size for gifs? any cost to making this higher? |
||
| end | ||
|
|
||
| private | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Admin::ScreenshotsController do | ||
| let(:split) { FactoryBot.create(:split, name: 'my_split') } | ||
|
|
||
| around do |example| | ||
| env_config = Rails.application.env_config | ||
| show_exceptions_was = env_config['action_dispatch.show_exceptions'] | ||
| show_detailed_exceptions_was = env_config['action_dispatch.show_detailed_exceptions'] | ||
| env_config['action_dispatch.show_exceptions'] = true | ||
| env_config['action_dispatch.show_detailed_exceptions'] = false | ||
| example.run | ||
| ensure | ||
| env_config['action_dispatch.show_exceptions'] = show_exceptions_was | ||
| env_config['action_dispatch.show_detailed_exceptions'] = show_detailed_exceptions_was | ||
| end | ||
|
|
||
| describe 'GET /variant.ext' do | ||
| it 'returns a 404' do | ||
| get "/admin/splits/#{split.id}/screenshots/hammer_time.jpg" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔨 |
||
|
|
||
| expect(response).to have_http_status(:not_found) | ||
| end | ||
|
|
||
| context 'when a variant detail record exists' do | ||
| let!(:variant_detail) do | ||
| FactoryBot.create(:variant_detail, split: split, variant: 'hammer_time') | ||
| end | ||
|
|
||
| it 'returns a 404' do | ||
| get "/admin/splits/#{split.id}/screenshots/hammer_time.jpg" | ||
|
|
||
| expect(response).to have_http_status(:not_found) | ||
| end | ||
|
|
||
| context 'when a screenshot exists' do | ||
| before do | ||
| variant_detail.screenshot_file_name = '1x1.jpg' | ||
| variant_detail.screenshot_content_type = 'image/jpeg' | ||
| variant_detail.screenshot_file_size = 123 | ||
| variant_detail.save! | ||
| end | ||
|
|
||
| it 'redirects to the screenshot' do | ||
| get "/admin/splits/#{split.id}/screenshots/hammer_time.jpg" | ||
|
|
||
| expect(response).to have_http_status(:found) | ||
| expect(response).to redirect_to(variant_detail.screenshot.url) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
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.
I added a step to
seeds.rbthat will conditionally read from any Rails fixture files placed in this folder.