Skip to content

Commit

Permalink
pass district as param
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuuki77 committed Apr 5, 2021
1 parent bc5f8fe commit 73a4865
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 107 deletions.
15 changes: 7 additions & 8 deletions app/controllers/heritages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class HeritagesController < ApplicationController
before_action :load_district, only: [:index, :create, :update_with_district]
before_action :load_district, only: [:index, :create]
before_action :load_heritage, except: [:index, :create, :trigger]

before_action :load_district_by_param, only: [:update, :trigger]
skip_before_action :authenticate, only: [:trigger]

def index
Expand All @@ -22,13 +24,6 @@ def create
end

def update
@heritage = BuildHeritage.new(permitted_params).execute
@heritage.save_and_deploy!(without_before_deploy: false,
description: "Update to #{@heritage.image_path}")
render json: @heritage
end

def update_with_district
@heritage = BuildHeritage.new(permitted_params, district: @district).execute
@heritage.save_and_deploy!(without_before_deploy: false,
description: "Update to #{@heritage.image_path}")
Expand Down Expand Up @@ -158,6 +153,10 @@ def load_district
@district = District.find_by!(name: params[:district_id])
end

def load_district_by_param
@district = District.find_by(name: params[:district])
end

private

def service
Expand Down
2 changes: 0 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
post :env_vars, on: :member, to: "heritages#set_env_vars"
delete :env_vars, on: :member, to: "heritages#delete_env_vars"

post :update_with_district, on: :member, to: "heritages#update_with_district"

post "/trigger/:token", to: "heritages#trigger"
resources :oneoffs, only: [:show, :create]

Expand Down
32 changes: 31 additions & 1 deletion spec/requests/update_heritage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,37 @@
end
end


it "updates a heritage by specifying district name" do
params = {
district: district.name,
image_tag: "v3",
before_deploy: nil,
services: [
{
name: "web",
command: "true"
},
{
name: "worker",
command: "rake jobs:work"
}
]
}

expect(Heritage.last.services.find_by(name: 'web').cpu).to eq 128

expect(DeployRunnerJob).to receive(:perform_later)
api_request :patch, "/v1/heritages/nginx", params
expect(response).to be_successful
heritage = JSON.load(response.body)["heritage"]
token = JSON.load(response.body)["heritage"]["token"]
web_service = heritage["services"].find { |s| s["name"] == "web" }

expect(web_service["cpu"]).to be_nil
expect(Heritage.last.services.find_by(name: 'web').cpu).to be_nil
end

describe "POST /heritages/:heritage/trigger/:token", type: :request do
let(:district) { create :district }

Expand Down Expand Up @@ -211,7 +242,6 @@
expect(web_service["cpu"]).to be_nil
expect(Heritage.last.services.find_by(name: 'web').cpu).to be_nil
end

end

describe "with wrong heritage token", type: :request do
Expand Down
96 changes: 0 additions & 96 deletions spec/requests/update_heritage_with_district_spec.rb

This file was deleted.

0 comments on commit 73a4865

Please sign in to comment.