Skip to content

Commit

Permalink
Rename of_service scope to all_available
Browse files Browse the repository at this point in the history
previous name was hard to understand, and incorrect, since features may
belong to service or account plans
  • Loading branch information
jlledom committed Nov 28, 2024
1 parent ef08f84 commit a5d6b40
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
11 changes: 4 additions & 7 deletions app/models/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,10 @@ def visible
plan.has_many :plan_metrics, foreign_key: :plan_id, &Logic::MetricVisibility::OfMetricAssociationProxy
end

has_many :features_plans, :as => :plan

# FIXME: this should be a simple HABTM
# No it can't, because it is POLYMORPHIC
has_many :features, :through => :features_plans do
# returns all features owned by issuer, not only enabled by plan
def of_service
has_many :features_plans, as: :plan, dependent: :delete_all
has_many :features, through: :features_plans do # Only enabled features
# returns all features available for this plan, not only enabled ones
def all_available
owner = proxy_association.owner
owner.issuer.features.with_object_scope(owner)
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/api/plans/_features.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

<tbody>

<tr class="notice" <%= "style=display:none;" unless @plan.features.of_service.empty? -%>>
<tr class="notice" <%= "style=display:none;" unless @plan.features.all_available.empty? -%>>
<td colspan="4">
<span>This plan has no features yet.</span>
</td>
</tr>

<%= render :partial => 'api/features/feature', :collection => @plan.features.of_service %>
<%= render :partial => 'api/features/feature', :collection => @plan.features.all_available %>
</tbody>
</table>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def setup

xml = Nokogiri::XML::Document.parse(@response.body)

assert_all_features_of_service xml, service
assert_all_features_available xml, service
end

test 'show' do
Expand Down
2 changes: 1 addition & 1 deletion test/test_helpers/xml_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def assert_an_application_plan(xml, service)
assert xml.xpath('.//plan/cancellation_period').presence
end

def assert_all_features_of_service(xml, service)
def assert_all_features_available(xml, service)
assert xml.xpath('.//features/feature/service_id').presence
assert xml.xpath('.//features/feature/service_id')
.all? { |service_id| service_id.text == service.id.to_s }
Expand Down

0 comments on commit a5d6b40

Please sign in to comment.