Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WpApiClient::Collection: Added accessor to get total pages for a cust… #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

gadikotamohan
Copy link

WpApiClient::Collection: Added accessor to get total pages for a custom post_type posts

@gadikotamohan
Copy link
Author

@duncanjbrown Could review ?

@duncanjbrown
Copy link
Owner

Thank you! Would you mind adding a spec?

@mgadikota-rpx
Copy link

@duncanjbrown added spec please review..

@mgadikota-rpx
Copy link

WpApiClient::Collection
  fetching posts of a certain post type
    returns an array of posts
    can paginate
    accepts array and non-array input
    responds to array methods
    should respond to total_pages and total_available
    should respond to total_pages and total_available
WARNING: Using the `raise_error` matcher without providing a specific error or message risks false positives, since `raise_error` will match when Ruby raises a `NoMethodError`, `NameError` or `ArgumentError`, potentially allowing the expectation to pass without even executing the method you are intending to call. Actual error raised was #<WpApiClient::ErrorResponse: WpApiClient::ErrorResponse>. Instead consider providing a specific error class or message. This message can be suppressed by setting: `RSpec::Expectations.configuration.on_potential_false_positives = :nothing`. Called from /Users/mohan/WorkSpace/playground/wp-api-client/spec/collection_spec.rb:53:in `block (3 levels) in <top (required)>'.
    throws an error when it tries to parse an error response

WpApiClient::Collection
  fetching posts concurrently
    allows simultaneous fetching of posts

WpApiClient::Entities::Base
  general entity methods
    work to retrieve embedded hypermedia
    work to retrieve non-embedded hypermedia
    allows querying on specific relations from posts to terms
    allows querying on specific relations from terms to posts

WpApiClient::Entities::Error
  an API access error
    throws an exception
    recognises the error JSON exception

WpApiClient::Entities::Image
  calling instance methods on an image object
    returns the URL for different sizes

WpApiClient::Entities::Post
  calling instance methods on a post
    returns the title
    returns the date as a Time object
    returns the content as HTML
    returns its own ID
    returns its own slug
    allows its internal resource to be queried directly
    returns its author
  meta function
    returns an individual meta value
    caches
    returns the right items from cache

WpApiClient::Relationship
  relationships with terms
    presents term objects as a set of key/value collections
  relationships with posts
    returns an collection of posts
  relationships with featured images
    returns an collection of posts
  relationships with metadata
    returns an hash of meta

WpApiClient::Entities::Taxonomy
  calling instance methods on a taxonomy
    returns the name
    returns a collection of terms

WpApiClient::Entities::Term
  reading data out of the term
    returns the name
    returns the slug
    returns a taxonomy object
  a term connected to two different post types
    returns two collections of posts

WpApiClient::Entities::User
  calling instance methods on a user
    returns the id

WpApiClient
  has a version number

WpApiClient::Configuration
  #configure
    can set the endpoint URL for the API connection
    can specify whether or not to request embedded resources
    can set up OAuth credentials
    can set up link relationships
    exposes a #proxy configuration option

Finished in 0.40895 seconds (files took 0.64956 seconds to load)
42 examples, 0 failures


@gadikotamohan
Copy link
Author

@duncanjbrown Please find rspec result in https://travis-ci.org/gadikotamohan/wp-api-client

Copy link
Owner

@duncanjbrown duncanjbrown left a comment

Choose a reason for hiding this comment

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

Thank you so much — Travis too! 🙌

Couple of minor comments.

it "should respond to total_pages and total_available" do
expect(@collection).to respond_to(:total_pages)
expect(@collection).to respond_to(:total_available)
end
Copy link
Owner

Choose a reason for hiding this comment

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

This spec has the same name as the below one and I think it's redundant?

Copy link
Author

Choose a reason for hiding this comment

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

@duncanjbrown yeah I will correct this.

it "should respond to total_pages and total_available" do
expect(@collection.total_pages).to eq(@api.instance_variable_get("@headers")["X-Wp-Totalpages"].to_i)
expect(@collection.total_available).to eq(@api.instance_variable_get("@headers")["X-Wp-Total"].to_i)
end
Copy link
Owner

@duncanjbrown duncanjbrown Jul 8, 2019

Choose a reason for hiding this comment

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

The right hand side is quite magical here. These values are hardcoded in the VCR cassettes: I believe X-WP-TOTAL is 100 and X-WP-TOTALPAGES is 10.

My whole testing approach here was flawed, but I think the least worst thing would be to put literals on the right hand side here, like this?

expect(@collection.total_pages).to eq(10)
expect(@collection.total_available).to eq(100)

Copy link
Author

Choose a reason for hiding this comment

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

@duncanjbrown making this change.

WpApiClient::Collection: Added accessor to get total pages for a custom post_type posts
@gadikotamohan
Copy link
Author

@duncanjbrown made suggested changes to code and please find rpsec status in https://travis-ci.org/gadikotamohan/wp-api-client/builds/556100532 (all specs are green)

@gadikotamohan
Copy link
Author

Hi @duncanjbrown got a chance to look into this ?

@mgadikota-rpx
Copy link

hi @duncanjbrown, have you got a chance to look into this PR ?

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.

3 participants