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

[56] Request to join groups #121

Merged
merged 1 commit into from
Jan 27, 2017
Merged

[56] Request to join groups #121

merged 1 commit into from
Jan 27, 2017

Conversation

esoterik
Copy link
Collaborator

Resolves #56

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 things we missed last night, but this is overall excellent IMO 😛. Let me know when I should give it a final skim.


def update_counter_cache
return unless status_changed?
increment_counter_cache
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm shouldn't this actually be if accepted?? I'm just thinking about cases where it goes from requested to invited hypothetically - that shouldn't trigger an increment of the counter cache. Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the increment only works if the status is accepted

# Class method to permit calling :create! on the class without instantiating
# the service object directly
#
# @param [#to_h] params The params object from the MembershipsController.
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's fix this comment since there is no MembershipsController.


# Initialize a MembershipCreator
#
# @param [#to_h] params The params object from the MembershipsController.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here re:comment


def success
{ object: [object.group.draw, object.group],
msg: { success: "#{object.user.full_name} accepted." } }
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a note, but we may want to make this message configurable for this object since it will likely be different for accepting invitations vs accepting requests. That will likely come into play in #107.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could just change it to "joined group" instead of "accepted"?

<% if policy(@group).request_to_join? %>
<%= link_to 'Request To Join', draw_group_request_path(@draw, @group), method: :post %>
<% end %>
<%= link_to('Delete', draw_group_path(@draw, @group), method: :delete) if policy(@group).destroy? %>
Copy link
Contributor

Choose a reason for hiding this comment

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

Another note, but this feels like it will be worth extracting into a partial for the footer where we can pass in the object in question as a local variable, since destroy? is always the relevant action across all the policies. I'll open an issue for this.

it 'succeeds' do # rubocop:disable RSpec/ExampleLength
group = FactoryGirl.create(:open_group)
user = FactoryGirl.create(:student, intent: 'on_campus', draw: group.draw)
MembershipCreator.create!(group: group, user: user, status: 'requested')
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we just use Membership.create here? I'm not sure what the service object adds since we're passing all the same parameters in.

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 what we did in all the other specs, so I'd recommend changing it here.

it 'returns an array of users who have requested to join' do
group = FactoryGirl.create(:open_group)
user = FactoryGirl.create(:student, intent: 'on_campus', draw: group.draw)
Membership.create(group: group, user: user, status: 'requested')
Copy link
Contributor

Choose a reason for hiding this comment

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

Lol, see my previous comment - we weren't even consistent last night 😛.

@@ -33,6 +34,19 @@ def destroy
handle_action(**result)
end

def request_to_join
result = MembershipCreator.new(group: @group, user: current_user,
status: 'requested').create!
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

should be changed to just call create! directly

Resolves #56
  - Adds Membership creator / updater objects
  - Adds status to Memberships
  - Changes Group#memberships_count to a conditional counter
    cache that only counts accepted memberships towards the total
@esoterik esoterik merged commit 58ceb01 into master Jan 27, 2017
@esoterik esoterik deleted the 56_request_to_join_groups branch January 27, 2017 16:53
@orenyk orenyk mentioned this pull request Jan 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants