diff --git a/README.md b/README.md index 781861b7..09be7c9f 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,11 @@ docker-compose run app bundle exec rake assets:precompile docker-compose up -d ``` +To run tests in your docker container, you will need to override the environment, like so: +``` +docker-compose exec -e RAILS_ENV=test app rspec +``` + ## Requirements To deploy Cobra, you only need Docker Compose and a way of getting the repository onto your server (such as git). diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 579390b4..e4cf735c 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -76,7 +76,7 @@ def destroy def upload_to_abr authorize @tournament - response = AbrUpload.upload!(@tournament) + response = AbrUpload.upload!(@tournament, tournament_url(@tournament.slug, @request)) if(response[:code]) @tournament.update(abr_code: response[:code]) diff --git a/app/services/abr_upload.rb b/app/services/abr_upload.rb index 171c9921..01da66c6 100644 --- a/app/services/abr_upload.rb +++ b/app/services/abr_upload.rb @@ -1,27 +1,28 @@ class AbrUpload attr_reader :tournament - def initialize(tournament) + def initialize(tournament, tournament_url) @tournament = tournament + @tournament_url = tournament_url end def upload! JSON.parse(send_data).with_indifferent_access end - def self.upload!(tournament) - new(tournament).upload! + def self.upload!(tournament, tournament_url) + new(tournament, tournament_url).upload! end private - def send_data + def send_data() Faraday.new do |conn| conn.request :multipart conn.adapter :net_http conn.request :basic_auth, 'cobra', Rails.application.secrets.abr_auth end.post endpoint do |req| - upload = Faraday::UploadIO.new(StringIO.new(json), 'text/json') + upload = Faraday::UploadIO.new(StringIO.new(json(@tournament, @tournament_url)), 'text/json') req.body = { jsonresults: upload } end.body end @@ -30,7 +31,7 @@ def endpoint "#{Rails.configuration.abr_host}/api/nrtm" end - def json - NrtmJson.new(tournament).data.to_json + def json(tournament, tournament_url) + NrtmJson.new(@tournament).data(@tournament_url).to_json end end diff --git a/spec/fixtures/files/nrtm_json_cut.json b/spec/fixtures/files/nrtm_json_cut.json index 0606878d..4ef883d7 100644 --- a/spec/fixtures/files/nrtm_json_cut.json +++ b/spec/fixtures/files/nrtm_json_cut.json @@ -138,6 +138,6 @@ "uploadedFrom": "Cobra", "links": [ { "rel": "schemaderivedfrom", "href": "http://steffens.org/nrtm/nrtm-schema.json" }, - { "rel": "uploadedfrom", "href": "http://cobr.ai/SLUG" } + { "rel": "uploadedfrom", "href": "https://server/SLUG" } ] } diff --git a/spec/fixtures/files/nrtm_json_swiss.json b/spec/fixtures/files/nrtm_json_swiss.json index c3311c9d..b9563a94 100644 --- a/spec/fixtures/files/nrtm_json_swiss.json +++ b/spec/fixtures/files/nrtm_json_swiss.json @@ -80,6 +80,6 @@ "uploadedFrom": "Cobra", "links": [ { "rel": "schemaderivedfrom", "href": "http://steffens.org/nrtm/nrtm-schema.json" }, - { "rel": "uploadedfrom", "href": "http://cobr.ai/SLUG" } + { "rel": "uploadedfrom", "href": "https://server/SLUG" } ] } diff --git a/spec/services/abr_upload_spec.rb b/spec/services/abr_upload_spec.rb index d4672dc4..79297de6 100644 --- a/spec/services/abr_upload_spec.rb +++ b/spec/services/abr_upload_spec.rb @@ -1,5 +1,5 @@ RSpec.describe AbrUpload do - let(:upload) { described_class.new(tournament) } + let(:upload) { described_class.new(tournament, 'https://server/SLUG') } let(:tournament) { create(:tournament, name: 'Some Tournament') } let(:jack) { create(:player, corp_identity: 'ETF', runner_identity: 'Noise') } let(:jill) { create(:player, corp_identity: 'PE', runner_identity: 'Gabe') } @@ -11,12 +11,12 @@ describe '.upload!' do before do - allow(described_class).to receive(:new).with(tournament).and_return(upload) + allow(described_class).to receive(:new).with(tournament, 'https://server/SLUG').and_return(upload) allow(upload).to receive(:upload!) end it 'calls new instance' do - described_class.upload!(tournament) + described_class.upload!(tournament, 'https://server/SLUG') expect(upload).to have_received(:upload!) end diff --git a/spec/services/nrtm_json_spec.rb b/spec/services/nrtm_json_spec.rb index 96d5ad7e..a6b966b2 100644 --- a/spec/services/nrtm_json_spec.rb +++ b/spec/services/nrtm_json_spec.rb @@ -44,7 +44,7 @@ end it 'returns hash of data' do - expect(json.data.with_indifferent_access).to eq( + expect(json.data('https://server/SLUG').with_indifferent_access).to eq( JSON.parse(file_fixture('nrtm_json_swiss.json').read) ) end @@ -68,7 +68,7 @@ end it 'returns hash of data' do - expect(JSON.parse(json.data.to_json)).to eq( + expect(JSON.parse(json.data('https://server/SLUG').to_json)).to eq( JSON.parse(file_fixture('nrtm_json_cut.json').read) ) end