Merge branch 'dev' into merge-crops

This commit is contained in:
Daniel O'Connor
2025-10-09 22:52:52 +10:30
committed by GitHub
16 changed files with 245 additions and 53 deletions

View File

@@ -82,8 +82,8 @@ GEM
addressable
active_median (0.6.0)
activesupport (>= 7.1)
active_record_union (1.3.0)
activerecord (>= 4.0)
active_record_union (1.4.0)
activerecord (>= 6.0)
active_utils (3.6.0)
activesupport (>= 4.2)
i18n
@@ -142,7 +142,7 @@ GEM
erubi (>= 1.0.0)
rack (>= 0.9.0)
rouge (>= 1.0.0)
bigdecimal (3.2.3)
bigdecimal (3.3.0)
bluecloth (2.2.0)
bonsai-elasticsearch-rails (7.0.1)
elasticsearch-model (< 8)
@@ -208,7 +208,7 @@ GEM
gli (>= 2.7.0)
i18n (>= 0.6.4)
rubyzip (>= 1.0.0)
csv (3.3.1)
csv (3.3.5)
csv_shaper (1.4.0)
activesupport (>= 3.0.0)
csv
@@ -264,7 +264,7 @@ GEM
railties (>= 6.1.0)
faker (3.5.2)
i18n (>= 1.8.11, < 2)
faraday (2.13.4)
faraday (2.14.0)
faraday-net_http (>= 2.0, < 3.5)
json
logger
@@ -277,7 +277,7 @@ GEM
friendly_id (5.5.1)
activerecord (>= 4.0.0)
gbifrb (0.2.0)
geocoder (1.8.5)
geocoder (1.8.6)
base64 (>= 0.1.0)
csv (>= 3.0.0)
gibbon (1.2.1)
@@ -294,7 +294,7 @@ GEM
temple (>= 0.8.2)
thor
tilt
haml-rails (2.1.0)
haml-rails (3.0.0)
actionpack (>= 5.1)
activesupport (>= 5.1)
haml (>= 4.0.6)
@@ -337,7 +337,7 @@ GEM
terminal-table (>= 1.5.1)
i18n_data (1.1.0)
simple_po_parser (~> 1.1)
icalendar (2.11.2)
icalendar (2.12.0)
base64
ice_cube (~> 0.16)
logger
@@ -411,7 +411,7 @@ GEM
mini_magick (4.12.0)
mini_mime (1.1.5)
mini_portile2 (2.8.9)
minitest (5.25.5)
minitest (5.26.0)
moneta (1.0.0)
msgpack (1.8.0)
multi_json (1.15.0)
@@ -430,10 +430,10 @@ GEM
net-protocol
netrc (0.11.0)
nio4r (2.7.4)
nokogiri (1.18.9)
nokogiri (1.18.10)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.18.9-x86_64-linux-gnu)
nokogiri (1.18.10-x86_64-linux-gnu)
racc (~> 1.4)
oauth (0.5.6)
oj (3.16.11)
@@ -475,11 +475,11 @@ GEM
date
stringio
public_suffix (6.0.1)
puma (7.0.3)
puma (7.0.4)
nio4r (~> 2.0)
query_diet (0.7.2)
racc (1.8.1)
rack (2.2.17)
rack (2.2.19)
rack-cors (2.0.2)
rack (>= 2.0.0)
rack-protection (3.2.0)
@@ -546,7 +546,7 @@ GEM
recaptcha (5.21.1)
redis-client (0.23.2)
connection_pool
regexp_parser (2.11.2)
regexp_parser (2.11.3)
reline (0.6.2)
io-console (~> 0.5)
responders (3.1.1)
@@ -557,7 +557,7 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.4.2)
rexml (3.4.4)
rouge (4.1.2)
rspec (3.13.0)
rspec-core (~> 3.13.0)
@@ -601,7 +601,7 @@ GEM
rswag-ui (2.16.0)
actionpack (>= 5.2, < 8.1)
railties (>= 5.2, < 8.1)
rubocop (1.80.2)
rubocop (1.81.1)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
@@ -609,10 +609,10 @@ GEM
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.46.0, < 2.0)
rubocop-ast (>= 1.47.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.46.0)
rubocop-ast (1.47.1)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-capybara (2.22.1)
@@ -621,7 +621,7 @@ GEM
rubocop-factory_bot (2.27.1)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
rubocop-rails (2.33.3)
rubocop-rails (2.33.4)
activesupport (>= 4.2.0)
lint_roller (~> 1.1)
rack (>= 1.1)
@@ -641,7 +641,7 @@ GEM
ruby-units (4.1.0)
ruby-vips (2.2.1)
ffi (~> 1.12)
rubyzip (3.0.1)
rubyzip (3.1.1)
sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
@@ -661,9 +661,11 @@ GEM
activemodel (>= 6.1)
hashie
securerandom (0.4.1)
selenium-webdriver (4.35.0)
selenium-webdriver (4.36.0)
base64 (~> 0.2)
json (<= 2.13.2)
logger (~> 1.4)
prism (~> 1.0, < 1.5)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 4.0)
websocket (~> 1.0)
@@ -697,9 +699,9 @@ GEM
timeout (0.4.3)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (3.1.5)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.1.0)
unicorn (6.1.0)
kgio (~> 2.6)
raindrops (~> 0.7)

View File

@@ -7,9 +7,9 @@ module Api
@model.owner = context[:current_user]
end
has_one :owner, class_name: 'Member'
has_one :garden
has_one :planting
has_one :owner, class_name: 'Member', always_include_linkage_data: true
has_one :garden, always_include_linkage_data: true
has_one :planting, always_include_linkage_data: true
attribute :name
attribute :description

View File

@@ -12,7 +12,7 @@ module Api
has_many :photos
has_one :parent, class_name: 'Crop'
has_one :parent, class_name: 'Crop', always_include_linkage_data: true
attribute :name
attribute :en_wikipedia_url

View File

@@ -7,7 +7,7 @@ module Api
@model.owner = context[:current_user]
end
has_one :owner, class_name: 'Member'
has_one :owner, class_name: 'Member', always_include_linkage_data: true
has_many :plantings
has_many :photos

View File

@@ -10,9 +10,9 @@ module Api
@model.plant_part = PlantPart.first
end
has_one :crop
has_one :planting
has_one :owner, class_name: 'Member'
has_one :crop, always_include_linkage_data: true
has_one :planting, always_include_linkage_data: true
has_one :owner, class_name: 'Member', always_include_linkage_data: true
# has_one :plant_part
has_many :photos

View File

@@ -9,6 +9,7 @@ module Api
has_many :plantings, foreign_key: 'owner_id'
has_many :harvests, foreign_key: 'owner_id'
has_many :seeds, foreign_key: 'owner_id'
has_many :activities, foreign_key: 'owner_id'
has_many :photos

View File

@@ -8,7 +8,7 @@ module Api
@model.owner = context[:current_user]
end
has_one :owner, class_name: 'Member'
has_one :owner, class_name: 'Member', always_include_linkage_data: true
has_many :plantings
has_many :gardens
has_many :harvests

View File

@@ -7,9 +7,9 @@ module Api
@model.owner = context[:current_user]
end
has_one :garden
has_one :crop
has_one :owner, class_name: 'Member'
has_one :garden, always_include_linkage_data: true
has_one :crop, always_include_linkage_data: true
has_one :owner, class_name: 'Member', always_include_linkage_data: true
has_many :photos
has_many :harvests

View File

@@ -7,8 +7,8 @@ module Api
@model.owner = context[:current_user]
end
has_one :owner, class_name: 'Member'
has_one :crop
has_one :owner, class_name: 'Member', always_include_linkage_data: true
has_one :crop, always_include_linkage_data: true
attribute :description
attribute :quantity

142
public/robots.txt Normal file
View File

@@ -0,0 +1,142 @@
# robots.txt for based on the one for http://www.wikipedia.org/ and friends
# Observed spamming large amounts of https://en.wikipedia.org/?curid=NNNNNN
# and ignoring 429 ratelimit responses, claims to respect robots:
# http://mj12bot.com/
User-agent: MJ12bot
Disallow: /
# advertising-related bots:
User-agent: Mediapartners-Google*
Disallow: /
# Wikipedia work bots:
User-agent: IsraBot
Disallow:
User-agent: Orthogaffe
Disallow:
# Crawlers that are kind enough to obey, but which we'd rather not have
# unless they're feeding search engines.
User-agent: UbiCrawler
Disallow: /
User-agent: DOC
Disallow: /
User-agent: Zao
Disallow: /
# Some bots are known to be trouble, particularly those designed to copy
# entire sites. Please obey robots.txt.
User-agent: sitecheck.internetseer.com
Disallow: /
User-agent: Zealbot
Disallow: /
User-agent: MSIECrawler
Disallow: /
User-agent: SiteSnagger
Disallow: /
User-agent: WebStripper
Disallow: /
User-agent: WebCopier
Disallow: /
User-agent: Fetch
Disallow: /
User-agent: Offline Explorer
Disallow: /
User-agent: Teleport
Disallow: /
User-agent: TeleportPro
Disallow: /
User-agent: WebZIP
Disallow: /
User-agent: linko
Disallow: /
User-agent: HTTrack
Disallow: /
User-agent: Microsoft.URL.Control
Disallow: /
User-agent: Xenu
Disallow: /
User-agent: larbin
Disallow: /
User-agent: libwww
Disallow: /
User-agent: ZyBORG
Disallow: /
User-agent: Download Ninja
Disallow: /
# Misbehaving: requests much too fast:
User-agent: fast
Disallow: /
#
# Sorry, wget in its recursive mode is a frequent problem.
# Please read the man page and use it properly; there is a
# --wait option you can use to set the delay between hits,
# for instance.
#
User-agent: wget
Disallow: /
#
# The 'grub' distributed client has been *very* poorly behaved.
#
User-agent: grub-client
Disallow: /
#
# Doesn't follow robots.txt anyway, but...
#
User-agent: k2spider
Disallow: /
#
# Hits many times per second, not acceptable
# http://www.nameprotect.com/botinfo.html
User-agent: NPBot
Disallow: /
# A capture bot, downloads gazillions of pages with no public benefit
# http://www.webreaper.net/
User-agent: WebReaper
Disallow: /
# Per their statement, semrushbot respects crawl-delay directives
# We want them to overall stay within reasonable request rates to
# the backend (20 rps); keeping in mind that the crawl-delay will
# be applied by site and not globally by the bot, 5 seconds seem
# like a reasonable approximation
User-agent: SemrushBot
Crawl-delay: 5
#
# Friendly, low-speed bots are welcome viewing pages, but not
# dynamically-generated pages please.
#
# Another exception is for REST API documentation, located at
# /api/rest_v1/?doc.
#
User-agent: *
Disallow: /api/

View File

@@ -5,8 +5,14 @@ require 'rails_helper'
RSpec.describe 'Activities', type: :request do
subject { JSON.parse response.body }
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
let!(:activity) { FactoryBot.create(:activity, garden: create(:garden), planting: create(:planting)) }
let(:member) { create(:member) }
let(:token) do
member.regenerate_api_token
member.api_token.token
end
let(:headers) { { 'Accept' => 'application/vnd.api+json', 'Content-Type' => 'application/vnd.api+json' } }
let(:auth_headers) { headers.merge('Authorization' => "Bearer #{token}") }
let!(:activity) { FactoryBot.create(:activity, owner: member, garden: create(:garden, owner: member), planting: create(:planting, owner: member)) }
let!(:activity2) { FactoryBot.create(:activity) }
it '#index' do
@@ -53,4 +59,37 @@ RSpec.describe 'Activities', type: :request do
expect(subject['data'][1]['id']).to eq(activity2.id.to_s)
end
end
context '#update' do
let(:params) do
{
'data' => {
'type' => 'activities',
'id' => activity.id.to_s,
'attributes' => {
'description' => 'A new description',
'finished' => true,
'due-date' => '2025-10-31'
}
}
}
end
it 'updates the activity' do
patch "/api/v1/activities/#{activity.id}", params: params.to_json, headers: auth_headers
expect(response).to have_http_status(:ok)
# Check response
expect(subject['data']['attributes']['description']).to eq('A new description')
expect(subject['data']['attributes']['finished']).to eq(true)
expect(subject['data']['attributes']['due-date']).to eq('2025-10-31')
# Check database
activity.reload
expect(activity.description).to eq('A new description')
expect(activity.finished).to eq(true)
expect(activity.due_date.to_s).to eq('2025-10-31')
end
end
end

View File

@@ -85,7 +85,7 @@ RSpec.describe 'Gardens', type: :request do
member.api_token.token
end
let(:headers) { { 'Accept' => 'application/vnd.api+json', 'Content-Type' => 'application/vnd.api+json' } }
let(:auth_headers) { headers.merge('Authorization' => "Token token=#{token}") }
let(:auth_headers) { headers.merge('Authorization' => "Bearer #{token}") }
let(:garden_params) do
{
data: {
@@ -116,7 +116,7 @@ RSpec.describe 'Gardens', type: :request do
member.api_token.token
end
let(:headers) { { 'Accept' => 'application/vnd.api+json', 'Content-Type' => 'application/vnd.api+json' } }
let(:auth_headers) { headers.merge('Authorization' => "Token token=#{token}") }
let(:auth_headers) { headers.merge('Authorization' => "Bearer #{token}") }
let(:garden) { create(:garden, owner: member) }
let(:other_member_garden) { create(:garden) }
let(:update_params) do
@@ -164,7 +164,7 @@ RSpec.describe 'Gardens', type: :request do
member.api_token.token
end
let(:headers) { { 'Accept' => 'application/vnd.api+json', 'Content-Type' => 'application/vnd.api+json' } }
let(:auth_headers) { headers.merge('Authorization' => "Token token=#{token}") }
let(:auth_headers) { headers.merge('Authorization' => "Bearer #{token}") }
let!(:garden) { create(:garden, owner: member) }
let(:other_member_garden) { create(:garden) }

View File

@@ -117,7 +117,7 @@ RSpec.describe 'Harvests', type: :request do
member.api_token.token
end
let(:headers) { { 'Accept' => 'application/vnd.api+json', 'Content-Type' => 'application/vnd.api+json' } }
let(:auth_headers) { headers.merge('Authorization' => "Token token=#{token}") }
let(:auth_headers) { headers.merge('Authorization' => "Bearer #{token}") }
let(:crop) { create(:crop) }
let(:planting) { create(:planting, owner: member) }
let(:plant_part) { create(:plant_part) }
@@ -156,7 +156,7 @@ RSpec.describe 'Harvests', type: :request do
member.api_token.token
end
let(:headers) { { 'Accept' => 'application/vnd.api+json', 'Content-Type' => 'application/vnd.api+json' } }
let(:auth_headers) { headers.merge('Authorization' => "Token token=#{token}") }
let(:auth_headers) { headers.merge('Authorization' => "Bearer #{token}") }
let(:harvest) { create(:harvest, owner: member) }
let(:other_member_harvest) { create(:harvest) }
let(:update_params) do
@@ -205,7 +205,7 @@ RSpec.describe 'Harvests', type: :request do
member.api_token.token
end
let(:headers) { { 'Accept' => 'application/vnd.api+json', 'Content-Type' => 'application/vnd.api+json' } }
let(:auth_headers) { headers.merge('Authorization' => "Token token=#{token}") }
let(:auth_headers) { headers.merge('Authorization' => "Bearer #{token}") }
let!(:harvest) { create(:harvest, owner: member) }
let(:other_member_harvest) { create(:harvest) }

View File

@@ -17,7 +17,8 @@ RSpec.describe 'Members', type: :request do
"harvests" => harvests_as_json_api,
"photos" => photos_as_json_api,
"plantings" => plantings_as_json_api,
"seeds" => seeds_as_json_api
"seeds" => seeds_as_json_api,
"activities" => activities_as_json_api
} }
end
@@ -41,6 +42,12 @@ RSpec.describe 'Members', type: :request do
"related" => "#{resource_url}/seeds" } }
end
let(:activities_as_json_api) do
{ "links" =>
{ "self" => "#{resource_url}/relationships/activities",
"related" => "#{resource_url}/activities" } }
end
let(:plantings_as_json_api) do
{ "links" =>
{ "self" =>
@@ -74,6 +81,7 @@ RSpec.describe 'Members', type: :request do
it { expect(subject['data']['relationships']).to include("seeds" => seeds_as_json_api) }
it { expect(subject['data']['relationships']).to include("harvests" => harvests_as_json_api) }
it { expect(subject['data']['relationships']).to include("photos" => photos_as_json_api) }
it { expect(subject['data']['relationships']).to include("activities" => activities_as_json_api) }
it { expect(subject['data']).to eq(member_encoded_as_json_api) }
end

View File

@@ -102,7 +102,7 @@ RSpec.describe 'Plantings', type: :request do
member.api_token.token
end
let(:headers) { { 'Accept' => 'application/vnd.api+json', 'Content-Type' => 'application/vnd.api+json' } }
let(:auth_headers) { headers.merge('Authorization' => "Token token=#{token}") }
let(:auth_headers) { headers.merge('Authorization' => "Bearer #{token}") }
let(:crop) { create(:crop) }
let(:garden) { create(:garden, owner: member) }
let(:planting_params) do
@@ -140,7 +140,7 @@ RSpec.describe 'Plantings', type: :request do
member.api_token.token
end
let(:headers) { { 'Accept' => 'application/vnd.api+json', 'Content-Type' => 'application/vnd.api+json' } }
let(:auth_headers) { headers.merge('Authorization' => "Token token=#{token}") }
let(:auth_headers) { headers.merge('Authorization' => "Bearer #{token}") }
let(:planting) { create(:planting, owner: member) }
let(:other_member_planting) { create(:planting) }
let(:update_params) do
@@ -189,7 +189,7 @@ RSpec.describe 'Plantings', type: :request do
member.api_token.token
end
let(:headers) { { 'Accept' => 'application/vnd.api+json', 'Content-Type' => 'application/vnd.api+json' } }
let(:auth_headers) { headers.merge('Authorization' => "Token token=#{token}") }
let(:auth_headers) { headers.merge('Authorization' => "Bearer #{token}") }
let!(:planting) { create(:planting, owner: member) }
let(:other_member_planting) { create(:planting) }

View File

@@ -68,7 +68,7 @@ RSpec.describe 'Seeds', type: :request do
member.api_token.token
end
let(:headers) { { 'Accept' => 'application/vnd.api+json', 'Content-Type' => 'application/vnd.api+json' } }
let(:auth_headers) { headers.merge('Authorization' => "Token token=#{token}") }
let(:auth_headers) { headers.merge('Authorization' => "Bearer #{token}") }
let(:crop) { create(:crop) }
let(:seed_params) do
{
@@ -103,7 +103,7 @@ RSpec.describe 'Seeds', type: :request do
member.api_token.token
end
let(:headers) { { 'Accept' => 'application/vnd.api+json', 'Content-Type' => 'application/vnd.api+json' } }
let(:auth_headers) { headers.merge('Authorization' => "Token token=#{token}") }
let(:auth_headers) { headers.merge('Authorization' => "Bearer #{token}") }
let(:crop) { create(:crop) }
let(:seed) { create(:seed, owner: member, crop: crop) }
let(:other_member_seed) { create(:seed) }
@@ -152,7 +152,7 @@ RSpec.describe 'Seeds', type: :request do
member.api_token.token
end
let(:headers) { { 'Accept' => 'application/vnd.api+json', 'Content-Type' => 'application/vnd.api+json' } }
let(:auth_headers) { headers.merge('Authorization' => "Token token=#{token}") }
let(:auth_headers) { headers.merge('Authorization' => "Bearer #{token}") }
let(:crop) { create(:crop) }
let!(:seed) { create(:seed, owner: member, crop: crop) }
let(:other_member_seed) { create(:seed) }