-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
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
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 |