Skip to content

Commit

Permalink
Subscriptions with many line items can be edited
Browse files Browse the repository at this point in the history
The admin subscriptions form was not updated to support the 1 to many
relationship between subscriptions and subscription line items. This
updated the existing form to support editing multiple line items per
subscription
  • Loading branch information
Brendan Deere committed Jul 24, 2017
1 parent 593e001 commit f0ed040
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 36 deletions.
70 changes: 35 additions & 35 deletions app/views/spree/admin/subscriptions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,48 @@
<% end %>
</fieldset>

<%= f.fields_for :line_item, @line_item do |lf| %>
<div class="row">
<%= content_tag :div, class: "field alpha three columns" do %>
<%= f.label :actionable_date %>
<%= f.text_field :actionable_date, class: "fullwidth datepicker" %>
<% end %>
<div class="row">
<%= content_tag :div, class: "field alpha three columns" do %>
<%= f.label :actionable_date %>
<%= f.text_field :actionable_date, class: "fullwidth datepicker" %>
<% end %>

<div class='field three columns'>
<%= lf.label :inverval_length %>
<%= lf.number_field :interval_length, class: "fullwidth" %>
</div>
<div class='field three columns'>
<%= f.label :inverval_length %>
<%= f.number_field :interval_length, class: "fullwidth" %>
</div>

<div class='field three columns'>
<%= lf.label :interval_units %>
<%
unit_values = SolidusSubscriptions::LineItem.interval_units.keys
units = unit_values.map do |unit|
[
unit,
SolidusSubscriptions::LineItem.human_attribute_name("interval_units.#{ unit }")
]
end
%>
<div class='field three columns'>
<%= f.label :interval_units %>
<%
unit_values = SolidusSubscriptions::LineItem.interval_units.keys
units = unit_values.map do |unit|
[
unit,
SolidusSubscriptions::LineItem.human_attribute_name("interval_units.#{ unit }")
]
end
%>

<div>
<% units.each_with_index do |(value, name), i| %>
<div>
<%= lf.label :interval_units, for: "interval_units_#{ value }", class: 'fullwidth' do %>
<%= lf.radio_button :interval_units, value, id: "interval_units_#{ value }" %>
<%= name %>
<% end %>
</div>
<% end %>
</div>
<div>
<% units.each_with_index do |(value, name), i| %>
<div>
<%= f.label :interval_units, for: "interval_units_#{ value }", class: 'fullwidth' do %>
<%= f.radio_button :interval_units, value, id: "interval_units_#{ value }" %>
<%= name %>
<% end %>
</div>
<% end %>
</div>
</div>

<div class="field omega three columns">
<%= lf.label :end_date %>
<%= lf.date_field :end_date, class: "required", class: "fullwidth" %>
</div>
<div class="field omega three columns">
<%= f.label :end_date %>
<%= f.date_field :end_date, class: "required fullwidth" %>
</div>
</div>

<%= f.fields_for :line_items do |lf| %>
<fieldset class='no-border-bottom'>
<legend><%= t('.subscription_line_item') %></legend>

Expand Down
27 changes: 26 additions & 1 deletion spec/controllers/spree/admin/subscriptions_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'rails_helper'

RSpec.describe Spree::Admin::SubscriptionsController, type: :controller do
routes { Spree::Core::Engine.routes }
stub_authorization!
Expand All @@ -16,6 +15,32 @@
it { is_expected.to be_successful }
end

describe 'GET :edit' do
subject { get :edit, params: { id: subscription.id } }
let(:subscription) { create :subscription, :actionable }

it { is_expected.to be_successful }
end

describe 'PUT :update' do
subject { put :update, params: subscription_params }

let(:expected_date) { DateTime.parse('2001/11/12') }
let(:subscription) { create :subscription, :actionable }
let(:subscription_params) do
{
id: subscription.id,
subscription: { actionable_date: expected_date }
}
end

it { is_expected.to redirect_to admin_subscriptions_path }

it 'updates the subscription attributes', :aggregate_failures do
expect { subject }.to change { subscription.reload.actionable_date }.to expected_date
end
end

describe 'POST cancel' do
subject { delete :cancel, params: { id: subscription.id } }
context 'the subscription can be canceled' do
Expand Down

0 comments on commit f0ed040

Please sign in to comment.