Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
WIP. Attempt at adding a many-to-one floors to library reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
sdellis committed Jun 14, 2016
1 parent 2ece830 commit f55e5f6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/controllers/locations/floors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def create
if @floor.save
redirect_to @floor, notice: 'Floor was successfully created.'
else
flash.now[:error] = @floor.errors.full_messages
render :new
end
end
Expand Down Expand Up @@ -56,7 +57,7 @@ def set_floor

# Only allow a trusted parameter "white list" through.
def floor_params
params.require(:floor).permit(:label, :floor_plan_uri, :starting_point, :walkable_areas)
params.require(:floor).permit(:label, :floor_plan_uri, :starting_point, :walkable_areas, :locations_library_id)
end
end
end
4 changes: 4 additions & 0 deletions app/models/locations/floor.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module Locations
class Floor < ActiveRecord::Base
include Locations::Labeled
include Locations::WithLibrary

belongs_to :holding_library, class_name: 'Locations::Library', foreign_key: :holding_library_id

end
end
5 changes: 5 additions & 0 deletions db/migrate/20160614154022_add_library_to_floors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddLibraryToFloors < ActiveRecord::Migration
def change
add_reference :floors, :library, index: true, foreign_key: true
end
end
11 changes: 9 additions & 2 deletions spec/controllers/locations/floors_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ module Locations
# This should return the minimal set of attributes required to create a valid
# Floor. As you add validations to Floor, be sure to
# adjust the attributes here as well.

let(:valid_attributes) {
skip("Add a hash of attributes valid for your model")
FactoryGirl.attributes_for(:floor)
}

let(:invalid_attributes) {
skip("Add a hash of attributes invalid for your model")
FactoryGirl.attributes_for(:floor, library: nil)
}

# This should return the minimal set of values that should be in the session
Expand Down Expand Up @@ -71,6 +72,12 @@ module Locations
end

describe "POST #create" do
let(:valid_attributes) {
attrs = FactoryGirl.attributes_for(:floor)
library = FactoryGirl.create(:library)
attrs[:locations_library_id] = library.id
attrs
}
context "with valid params" do
it "creates a new Floor" do
expect {
Expand Down
1 change: 1 addition & 0 deletions spec/factories/locations/floors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
floor_plan_uri { Faker::Internet.url }
starting_point "10,10,10,10"
walkable_areas "<svg></svg>"
library
end

end
7 changes: 7 additions & 0 deletions spec/models/locations/floor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ module Locations
it 'factory creates a valid instance' do
expect(subject.valid?).to be_truthy
end

it 'must have a library associated with it' do
expect {
FactoryGirl.create(:floor, library: nil)
}.to raise_error ActiveRecord::RecordInvalid
end

end
end
end

0 comments on commit f55e5f6

Please sign in to comment.