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

NVK-55 - location not required for digital artworks #158

Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@

.vscode

.byebug_history
Binary file modified .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ gem "stimulus-rails"
gem "turbo-rails"

group :development, :test do
gem "byebug"
gem "debug"
end

Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ GEM
bundler-audit (0.9.2)
bundler (>= 1.2.0, < 3)
thor (~> 1.0)
byebug (11.1.3)
cgi (0.4.1)
chargebee (2.47.0.beta.1)
cgi (>= 0.1.0, < 1.0.0)
Expand Down Expand Up @@ -337,6 +338,7 @@ DEPENDENCIES
bootsnap
bootstrap_form
bundler-audit
byebug
chargebee (= 2.47.0.beta.1)
cssbundling-rails
debug
Expand Down
3 changes: 2 additions & 1 deletion app/models/artwork.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class Artwork < ApplicationRecord
"Design", "Drawing", "Installation", "Film/Video", "Jewelry", "Performance Art",
"Reproduction", "Ephemera or Merchandise", "Digital Art"]

validates :title, :medium, :location, :year, presence: true
validates :title, :medium, :year, presence: true
validates :location, presence: true, unless: -> { ["Digital Art", "NFT"].include?(medium) }
validates :units, inclusion: {in: %w[in cm],
message: "%{value} is not a valid unit"}
validates :duration, numericality: {greater_than_or_equal_to: 0, allow_blank: true}
Expand Down
11 changes: 11 additions & 0 deletions test/models/artwork_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@ class ArtworkTest < ActiveSupport::TestCase
artwork = create_artwork(user)
assert_equal "Louise the Artist", artwork.artist_name
end

test "location is required except for Digital Art/NFTs" do
user = users(:artist)
artwork = create_artwork(user, "Painting")
artwork.location = nil
refute artwork.valid?
artwork.medium = "NFT"
assert artwork.valid?
artwork.medium = "Digital Art"
assert artwork.valid?
end
end
7 changes: 4 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ class TestCase
# Add more helper methods to be used by all tests here...
include Devise::Test::IntegrationHelpers

def create_artwork(user)
def create_artwork(user, medium = false)
r = Random.new
user.artworks.create!(title: "Title#{r.rand(100)}", medium: Artwork::MEDIUM_LIST[r.rand(Artwork::MEDIUM_LIST.size)],

user.artworks.create!(title: "Title#{r.rand(100)}", medium: medium || Artwork::MEDIUM_LIST[r.rand(Artwork::MEDIUM_LIST.size)],
material: "material#{r.rand(100)}", visible: true, height: 2, width: 3, location: "Brooklyn", year: 2025)
end
end
end
end