Skip to content

Conversation

@ipundit
Copy link
Contributor

@ipundit ipundit commented Sep 19, 2023

first() is defined to return the first record in the table, despite order('author_id DESC'). Or should the spec be changed to?:

$author = Author::order('author_id DESC')->first();
$author2 = Author::order('author_id ASC')->last();

$this->assertEquals($author, $author2);

According to https://edgeguides.rubyonrails.org/active_record_querying.html#first

If your default scope contains an order method, first will return the first record according to this ordering.

the answer is 'yes', so there is a bug in the original test case. This is fixed in the latest commit. If you want to refactor from here, be my guest.

ipundit added 30 commits August 31, 2023 18:10
…at capitalization for attribute names are retained. So the short form for New York is now NY instead of ny. test/model/Author, Book, and Venue now have those strtoupper() workarounds in getter/setter methods removed as it's done in Model.php
…rcased in Model.php in order to be case insensitive.
…at capitalization for attribute names are retained. So the short form for New York is now NY instead of ny. test/model/Author, Book, and Venue now have those strtoupper() workarounds in getter/setter methods removed as it's done in Model.php
…rcased in Model.php in order to be case insensitive.
…cord

# Conflicts:
#	test/ActiveRecordTest.php
#	test/models/Book.php
…Disable it so that regression does not timeout.
…d#35:

Authors table now has a column that is camel cased: firstName
Added tests that demonstrate case insensitivity when accessing this firstName column
- Correct link to contributing.md
…cord

# Conflicts:
#	composer.json
#	scripts/TestCommand.php
…RecordFindByTest.php and ActiveRecordFromTest.php respectively

- In doing the above, found and removed duplicated tests
- Added test for Relation::testFindBySelect()
1) Author::order('author_id DESC')->find_by_name('Tito'); would clobber order
2) Author::limit(2)->find_by_name('Tito'); would clobber limit
…. This now passes:

  $rel = Author::limit(2)->order('author_id DESC');
  $this->assertEquals(Author::last(), $rel->first());
  $this->assertEquals(Author::first(), $rel->last());
@codecov
Copy link

codecov bot commented Sep 19, 2023

Codecov Report

Merging #85 (ab321f3) into master (ac4bfa9) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##             master      #85   +/-   ##
=========================================
  Coverage     96.73%   96.73%           
  Complexity      964      964           
=========================================
  Files            33       33           
  Lines          2358     2358           
=========================================
  Hits           2281     2281           
  Misses           77       77           
Files Changed Coverage Δ
lib/Relation.php 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@shmax
Copy link
Contributor

shmax commented Sep 19, 2023

If you want to refactor from here

Naw, I had a look at your code and it was perfectly fine. I just renamed your method. 😄

Copy link
Contributor

@shmax shmax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna take your word for it on this one. 👍

@shmax shmax merged commit 3651bac into php-activerecord:master Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants