Skip to content
This repository was archived by the owner on Jul 24, 2020. It is now read-only.

[1624] Add option to disable requests #1625

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

Conversation

esoterik
Copy link
Collaborator

Blocking on #1586.

Resolves #1624

@orenyk
Copy link
Contributor

orenyk commented Sep 19, 2016

Can we rebase this before review?

@esoterik esoterik force-pushed the 1624_disable_requests_option branch from 92c57bc to 435ba14 Compare October 9, 2016 20:35
@esoterik
Copy link
Collaborator Author

esoterik commented Oct 9, 2016

Rebased!

Copy link
Contributor

@orenyk orenyk left a comment

Choose a reason for hiding this comment

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

A few minor changes and one discussion about the multiple extracted methods in the service object. Overall well done, hopefully we can actually get this stuff merged in 😄.

@@ -0,0 +1,60 @@
# frozen_string_literal: true
Copy link
Contributor

Choose a reason for hiding this comment

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

OMG, Service Objects!

<div id="content" class="col-md-9">
<% unless @errors.empty? %>
<p>
<h3><i class="fa fa-exclamation-triangle warning-icon"></i> Would you like to resolve the following error(s)?</h3>
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably read Please resolve the following error(s): since they can't be overriden by the student.

override && !cart_errors.blank?
end

def valid_override?
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to extract this separately? I feel like we have a bunch of little methods that aren't strictly necessary. For example, the only time it's used (L31 - override? && !(override? && !notes.blank?)), is equivalent to override? && notes.blank? (if I'm expanding correctly).

I guess I see how this is useful in making the code easier to read, but I think what's bothering me is the use of override? inside valid_override? when it's just cancelled out in the override? necessarily. This also applies to valid_request?. Thoughts?

before do
allow_any_instance_of(described_class).to \
receive(:cart).and_return(cart)
allow_any_instance_of(described_class).to receive(:fix_cart_date)
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeesh these smell a bit to me, but it's definitely out of scope for this issue.

current_user: current_user,
**attrs)
results = creator.create!
expect(results[:result]).to be_truthy
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to make assertions about the value of results[:result] since it's used when processing the successful result in the controller?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think so -- this is also a part of the move away from controller tests (though Reservations might not really make it all the way there)

Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, I feel like this discussion wasn't resolved. I think was asking if we should also be asserting against the actual value of results[:results], not just whether or not it's truthy. Am I missing something?

@@ -28,7 +28,11 @@
describe UserMailer, type: :mailer do
before(:each) do
@ac = mock_app_config(admin_email: '[email protected]',
disable_user_emails: false)
disable_user_emails: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Where did all of these come from and why did we only run into this now?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh wait, is it from switching from spy to instance_spy? Do you remember why we did this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm pretty sure it's from switching to instance_spy which is safer because it only lets you stub out things that exist in the real class.

@esoterik
Copy link
Collaborator Author

refactored the service object a bit and rebased!

Resolves #1624
  - Adds a Service Object for reservation creation
@esoterik esoterik force-pushed the 1624_disable_requests_option branch from 5da4f10 to bfe944e Compare November 20, 2016 21:41
Copy link
Contributor

@orenyk orenyk left a comment

Choose a reason for hiding this comment

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

One more comment on the ReservationCreator and a question about the templates. Almost there!

<%= render partial: 'new_reservation' %>
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why we need partials for this if we now have independent views for each of the different cases that are rendered independently - can we just move the partial content into the full views?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's necessary for how the reservation_form JS works

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea fair enough. I feel like there might be a way to improve this but it's really not critical.

end

def needs_notes?
(request? || override?) && notes.blank?
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't request? || override? equivalent to !cart_errors.blank?, since request? is true if override is falsey and override? is true if override is truthy?

Copy link
Contributor

Choose a reason for hiding this comment

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

This would eliminate the need for the override? method, I believe.

flash[:error] = 'Please give a short justification for this reservation'
@notes_required = true
@request_text = if AppConfig.get(:request_text).empty?
'Please give a short justification for this '\
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is a little out of scope but it seems like we should just set this as a default value for request_text rather than having this live in the controller

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea... that's a great point. I'll open up an issue.

@esoterik
Copy link
Collaborator Author

esoterik commented Dec 2, 2016

pushed an update

Copy link
Contributor

@orenyk orenyk left a comment

Choose a reason for hiding this comment

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

Ok revisiting an old discussion, but this should be it. Thanks!

current_user: current_user,
**attrs)
results = creator.create!
expect(results[:result]).to be_truthy
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, I feel like this discussion wasn't resolved. I think was asking if we should also be asserting against the actual value of results[:results], not just whether or not it's truthy. Am I missing something?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants