From 1af87e5ca6b12ef3b17ac33536a9960703571c99 Mon Sep 17 00:00:00 2001 From: Oleksii Leonov Date: Wed, 8 May 2024 14:32:12 +0000 Subject: [PATCH] feat: add description setter to MajorObject --- lib/gdal/major_object.rb | 6 ++++++ spec/unit/gdal/major_object_spec.rb | 31 +++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/gdal/major_object.rb b/lib/gdal/major_object.rb index 56d94697..a9a07122 100644 --- a/lib/gdal/major_object.rb +++ b/lib/gdal/major_object.rb @@ -75,6 +75,12 @@ def description desc end + # @param description [String] + # @return [String] + def description=(description) + FFI::GDAL::GDAL.GDALSetDescription(@c_pointer, description) + end + def null? @c_pointer.null? end diff --git a/spec/unit/gdal/major_object_spec.rb b/spec/unit/gdal/major_object_spec.rb index 18acd331..d1d3ec8e 100644 --- a/spec/unit/gdal/major_object_spec.rb +++ b/spec/unit/gdal/major_object_spec.rb @@ -3,7 +3,34 @@ require "gdal/major_object" RSpec.describe GDAL::MajorObject do - subject { Object.new.extend(described_class) } + subject { band.extend(described_class) } - pending "Add some tests!" + let(:driver) { GDAL::Driver.by_name("GTiff") } + let(:dataset) { driver.create_dataset("/vsimem/test-#{SecureRandom.uuid}.tif", 1, 1) } + let(:band) { dataset.raster_band(1) } + after { dataset.close } + + describe "#description" do + context "when the object has no description" do + it "returns an empty string" do + expect(subject.description).to eq("") + end + end + + context "when the object has a description" do + before { subject.description = "This is a description" } + + it "returns the description of the object" do + expect(subject.description).to eq("This is a description") + end + end + end + + describe "#description=" do + it "sets the description of the object" do + expect(subject.description).to eq("") + subject.description = "This is a description" + expect(subject.description).to eq("This is a description") + end + end end