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

Basic comparison of business times #92

Closed
pacso opened this issue Oct 9, 2014 · 3 comments
Closed

Basic comparison of business times #92

pacso opened this issue Oct 9, 2014 · 3 comments
Milestone

Comments

@pacso
Copy link

pacso commented Oct 9, 2014

I am trying to test a service which provides calculated deadlines for records. My test goes something like this:

require 'rails_helper'

RSpec.describe CalculateDeadline, type: :model do
  describe 'for priority certificates' do
    let(:certificate) { create :certificate, service_level: 'priority' }

    it 'returns 3 business days' do
      expect(CalculateDeadline.call certificate).to eq 3.business_days
    end
  end
end

Of course, this fails miserably since there are no comparison methods provided and the two times are separate instances of BusinessTime::BusinessDays and as such not identical.

Can we add an equality evaluation method. If not, please explain how else I should test my code without either creating two Time instances to compare, or poking about in the instance with something like 3.business_days.instance_variable_get('@days').

@pacso pacso changed the title Basic comparison and manipulation methods Basic comparison of business times Oct 9, 2014
@bokmann
Copy link
Owner

bokmann commented Nov 3, 2014

Interesting use... I always considered the objects returned by something like "3.business_days" to be throwaway; just someplace to hang the math related to the integer and time. I like this use case though, and fixing this should be as simple as implementing the spaceship operator on BusinessHours and BusinessDays and delegating to the integer they wrap.

@pacso
Copy link
Author

pacso commented Nov 3, 2014

That's what I thought, however having recently done some work on another gem which was eventually discarded by the maintainer I figured I'd make sure something like this would be wanted prior to wasting any more time.

I'm happy to put something together at the weekend and send you a pull request.

@bokmann bokmann added this to the 0.8+ milestone Apr 12, 2015
@bokmann
Copy link
Owner

bokmann commented Apr 12, 2015

Just implemented this.

@bokmann bokmann closed this as completed Apr 12, 2015
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

No branches or pull requests

2 participants