Skip to content

Commit

Permalink
fix associations for status + fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
one-m1nd committed Mar 4, 2024
1 parent bdd51e9 commit b6deaeb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/plants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class PlantsController < ApplicationController

# GET /plants or /plants.json
def index
@plants = Plant.all.includes(:genus, :family).sort_by(&:name)
@plants = Plant.all.includes(:genus, :family, :status).sort_by(&:name)
end

# GET /plants/1 or /plants/1.json
Expand Down
6 changes: 1 addition & 5 deletions app/models/plant.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
class Plant < ApplicationRecord
belongs_to :family
belongs_to :genus
has_one :status

def status
Status.find(status_id)
end
belongs_to :status

# @return [Hash]
def trefle_data
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/plants_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PlantsControllerTest < ActionDispatch::IntegrationTest

test "should create plant" do
assert_difference("Plant.count") do
post plants_url, params: { plant: { name: 'PlantThree', family_id: 1, genus_id: 1 } }
post plants_url, params: { plant: { name: 'PlantThree', family_id: 1, genus_id: 1, status_id: 1 } }
end

assert_redirected_to plant_url(Plant.last)
Expand Down

0 comments on commit b6deaeb

Please sign in to comment.