Created
February 25, 2019 18:42
-
-
Save daniel-rikowski/251c95155c63223ae4fe4601716f935e to your computer and use it in GitHub Desktop.
Array of points error (Rails 6)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem "rails", github: "rails/rails" | |
gem 'pg' | |
end | |
require "active_record" | |
require "minitest/autorun" | |
require "logger" | |
ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'TODO', username: 'TODO', password: 'TODO') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :shapes, force: true do |t| | |
t.column :centroid, :point | |
t.column :polygon, :point, array: true | |
end | |
end | |
class Shape < ActiveRecord::Base | |
end | |
class ArrayOfPointsTest < Minitest::Test | |
def test_point # Succeeds! | |
Shape.create!(centroid: [0.4, 0.7]) | |
end | |
def test_array_of_points # Fails! | |
Shape.create!(polygon: [[0.1, 0.2], | |
[0.3, 0.4], | |
[0.5, 0.6], | |
[0.7, 0.8], | |
[0.1, 0.2]]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment