diff --git a/app/models/plan.rb b/app/models/plan.rb index a021fa8457..af54d79127 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -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 diff --git a/app/views/api/plans/_features.html.erb b/app/views/api/plans/_features.html.erb index a877e71c2b..875b08e284 100644 --- a/app/views/api/plans/_features.html.erb +++ b/app/views/api/plans/_features.html.erb @@ -15,13 +15,13 @@ - > + > This plan has no features yet. - <%= render :partial => 'api/features/feature', :collection => @plan.features.of_service %> + <%= render :partial => 'api/features/feature', :collection => @plan.features.all_available %> diff --git a/test/integration/user-management-api/service_features_test.rb b/test/integration/user-management-api/service_features_test.rb index b11b98a84e..e148084f02 100644 --- a/test/integration/user-management-api/service_features_test.rb +++ b/test/integration/user-management-api/service_features_test.rb @@ -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 diff --git a/test/test_helpers/xml_assertions.rb b/test/test_helpers/xml_assertions.rb index a84236f5ff..11f9536dd7 100644 --- a/test/test_helpers/xml_assertions.rb +++ b/test/test_helpers/xml_assertions.rb @@ -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 }