From 5e59f7b79d36e7c0ddde5dbef743604a5a2d65e9 Mon Sep 17 00:00:00 2001 From: Michael Kohl Date: Mon, 24 Aug 2020 11:55:53 +0700 Subject: [PATCH] [deploy] Stop using ProfileField#active Part 1 (#9910) * Stop using ProfileField#active * Fix specs --- app/models/profile.rb | 4 ++-- app/models/profile_field.rb | 5 ++--- app/views/admin/profile_fields/_form.html.erb | 4 ---- spec/factories/profile_fields.rb | 1 - spec/models/profile_field_spec.rb | 1 - spec/models/profile_spec.rb | 2 -- spec/requests/admin/profile_fields_spec.rb | 8 +++----- 7 files changed, 7 insertions(+), 18 deletions(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index dab8789f4..e3ad58dea 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -3,9 +3,9 @@ class Profile < ApplicationRecord validates :user_id, uniqueness: true - # This method generates typed accessors for all active profile fields + # This method generates typed accessors for all profile fields def self.refresh_store_accessors! - ProfileField.active.find_each do |field| + ProfileField.find_each do |field| store_attribute :data, field.attribute_name, field.type end end diff --git a/app/models/profile_field.rb b/app/models/profile_field.rb index 68c02668c..ffeea8375 100644 --- a/app/models/profile_field.rb +++ b/app/models/profile_field.rb @@ -1,4 +1,6 @@ class ProfileField < ApplicationRecord + self.ignored_columns = ["active"] + before_create :generate_attribute_name WORD_REGEX = /\w+/.freeze @@ -17,12 +19,9 @@ class ProfileField < ApplicationRecord } validates :label, presence: true, uniqueness: { case_sensitive: false } - validates :active, inclusion: { in: [true, false] } validates :attribute_name, presence: true, on: :update validates :show_in_onboarding, inclusion: { in: [true, false] } - scope :active, -> { where(active: true) } - def type return :boolean if check_box? diff --git a/app/views/admin/profile_fields/_form.html.erb b/app/views/admin/profile_fields/_form.html.erb index a415383de..89a77999c 100644 --- a/app/views/admin/profile_fields/_form.html.erb +++ b/app/views/admin/profile_fields/_form.html.erb @@ -18,7 +18,3 @@ <%= form.label :input_type %> <%= form.select :input_type, ProfileField.input_types.keys, class: "form-control" %> -
- <%= form.label :active %> - <%= form.check_box :active %> -
diff --git a/spec/factories/profile_fields.rb b/spec/factories/profile_fields.rb index c3081492b..d7f35ce15 100644 --- a/spec/factories/profile_fields.rb +++ b/spec/factories/profile_fields.rb @@ -4,7 +4,6 @@ FactoryBot.define do input_type { :text_field } description { "some description" } placeholder_text { "john.doe@example.com" } - active { true } group { "Basic" } trait :onboarding do diff --git a/spec/models/profile_field_spec.rb b/spec/models/profile_field_spec.rb index f175e2c24..179ee0a63 100644 --- a/spec/models/profile_field_spec.rb +++ b/spec/models/profile_field_spec.rb @@ -9,7 +9,6 @@ RSpec.describe ProfileField, type: :model do it { is_expected.to validate_presence_of(:label) } it { is_expected.to validate_uniqueness_of(:label).case_insensitive } - it { is_expected.to validate_inclusion_of(:active).in_array([true, false]) } it { is_expected.to validate_presence_of(:attribute_name).on(:update) } it { is_expected.to validate_inclusion_of(:show_in_onboarding).in_array([true, false]) } end diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index a0c74b4b4..58c360726 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -11,7 +11,6 @@ RSpec.describe Profile, type: :model do before do create(:profile_field, label: "Test 1") create(:profile_field, label: "Test 2", input_type: :check_box) - create(:profile_field, label: "Test 3", active: false) described_class.refresh_store_accessors! end @@ -20,7 +19,6 @@ RSpec.describe Profile, type: :model do it "defines accessors for active profile fields", :aggregate_failures do expect(profile).to respond_to(:test1) expect(profile).to respond_to(:test2) - expect(profile).not_to respond_to(:test3) end it "performs ActiveRecord typecasting for profile fields", :aggregate_failures do diff --git a/spec/requests/admin/profile_fields_spec.rb b/spec/requests/admin/profile_fields_spec.rb index 5a35394f8..fd58c88f3 100644 --- a/spec/requests/admin/profile_fields_spec.rb +++ b/spec/requests/admin/profile_fields_spec.rb @@ -33,7 +33,6 @@ RSpec.describe "/admin/profile_fields", type: :request do input_type: "text_field", description: "users' location", placeholder_text: "new york", - active: false, group: "Location" } end @@ -53,7 +52,6 @@ RSpec.describe "/admin/profile_fields", type: :request do expect(last_profile_field_record.input_type).to eq(new_profile_field[:input_type]) expect(last_profile_field_record.description).to eq(new_profile_field[:description]) expect(last_profile_field_record.placeholder_text).to eq(new_profile_field[:placeholder_text]) - expect(last_profile_field_record.active).to eq(new_profile_field[:active]) expect(last_profile_field_record.group).to eq(new_profile_field[:group]) end end @@ -63,16 +61,16 @@ RSpec.describe "/admin/profile_fields", type: :request do it "redirects successfully" do put "#{admin_profile_fields_path}/#{profile_field.id}", - params: { profile_field: { active: false } } + params: { profile_field: { show_in_onboarding: false } } expect(response).to redirect_to admin_profile_fields_path end it "updates the profile field values" do put "#{admin_profile_fields_path}/#{profile_field.id}", - params: { profile_field: { active: false } } + params: { profile_field: { show_in_onboarding: false } } changed_profile_record = ProfileField.find(profile_field.id) - expect(changed_profile_record.active).to be(false) + expect(changed_profile_record.show_in_onboarding).to be(false) end end