Skip to content

Commit

Permalink
Standalone DTO inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
santib committed Jul 1, 2022
1 parent 0ebb4f4 commit ad6dc57
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions spec/ar2dto/dto_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

RSpec.describe AR2DTO::DTO do
let(:klass) do
Class.new(described_class[User]) do
def self.name
"AnonymousDTO"
end
end
end

let(:attributes) do
{
first_name: "Sandy",
last_name: "Doe",
email: "sandy@example.com",
birthday: Time.new(1995, 8, 25),
status: "pending"
}
end
let(:user) { User.new(attributes) }

context "initialized with value attributes" do
subject { klass.new(user.attributes) }

it "responds to defined methods" do
expect(subject.first_name).to eq("Sandy")
end

it "implements equality" do
expect(subject).to eq(klass.new(user.attributes))
expect(subject).to_not eq(klass.new(user.attributes.merge(first_name: "Other")))
end

it "does not respond to other methods" do
expect(subject).to_not respond_to(:undefined_method)
end

it_behaves_like "ActiveModel"
end
end

0 comments on commit ad6dc57

Please sign in to comment.