diff --git a/Gemfile.lock b/Gemfile.lock index bfc51257..daf162a5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -317,7 +317,7 @@ GEM rspec-mocks (~> 3.12) rspec-support (~> 3.12) racc (1.8.1) - rack (3.1.14) + rack (3.1.16) rack-accept (0.4.5) rack (>= 0.4) rack-protection (4.1.1) diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index af7c1e83..6ca25811 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -28,8 +28,6 @@ def new Rails.logger.debug { "^^^^^^^^^^^^^^^^ Profile is nil for user: #{current_user.inspect}" } else authorize @profile - @profile.build_home_address - @profile.build_campus_address end end @@ -86,8 +84,6 @@ def profile_params :major, :department, :grad_date, :degree, :receiving_financial_aid, :accepted_financial_aid_notice, :financial_aid_description, - :hometown_publication, :pen_name, - home_address_attributes: %i[id address1 address2 city state zip country address_type_id], - campus_address_attributes: %i[id address1 address2 city state zip country address_type_id]) + :hometown_publication, :pen_name) end end diff --git a/app/helpers/containers_helper.rb b/app/helpers/containers_helper.rb index 7fa7bcf9..ed112856 100644 --- a/app/helpers/containers_helper.rb +++ b/app/helpers/containers_helper.rb @@ -18,8 +18,8 @@ def render_eligibility_rules(description) eligibility_plain = description.eligibility_rules.to_plain_text if eligibility_plain.length > 100 content_tag(:div) do - truncate(eligibility_plain, length: 100, omission: '') + - link_to('...more', '#', + truncate(eligibility_plain, length: 60, omission: '') + + link_to(' ...more', '#', data: { action: 'click->modal#open', url: eligibility_rules_container_contest_description_path(description.container, description), diff --git a/app/helpers/contest_descriptions_helper.rb b/app/helpers/contest_descriptions_helper.rb index 44b1ee76..5e53842d 100644 --- a/app/helpers/contest_descriptions_helper.rb +++ b/app/helpers/contest_descriptions_helper.rb @@ -6,9 +6,8 @@ def contest_description_summary(description) if active_instances.any? first_active = active_instances.first entry_count = first_active.entries.where(deleted: false).count - summary += 'Active instance
' - summary += link_to(pluralize(entry_count, 'entry'), - container_contest_description_contest_instance_path(description.container, description, first_active), class: 'btn btn-sm btn-primary') + summary += link_to("Active: #{pluralize(entry_count, 'entry')}", + container_contest_description_contest_instance_path(description.container, description, first_active), class: 'btn btn-sm btn-primary small') summary += '
' end summary += "#{pluralize(total_instances, 'instance')}" diff --git a/app/javascript/controllers/address_copy_controller.js b/app/javascript/controllers/address_copy_controller.js deleted file mode 100644 index e09b4301..00000000 --- a/app/javascript/controllers/address_copy_controller.js +++ /dev/null @@ -1,17 +0,0 @@ -import { Controller } from "@hotwired/stimulus" - -export default class extends Controller { - static targets = [ - "homeAddress1", "homeAddress2", "homeCity", "homeState", "homeZip", "homeCountry", - "campusAddress1", "campusAddress2", "campusCity", "campusState", "campusZip", "campusCountry" - ] - - copy() { - this.homeAddress1Target.value = this.campusAddress1Target.value - this.homeAddress2Target.value = this.campusAddress2Target.value - this.homeCityTarget.value = this.campusCityTarget.value - this.homeStateTarget.value = this.campusStateTarget.value - this.homeZipTarget.value = this.campusZipTarget.value - this.homeCountryTarget.value = this.campusCountryTarget.value - } -} \ No newline at end of file diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js index d4b7e30a..896a70fa 100644 --- a/app/javascript/controllers/index.js +++ b/app/javascript/controllers/index.js @@ -4,9 +4,6 @@ import { application } from "./application" -import AddressCopyController from "./address_copy_controller" -application.register("address-copy", AddressCopyController) - import CharacterCounterController from "./character_counter_controller" application.register("character-counter", CharacterCounterController) diff --git a/app/models/address.rb b/app/models/address.rb deleted file mode 100644 index d24098fc..00000000 --- a/app/models/address.rb +++ /dev/null @@ -1,108 +0,0 @@ -# frozen_string_literal: true - -# == Schema Information -# -# Table name: addresses -# -# id :bigint not null, primary key -# address1 :string(255) -# address2 :string(255) -# city :string(255) -# country :string(255) -# state :string(255) -# zip :string(255) -# created_at :datetime not null -# updated_at :datetime not null -# address_type_id :bigint -# -# Indexes -# -# address_type_id_idx (address_type_id) -# id_unq_idx (id) UNIQUE -# index_addresses_on_address_type_id (address_type_id) -# -# Foreign Keys -# -# fk_rails_... (address_type_id => address_types.id) -# - -class Address < ApplicationRecord - belongs_to :address_type - has_many :home_profiles, class_name: 'Profile', foreign_key: 'home_address_id', dependent: :restrict_with_exception - has_many :campus_profiles, class_name: 'Profile', foreign_key: 'campus_address_id', dependent: :restrict_with_exception - - validates :address1, :city, :state, :zip, :country, presence: true - - STATES = - [ - [ 'Alabama', 'AL' ], - [ 'Alaska', 'AK' ], - [ 'Arizona', 'AZ' ], - [ 'Arkansas', 'AR' ], - [ 'California', 'CA' ], - [ 'Colorado', 'CO' ], - [ 'Connecticut', 'CT' ], - [ 'Delaware', 'DE' ], - [ 'District of Columbia', 'DC' ], - [ 'Florida', 'FL' ], - [ 'Georgia', 'GA' ], - [ 'Hawaii', 'HI' ], - [ 'Idaho', 'ID' ], - [ 'Illinois', 'IL' ], - [ 'Indiana', 'IN' ], - [ 'Iowa', 'IA' ], - [ 'Kansas', 'KS' ], - [ 'Kentucky', 'KY' ], - [ 'Louisiana', 'LA' ], - [ 'Maine', 'ME' ], - [ 'Maryland', 'MD' ], - [ 'Massachusetts', 'MA' ], - [ 'Michigan', 'MI' ], - [ 'Minnesota', 'MN' ], - [ 'Mississippi', 'MS' ], - [ 'Missouri', 'MO' ], - [ 'Montana', 'MT' ], - [ 'Nebraska', 'NE' ], - [ 'Nevada', 'NV' ], - [ 'New Hampshire', 'NH' ], - [ 'New Jersey', 'NJ' ], - [ 'New Mexico', 'NM' ], - [ 'New York', 'NY' ], - [ 'North Carolina', 'NC' ], - [ 'North Dakota', 'ND' ], - [ 'Ohio', 'OH' ], - [ 'Oklahoma', 'OK' ], - [ 'Oregon', 'OR' ], - [ 'Pennsylvania', 'PA' ], - [ 'Puerto Rico', 'PR' ], - [ 'Rhode Island', 'RI' ], - [ 'South Carolina', 'SC' ], - [ 'South Dakota', 'SD' ], - [ 'Tennessee', 'TN' ], - [ 'Texas', 'TX' ], - [ 'Utah', 'UT' ], - [ 'Vermont', 'VT' ], - [ 'Virginia', 'VA' ], - [ 'Washington', 'WA' ], - [ 'West Virginia', 'WV' ], - [ 'Wisconsin', 'WI' ], - [ 'Wyoming', 'WY' ] - ].freeze - - # def full_address - # "#{address1} #{address2} #{city}, #{state} #{zip}" - # end - def full_address - "#{address1}\n#{address2.present? ? "#{address2}\n" : ''}#{city}, #{state} #{zip}\n#{country_abbreviation}" - end - - def country_name - country_data = ISO3166::Country[country] - country_data.translations[I18n.locale.to_s] || country_data.name if country_data - end - - def country_abbreviation - country_data = ISO3166::Country[country] - country_data.alpha2 if country_data - end -end diff --git a/app/models/address_type.rb b/app/models/address_type.rb deleted file mode 100644 index d869c3a3..00000000 --- a/app/models/address_type.rb +++ /dev/null @@ -1,19 +0,0 @@ -# == Schema Information -# -# Table name: address_types -# -# id :bigint not null, primary key -# description :text(65535) -# kind :string(255) not null -# created_at :datetime not null -# updated_at :datetime not null -# -# Indexes -# -# id_unq_idx (id) UNIQUE -# index_address_types_on_kind (kind) UNIQUE -# -class AddressType < ApplicationRecord - has_many :addresses - validates :kind, presence: true, uniqueness: true -end diff --git a/app/models/profile.rb b/app/models/profile.rb index 6c7b5e7e..20520d2c 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -20,34 +20,28 @@ # umid :string(255) # created_at :datetime not null # updated_at :datetime not null -# campus_address_id :bigint # campus_id :bigint # class_level_id :bigint -# home_address_id :bigint # school_id :bigint # user_id :bigint not null # # Indexes # -# campus_id_idx (campus_id) -# class_level_id_idx (class_level_id) -# id_unq_idx (id) UNIQUE -# index_profiles_on_campus_address_id (campus_address_id) -# index_profiles_on_campus_id (campus_id) -# index_profiles_on_class_level_id (class_level_id) -# index_profiles_on_home_address_id (home_address_id) -# index_profiles_on_school_id (school_id) -# index_profiles_on_umid (umid) UNIQUE -# index_profiles_on_user_id (user_id) -# school_id_idx (school_id) -# user_id_idx (user_id) +# campus_id_idx (campus_id) +# class_level_id_idx (class_level_id) +# id_unq_idx (id) UNIQUE +# index_profiles_on_campus_id (campus_id) +# index_profiles_on_class_level_id (class_level_id) +# index_profiles_on_school_id (school_id) +# index_profiles_on_umid (umid) UNIQUE +# index_profiles_on_user_id (user_id) +# school_id_idx (school_id) +# user_id_idx (user_id) # # Foreign Keys # -# fk_rails_... (campus_address_id => addresses.id) # fk_rails_... (campus_id => campuses.id) # fk_rails_... (class_level_id => class_levels.id) -# fk_rails_... (home_address_id => addresses.id) # fk_rails_... (school_id => schools.id) # fk_rails_... (user_id => users.id) # @@ -60,17 +54,11 @@ class Profile < ApplicationRecord belongs_to :campus, optional: true has_many :entries, dependent: :restrict_with_error - belongs_to :home_address, class_name: 'Address', optional: true - belongs_to :campus_address, class_name: 'Address', optional: true - - accepts_nested_attributes_for :home_address, allow_destroy: true - accepts_nested_attributes_for :campus_address, allow_destroy: true - validates :preferred_first_name, presence: true, length: { in: 1..255 } validates :preferred_last_name, presence: true, length: { in: 1..255 } - validates :umid, - presence: true, - uniqueness: true, + validates :umid, + presence: true, + uniqueness: true, length: { is: 8 }, format: { with: /\A\d{8}\z/, message: "must be exactly 8 digits" } validates :grad_date, presence: true @@ -79,9 +67,6 @@ class Profile < ApplicationRecord validates :class_level_id, presence: true validates :campus_id, presence: true validates :school_id, presence: true - validates :home_address, presence: true - validates :campus_address, presence: true - def display_name "#{preferred_first_name} #{preferred_last_name}" diff --git a/app/policies/address_policy.rb b/app/policies/address_policy.rb deleted file mode 100644 index cac3e2a1..00000000 --- a/app/policies/address_policy.rb +++ /dev/null @@ -1,50 +0,0 @@ -# app/policies/address_policy.rb -class AddressPolicy < ApplicationPolicy - def index? - axis_mundi? - end - - def show? - axis_mundi? || owner? - end - - def create? - axis_mundi? || owner? - end - - def new? - create? - end - - def update? - axis_mundi? || owner? - end - - def edit? - update? - end - - def destroy? - axis_mundi? - end - - private - - # Checks if the user owns the address via their profile - def owner? - user && ( - record == user.profile&.home_address || - record == user.profile&.campus_address - ) - end - - class Scope < Scope - def resolve - if user&.axis_mundi? - scope.all - else - scope.none - end - end - end -end diff --git a/app/views/containers/_contest_descriptions_table.html.erb b/app/views/containers/_contest_descriptions_table.html.erb index 69cb9ca0..2c8a6d84 100644 --- a/app/views/containers/_contest_descriptions_table.html.erb +++ b/app/views/containers/_contest_descriptions_table.html.erb @@ -1,41 +1,56 @@ <%# app/views/containers/_contest_descriptions_table.html.erb %>
- +
- - - - - - - + + + + + + + <% descriptions.each do |description| %> - - - - + - + - - +
NameSummaryShort NameEligibility RulesNotesActiveActionsNameStatusShort NameEligibilityNotesActiveActions
<%= description.name %><%= contest_description_summary(description) %><%= description.short_name %> - <%= render_eligibility_rules(description) %> + + + <%= description.name %> + + + <%= contest_description_summary(description) %> + + + <%= description.short_name %> + + + + <%# <% if description.notes.present? %> - <%= link_to "view", container_contest_description_contest_instances_path(container, description) %> + <%= link_to "view", container_contest_description_contest_instances_path(container, description), class: "btn btn-link btn-sm p-0", title: "View notes", aria: { label: "View notes for #{description.name}" } %> <% end %> <%= boolean_to_yes_no(description.active) %> -
+
+ <%= boolean_to_yes_no(description.active) %> + +
<% contest_description_action_links(container, description).each do |action, config| %> <%= link_to config[:path], - class: 'd-block', + class: 'btn btn-link btn-sm p-0', data: config[:data]&.merge('bs-toggle': 'tooltip'), title: config[:title], aria: { label: config[:title] } do %> - + <%= config[:title] %> <% end %> <% end %> diff --git a/app/views/profiles/_form.html.erb b/app/views/profiles/_form.html.erb index b55288be..56c07f25 100644 --- a/app/views/profiles/_form.html.erb +++ b/app/views/profiles/_form.html.erb @@ -5,7 +5,7 @@ <%= f.error_notification %> <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> -
+

Contact Information

@@ -29,69 +29,6 @@ <%= f.input :pen_name, label: "Default pen name (optional)", hint: "Set a default pen name to use for future contest entries that require one. You can leave this blank if you prefer to enter a pen name each time. The pen name should bear no resemblance to your real name or any other personal information." %>
- -
-

Local (campus) Address

- (Please provide your current campus address) - <%= f.simple_fields_for :campus_address do |address_form| %> -
-
- <%= address_form.input :address1, input_html: { data: { target: "address-copy.campusAddress1" } } %> -
-
- <%= address_form.input :address2, input_html: { data: { target: "address-copy.campusAddress2" } } %> -
-
-
-
- <%= address_form.input :city, input_html: { data: { target: "address-copy.campusCity" } } %> -
-
- <%= address_form.input :state, collection: Address::STATES, input_html: { data: { target: "address-copy.campusState" } } %> -
-
-
-
- <%= address_form.input :zip, input_html: { data: { target: "address-copy.campusZip" } } %> -
-
- <%= address_form.input :country, priority: ["United States"], input_html: { data: { target: "address-copy.campusCountry" } } %> - <%= address_form.input :address_type_id, as: :hidden, input_html: { value: AddressType.find_by(kind: 'Campus').id } %> -
-
- <% end %> - - - -

Hometown Address

- <%= f.simple_fields_for :home_address do |address_form| %> -
-
- <%= address_form.input :address1, input_html: { data: { target: "address-copy.homeAddress1" } } %> -
-
- <%= address_form.input :address2, input_html: { data: { target: "address-copy.homeAddress2" } } %> -
-
-
-
- <%= address_form.input :city, input_html: { data: { target: "address-copy.homeCity" } } %> -
-
- <%= address_form.input :state, collection: Address::STATES, input_html: { data: { target: "address-copy.homeState" } } %> -
-
-
-
- <%= address_form.input :zip, input_html: { data: { target: "address-copy.homeZip" } } %> -
-
- <%= address_form.input :country, priority: ["United States"], input_html: { data: { target: "address-copy.homeCountry" } } %> - <%= address_form.input :address_type_id, as: :hidden, input_html: { value: AddressType.find_by(kind: 'Home').id } %> -
-
- <% end %> -

Academic Information

@@ -117,13 +54,11 @@

Publicity

- -
- <%= f.input :hometown_publication, label: "Name of your hometown newspaper or preferred media outlet:", hint: "For some contests, if your manuscript earns an award, the award’s committee will forward a press release to your local newspaper or media outlet." %> -
+
+ <%= f.input :hometown_publication, label: "Name of your hometown newspaper or preferred media outlet:", hint: "For some contests, if your manuscript earns an award, the award's committee will forward a press release to your local newspaper or media outlet." %> +
-
<% if (content = render_editable_content('profiles', 'information')) %> diff --git a/app/views/profiles/_profile.html.erb b/app/views/profiles/_profile.html.erb index 6630c186..01698a72 100644 --- a/app/views/profiles/_profile.html.erb +++ b/app/views/profiles/_profile.html.erb @@ -16,12 +16,10 @@
-
Local(campus) Address:<%= simple_format(profile.campus_address.full_address, {class:"fw-light"}) if profile.campus_address %>
-
Hometown Address:<%= simple_format(profile.home_address.full_address, {class:"fw-light"}) if profile.home_address %>
+ <% if profile.pen_name.present? %> +

Default pen name: <%= simple_format(profile.pen_name, {class:"fw-light"}) %>

+ <% end %>
- <% if profile.pen_name.present? %> -

Default pen name: <%= simple_format(profile.pen_name, {class:"fw-light"}) %>

- <% end %>
@@ -31,55 +29,65 @@

Academic Information

-
-
-

Class Level:
<%= profile.class_level.name if profile.class_level %>

-

School or College:
<%= profile.school.name if profile.school %>

-

Primary Campus Class Location:
<%= profile.campus.campus_descr if profile.campus %>

- <% if @profile&.major.present? %> -

Major (if undergraduate):
<%= profile.major %>

- <% end %> - <% if @profile&.department.present? %> -

Department (if graduate):
<%= profile.department if profile.department %>

- <% end %> -

Expected Graduation Date:
<%= profile.grad_date.strftime("%B %Y") %>

-

Degree:
<%= profile.degree %>

+
+
+
+

Class Level: <%= simple_format(profile.class_level.name, {class:"fw-light"}) %>

+

School or College: <%= simple_format(profile.school.name, {class:"fw-light"}) %>

+

Primary Campus Class Location: <%= simple_format(profile.campus.campus_descr, {class:"fw-light"}) %>

+ <% if profile.major.present? %> +

Major: <%= simple_format(profile.major, {class:"fw-light"}) %>

+ <% end %> + <% if profile.department.present? %> +

Department: <%= simple_format(profile.department, {class:"fw-light"}) %>

+ <% end %> +

Expected Graduation Date: <%= simple_format(profile.grad_date.strftime("%B %Y"), {class:"fw-light"}) %>

+

Degree: <%= simple_format(profile.degree, {class:"fw-light"}) %>

+
- <% if @profile.receiving_financial_aid && @profile.financial_aid_description.present? %> -
-
-

Financial Aid

-
-
+
+
+

Publicity

+
+
+
-

Financial Aid:
<%= profile.receiving_financial_aid ? 'Yes' : 'No' %>

- <% if profile.receiving_financial_aid %> -

Financial Aid Description:
<%= profile.financial_aid_description %>

- <% end %> + Entrant's name as it will appear in publicity:
+ (This is the name you entered as your preferred name.) + <%= simple_format(profile.display_name, {class:"fw-light"}) %>
+ <% if profile.hometown_publication.present? %> +
+
+ Hometown newspaper or preferred media outlet:
+ <%= simple_format(profile.hometown_publication, {class:"fw-light"}) %> +
+
+ <% end %>
- <% end %> +
-

Publicity

+

Financial Aid

-
-
- Entrant’s name as it will appear in publicity:
- (This is the name you entered as your preferred name.) - <%= simple_format(profile.display_name, {class:"fw-light"}) %> - <% if profile.hometown_publication.present? %> -

Name of your hometown newspaper or preferred media outlet:
<%= profile.hometown_publication %>

- <% end %> +
+
+
+ Receiving financial aid: <%= simple_format(profile.receiving_financial_aid ? "Yes" : "No", {class:"fw-light"}) %> + <% if profile.receiving_financial_aid && profile.financial_aid_description.present? %> +
+ Description: <%= simple_format(profile.financial_aid_description, {class:"fw-light"}) %> + <% end %> +
diff --git a/app/views/profiles/_profile_summary.html.erb b/app/views/profiles/_profile_summary.html.erb index cf628eae..c8764e6b 100644 --- a/app/views/profiles/_profile_summary.html.erb +++ b/app/views/profiles/_profile_summary.html.erb @@ -7,31 +7,10 @@

Welcome
<%= @profile.preferred_first_name %>!

UMID: <%= @profile.umid %>

- -
- <%= link_to edit_profile_path(@profile), class: 'text-white link-underline link-underline-opacity-0' do %> - Edit - <% end %> -
+

- -
-
-

- Hometown Address: - <%= simple_format(@profile.home_address.full_address, class: "text-white fw-light lh-1 pt-1 ms-2 small") if @profile.home_address %> -

-
-
-

- Local(campus) Address: - <%= simple_format(@profile.campus_address.full_address, class: "text-white fw-light lh-1 ms-2 pt-1 small") if @profile.campus_address %> -

-
-
-
@@ -134,10 +113,19 @@
- -
-

- Last updated:
<%= @profile.updated_at.strftime("%B %d, %Y") %>
-

+
+ +
+

+ Last updated:
+ <%= @profile.updated_at.strftime("%B %d, %Y") %>
+

+
+ +
+ <%= link_to edit_profile_path(@profile), class: 'text-white link-underline link-underline-opacity-0' do %> + + <% end %> +
-
\ No newline at end of file +
diff --git a/db/migrate/20250605204535_remove_address_columns_from_profiles.rb b/db/migrate/20250605204535_remove_address_columns_from_profiles.rb new file mode 100644 index 00000000..9e7e55d2 --- /dev/null +++ b/db/migrate/20250605204535_remove_address_columns_from_profiles.rb @@ -0,0 +1,8 @@ +class RemoveAddressColumnsFromProfiles < ActiveRecord::Migration[7.1] + def change + remove_foreign_key :profiles, :addresses, column: :home_address_id + remove_foreign_key :profiles, :addresses, column: :campus_address_id + remove_column :profiles, :home_address_id, :bigint + remove_column :profiles, :campus_address_id, :bigint + end +end diff --git a/db/migrate/20250605210643_drop_address_tables.rb b/db/migrate/20250605210643_drop_address_tables.rb new file mode 100644 index 00000000..63e15ffe --- /dev/null +++ b/db/migrate/20250605210643_drop_address_tables.rb @@ -0,0 +1,36 @@ +class DropAddressTables < ActiveRecord::Migration[7.1] + def up + # Drop tables in reverse order of dependencies + drop_table :addresses + drop_table :address_types + end + + def down + # Recreate address_types table + create_table :address_types do |t| + t.string :kind, null: false + t.text :description + + t.timestamps + end + + add_index :address_types, :kind, unique: true + add_index :address_types, :id, unique: true, name: 'id_unq_idx' + + # Recreate addresses table + create_table :addresses do |t| + t.string :address1 + t.string :address2 + t.string :city + t.string :state + t.string :zip + t.string :country + t.references :address_type, null: false, foreign_key: true + + t.timestamps + end + + add_index :addresses, :id, unique: true, name: 'id_unq_idx' + add_index :addresses, :address_type_id, name: 'address_type_id_idx' + end +end diff --git a/db/schema.rb b/db/schema.rb index 64c25b4d..eab24cc8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2025_03_12_173602) do +ActiveRecord::Schema[7.2].define(version: 2025_06_05_210643) do create_table "action_text_rich_texts", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "name", null: false t.text "body", size: :long @@ -49,30 +49,6 @@ t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true end - create_table "address_types", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| - t.string "kind", null: false - t.text "description" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["id"], name: "id_unq_idx", unique: true - t.index ["kind"], name: "index_address_types_on_kind", unique: true - end - - create_table "addresses", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| - t.string "address1" - t.string "address2" - t.string "city" - t.string "state" - t.string "zip" - t.string "country" - t.bigint "address_type_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["address_type_id"], name: "address_type_id_idx" - t.index ["address_type_id"], name: "index_addresses_on_address_type_id" - t.index ["id"], name: "id_unq_idx", unique: true - end - create_table "affiliations", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "name" t.bigint "user_id", null: false @@ -294,17 +270,13 @@ t.string "pen_name" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.bigint "home_address_id" - t.bigint "campus_address_id" t.boolean "campus_employee", default: false, null: false t.string "department" t.string "umid" - t.index ["campus_address_id"], name: "index_profiles_on_campus_address_id" t.index ["campus_id"], name: "campus_id_idx" t.index ["campus_id"], name: "index_profiles_on_campus_id" t.index ["class_level_id"], name: "class_level_id_idx" t.index ["class_level_id"], name: "index_profiles_on_class_level_id" - t.index ["home_address_id"], name: "index_profiles_on_home_address_id" t.index ["id"], name: "id_unq_idx", unique: true t.index ["school_id"], name: "index_profiles_on_school_id" t.index ["school_id"], name: "school_id_idx" @@ -385,7 +357,6 @@ add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" - add_foreign_key "addresses", "address_types" add_foreign_key "affiliations", "users" add_foreign_key "assignments", "containers" add_foreign_key "assignments", "roles" @@ -407,8 +378,6 @@ add_foreign_key "judging_assignments", "contest_instances" add_foreign_key "judging_assignments", "users" add_foreign_key "judging_rounds", "contest_instances" - add_foreign_key "profiles", "addresses", column: "campus_address_id" - add_foreign_key "profiles", "addresses", column: "home_address_id" add_foreign_key "profiles", "campuses" add_foreign_key "profiles", "class_levels" add_foreign_key "profiles", "schools" diff --git a/db/seeds.rb b/db/seeds.rb index 12fbde51..62ed52f5 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -86,42 +86,6 @@ { name: 'Other' } ]) - AddressType.create([ - { kind: 'Home', description: 'Home address' }, - { kind: 'Campus', description: 'Campus address' } - ]) - - # Create Addresses - Address.create([ - { - address1: Faker::Address.street_address, - address2: Faker::Address.secondary_address, - city: Faker::Address.city, - state: Faker::Address.state_abbr, - zip: Faker::Address.zip_code, - country: Faker::Address.country_code, - address_type: AddressType.find_by(kind: 'Home') - }, - { - address1: Faker::Address.street_address, - address2: Faker::Address.secondary_address, - city: Faker::Address.city, - state: Faker::Address.state_abbr, - zip: Faker::Address.zip_code, - country: Faker::Address.country_code, - address_type: AddressType.find_by(kind: 'Campus') - }, - { - address1: Faker::Address.street_address, - address2: Faker::Address.secondary_address, - city: Faker::Address.city, - state: Faker::Address.state_abbr, - zip: Faker::Address.zip_code, - country: Faker::Address.country_code, - address_type: AddressType.find_by(kind: 'Home') - } - ]) - # Seed data for Campus Campus.create([ { campus_descr: 'Ann Arbor', campus_cd: 100 }, diff --git a/lib/tasks/sample_data.rake b/lib/tasks/sample_data.rake index 5dc06bca..6930d849 100644 --- a/lib/tasks/sample_data.rake +++ b/lib/tasks/sample_data.rake @@ -1,140 +1,72 @@ namespace :sample_data do - desc 'Create sample contest entries for testing' - task create_entries: :environment do - if Rails.env.production? - puts 'This task cannot be run in the production environment.' - exit - end - - # Find or create required records - contest_description = ContestDescription.first || ContestDescription.create!( - name: 'Sample Contest 2024', - created_by: 'system', - container: Container.first || Container.create!( - name: 'Sample Container', - department: Department.first || Department.create!(name: 'Sample Department'), - visibility: Visibility.first || Visibility.create!(kind: 'Public') - ) - ) - - contest_instance = ContestInstance.first || - ContestInstance.create!( - contest_description: contest_description, - description: 'A sample contest for testing', - date_open: Date.today, - date_closed: 1.month.from_now, - require_pen_name: true, - created_by: 'system' - ) - - category = Category.first || Category.create!(kind: 'Poetry', description: 'Poetry submissions') - - # Create required reference data if not exists - class_level = ClassLevel.first || ClassLevel.create!(name: 'Senior', description: 'Fourth year student') - school = School.first || School.create!(name: 'Literature, Science, and the Arts') - campus = Campus.first || Campus.create!(campus_descr: 'Ann Arbor', campus_cd: 1) - - # Create address types if they don't exist - home_type = AddressType.find_or_create_by!(kind: 'Home', description: 'Home address') - campus_type = AddressType.find_or_create_by!(kind: 'Campus', description: 'Campus address') - - # Sample titles for creative writing entries - titles = [ - 'The Last Sunset', - 'Whispers in the Wind', - 'Beyond the Horizon', - 'Echoes of Tomorrow', - 'The Silent Garden', - 'Memories of Rain', - 'The Forgotten Door', - 'Dancing Shadows', - 'The Crystal Key', - "Autumn's Secret", - 'The Time Keeper', - "Midnight's Promise", - 'The Paper Boat', - "Winter's Song" - ] - - # Create entries - titles.each_with_index do |title, index| - # Create addresses - home_address = Address.create!( - address_type: home_type, - address1: "#{1000 + index} Home St", - city: 'Ann Arbor', - state: 'MI', - zip: '48109', - country: 'USA' + desc 'Create sample data for development' + task create: :environment do + # Create roles if they don't exist + axis_mundi_role = Role.find_or_create_by!(kind: 'Axis Mundi', description: 'Administrator role') + collection_admin_role = Role.find_or_create_by!(kind: 'Collection Administrator', description: 'Collection administrator role') + + # Create campuses if they don't exist + ann_arbor_campus = Campus.find_or_create_by!(name: 'Ann Arbor', description: 'Ann Arbor campus') + dearborn_campus = Campus.find_or_create_by!(name: 'Dearborn', description: 'Dearborn campus') + flint_campus = Campus.find_or_create_by!(name: 'Flint', description: 'Flint campus') + + # Create schools if they don't exist + lsa = School.find_or_create_by!(name: 'LSA', description: 'College of Literature, Science, and the Arts') + engineering = School.find_or_create_by!(name: 'Engineering', description: 'College of Engineering') + business = School.find_or_create_by!(name: 'Business', description: 'Ross School of Business') + + # Create class levels if they don't exist + freshman = ClassLevel.find_or_create_by!(name: 'Freshman', description: 'First year student') + sophomore = ClassLevel.find_or_create_by!(name: 'Sophomore', description: 'Second year student') + junior = ClassLevel.find_or_create_by!(name: 'Junior', description: 'Third year student') + senior = ClassLevel.find_or_create_by!(name: 'Senior', description: 'Fourth year student') + + # Create sample users with profiles + 5.times do |index| + # Create user + user = User.create!( + email: "user#{index + 1}@example.com", + first_name: Faker::Name.first_name, + last_name: Faker::Name.last_name, + uniqname: "user#{index + 1}", + uid: "user#{index + 1}", + display_name: "User #{index + 1}", + password: 'passwordpassword', + affiliations_attributes: [ + { name: 'student' }, + { name: 'member' } + ] ) - campus_address = Address.create!( - address_type: campus_type, - address1: "#{2000 + index} Campus Dr", - city: 'Ann Arbor', - state: 'MI', - zip: '48109', - country: 'USA' + # Create profile + p = Profile.create!( + user: user, + preferred_first_name: user.first_name, + preferred_last_name: user.last_name, + umid: format('%08d', rand(10000000..99999999)), + class_level: [freshman, sophomore, junior, senior].sample, + school: [lsa, engineering, business].sample, + campus: [ann_arbor_campus, dearborn_campus, flint_campus].sample, + major: Faker::Educator.subject, + department: Faker::Educator.subject, + grad_date: Date.today + rand(1..4).years, + degree: ['Bachelor\'s', 'Master\'s', 'PhD'].sample, + receiving_financial_aid: [true, false].sample, + accepted_financial_aid_notice: true, + campus_employee: [true, false].sample, + financial_aid_description: Faker::Lorem.paragraph, + hometown_publication: Faker::Address.city, + pen_name: Faker::Book.author ) - # Create a user for each entry - user = User.find_or_create_by!(email: "author#{index + 1}@example.com") do |u| - u.first_name = 'Author' - u.last_name = "#{index + 1}" - u.password = 'ThisIsALongPassword123!@#' - u.password_confirmation = 'ThisIsALongPassword123!@#' - end - - # Create a profile for the user - profile = Profile.find_or_create_by!(user: user) do |p| - p.preferred_first_name = user.first_name - p.preferred_last_name = user.last_name - p.grad_date = Date.new(2024, 5, 1) - p.degree = 'BA' - p.umid = format('%08d', index + 10000000) # 8-digit UMID - p.class_level = class_level - p.campus = campus - p.school = school - p.major = 'Creative Writing' - p.home_address = home_address - p.campus_address = campus_address - end - - Entry.find_or_create_by!(title: title) do |entry| - entry.contest_instance = contest_instance - entry.profile = profile - entry.category = category - entry.pen_name = "Poet#{index + 1}" - entry.created_at = Time.current - rand(1..30).days - - # Create a temporary markdown file - temp_file = Tempfile.new([ 'entry', '.md' ]) - temp_file.write("# #{title}\n\n") - temp_file.write("## By #{entry.pen_name}\n\n") - temp_file.write("This is a sample entry for testing purposes.\n\n") - temp_file.write('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.') - temp_file.rewind - - # Convert to PDF using pandoc - pdf_file = Tempfile.new([ 'entry', '.pdf' ]) - system("pandoc #{temp_file.path} -o #{pdf_file.path}") - - # Attach the PDF file to the entry - entry.entry_file.attach( - io: File.open(pdf_file.path), - filename: "#{title.downcase.gsub(/[^a-z0-9]/, '_')}.pdf", - content_type: 'application/pdf' - ) - - temp_file.close - temp_file.unlink - pdf_file.close - pdf_file.unlink - - puts "Created entry: #{title} by #{profile.preferred_first_name} #{profile.preferred_last_name} (#{entry.pen_name})" + # Assign roles to some users + if index < 2 + UserRole.create!(user: user, role: axis_mundi_role) + elsif index < 4 + UserRole.create!(user: user, role: collection_admin_role) end end - puts "\nCreated #{titles.length} sample entries for contest: #{contest_instance.contest_description.name}" + puts 'Sample data created successfully!' end end diff --git a/spec/factories/address_types.rb b/spec/factories/address_types.rb deleted file mode 100644 index acf514c6..00000000 --- a/spec/factories/address_types.rb +++ /dev/null @@ -1,33 +0,0 @@ -# == Schema Information -# -# Table name: address_types -# -# id :bigint not null, primary key -# description :text(65535) -# kind :string(255) not null -# created_at :datetime not null -# updated_at :datetime not null -# -# Indexes -# -# id_unq_idx (id) UNIQUE -# index_address_types_on_kind (kind) UNIQUE -# -FactoryBot.define do - factory :address_type do - # kind { 'Home' } - sequence(:kind) { |n| "Kind #{n}" } # Use a unique sequence for kind - description { Faker::Lorem.sentence } - - trait :home do - kind { 'Home' } - end - - trait :campus do - kind { 'Campus' } - end - - factory :home_address_type, traits: [ :home ] - factory :campus_address_type, traits: [ :campus ] - end -end diff --git a/spec/factories/addresses.rb b/spec/factories/addresses.rb deleted file mode 100644 index ef2b6258..00000000 --- a/spec/factories/addresses.rb +++ /dev/null @@ -1,37 +0,0 @@ -# == Schema Information -# -# Table name: addresses -# -# id :bigint not null, primary key -# address1 :string(255) -# address2 :string(255) -# city :string(255) -# country :string(255) -# state :string(255) -# zip :string(255) -# created_at :datetime not null -# updated_at :datetime not null -# address_type_id :bigint -# -# Indexes -# -# address_type_id_idx (address_type_id) -# id_unq_idx (id) UNIQUE -# index_addresses_on_address_type_id (address_type_id) -# -# Foreign Keys -# -# fk_rails_... (address_type_id => address_types.id) -# - -FactoryBot.define do - factory :address do - address1 { Faker::Address.street_address } - address2 { Faker::Address.secondary_address } - city { Faker::Address.city } - state { Faker::Address.state_abbr } - zip { Faker::Address.zip_code } - country { Faker::Address.country_code } - address_type - end -end diff --git a/spec/factories/profiles.rb b/spec/factories/profiles.rb index 08a5e4ca..c35111f9 100644 --- a/spec/factories/profiles.rb +++ b/spec/factories/profiles.rb @@ -20,34 +20,28 @@ # umid :string(255) # created_at :datetime not null # updated_at :datetime not null -# campus_address_id :bigint # campus_id :bigint # class_level_id :bigint -# home_address_id :bigint # school_id :bigint # user_id :bigint not null # # Indexes # -# campus_id_idx (campus_id) -# class_level_id_idx (class_level_id) -# id_unq_idx (id) UNIQUE -# index_profiles_on_campus_address_id (campus_address_id) -# index_profiles_on_campus_id (campus_id) -# index_profiles_on_class_level_id (class_level_id) -# index_profiles_on_home_address_id (home_address_id) -# index_profiles_on_school_id (school_id) -# index_profiles_on_umid (umid) UNIQUE -# index_profiles_on_user_id (user_id) -# school_id_idx (school_id) -# user_id_idx (user_id) +# campus_id_idx (campus_id) +# class_level_id_idx (class_level_id) +# id_unq_idx (id) UNIQUE +# index_profiles_on_campus_id (campus_id) +# index_profiles_on_class_level_id (class_level_id) +# index_profiles_on_school_id (school_id) +# index_profiles_on_umid (umid) UNIQUE +# index_profiles_on_user_id (user_id) +# school_id_idx (school_id) +# user_id_idx (user_id) # # Foreign Keys # -# fk_rails_... (campus_address_id => addresses.id) # fk_rails_... (campus_id => campuses.id) # fk_rails_... (class_level_id => class_levels.id) -# fk_rails_... (home_address_id => addresses.id) # fk_rails_... (school_id => schools.id) # fk_rails_... (user_id => users.id) # @@ -71,7 +65,5 @@ financial_aid_description { Faker::Lorem.paragraph } hometown_publication { Faker::Address.city } pen_name { Faker::Book.author } - home_address { association :address } - campus_address { association :address } end end diff --git a/spec/models/address_spec.rb b/spec/models/address_spec.rb deleted file mode 100644 index c26c00d7..00000000 --- a/spec/models/address_spec.rb +++ /dev/null @@ -1,124 +0,0 @@ -# == Schema Information -# -# Table name: addresses -# -# id :bigint not null, primary key -# address1 :string(255) -# address2 :string(255) -# city :string(255) -# country :string(255) -# state :string(255) -# zip :string(255) -# created_at :datetime not null -# updated_at :datetime not null -# address_type_id :bigint -# -# Indexes -# -# address_type_id_idx (address_type_id) -# id_unq_idx (id) UNIQUE -# index_addresses_on_address_type_id (address_type_id) -# -# Foreign Keys -# -# fk_rails_... (address_type_id => address_types.id) -# - -require 'rails_helper' - -RSpec.describe Address do - before do - @address_type = AddressType.create(kind: 'Home') - end - - it 'is valid with valid attributes' do - address = Address.new( - address1: Faker::Address.street_address, - address2: Faker::Address.secondary_address, - city: Faker::Address.city, - state: Faker::Number.between(from: 1, to: 50), - zip: Faker::Address.zip_code, - country: Faker::Number.between(from: 1, to: 250), - address_type: @address_type - ) - expect(address).to be_valid - end - - it 'is not valid without address1' do - address = Address.new( - address1: nil, - address2: Faker::Address.secondary_address, - city: Faker::Address.city, - state: Faker::Number.between(from: 1, to: 50), - zip: Faker::Address.zip_code, - country: Faker::Number.between(from: 1, to: 250), - address_type: @address_type - ) - expect(address).not_to be_valid - end - - it 'is not valid without city' do - address = Address.new( - address1: Faker::Address.street_address, - address2: Faker::Address.secondary_address, - city: nil, - state: Faker::Number.between(from: 1, to: 50), - zip: Faker::Address.zip_code, - country: Faker::Number.between(from: 1, to: 250), - address_type: @address_type - ) - expect(address).not_to be_valid - end - - it 'is not valid without state' do - address = Address.new( - address1: Faker::Address.street_address, - address2: Faker::Address.secondary_address, - city: Faker::Address.city, - state: nil, - zip: Faker::Address.zip_code, - country: Faker::Number.between(from: 1, to: 250), - address_type: @address_type - ) - expect(address).not_to be_valid - end - - it 'is not valid without zip' do - address = Address.new( - address1: Faker::Address.street_address, - address2: Faker::Address.secondary_address, - city: Faker::Address.city, - state: Faker::Number.between(from: 1, to: 50), - zip: nil, - country: Faker::Number.between(from: 1, to: 250), - address_type: @address_type - ) - expect(address).not_to be_valid - end - - it 'is not valid without country' do - address = Address.new( - address1: Faker::Address.street_address, - address2: Faker::Address.secondary_address, - city: Faker::Address.city, - state: Faker::Number.between(from: 1, to: 50), - zip: Faker::Address.zip_code, - country: nil, - address_type: @address_type - ) - expect(address).not_to be_valid - end - - it 'is not valid without address_type' do - address = Address.new( - address1: Faker::Address.street_address, - address2: Faker::Address.secondary_address, - city: Faker::Address.city, - state: Faker::Number.between(from: 1, to: 50), - zip: Faker::Address.zip_code, - country: Faker::Number.between(from: 1, to: 250), - address_type: nil - ) - expect(address).not_to be_valid - end -end diff --git a/spec/models/address_type_spec.rb b/spec/models/address_type_spec.rb deleted file mode 100644 index 649e751b..00000000 --- a/spec/models/address_type_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -# == Schema Information -# -# Table name: address_types -# -# id :bigint not null, primary key -# description :text(65535) -# kind :string(255) not null -# created_at :datetime not null -# updated_at :datetime not null -# -# Indexes -# -# id_unq_idx (id) UNIQUE -# index_address_types_on_kind (kind) UNIQUE -# -require 'rails_helper' - -RSpec.describe AddressType, type: :model do - before do - described_class.delete_all - end - - it 'is valid with valid attributes' do - expect(build(:address_type)).to be_valid - end - - it 'is not valid without a kind' do - expect(build(:address_type, kind: nil)).not_to be_valid - end - - it 'is not valid with a duplicate kind' do - create(:address_type, kind: 'Home') - expect(build(:address_type, kind: 'Home')).not_to be_valid - end -end diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index e8fbfe8f..29a88548 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -20,34 +20,28 @@ # umid :string(255) # created_at :datetime not null # updated_at :datetime not null -# campus_address_id :bigint # campus_id :bigint # class_level_id :bigint -# home_address_id :bigint # school_id :bigint # user_id :bigint not null # # Indexes # -# campus_id_idx (campus_id) -# class_level_id_idx (class_level_id) -# id_unq_idx (id) UNIQUE -# index_profiles_on_campus_address_id (campus_address_id) -# index_profiles_on_campus_id (campus_id) -# index_profiles_on_class_level_id (class_level_id) -# index_profiles_on_home_address_id (home_address_id) -# index_profiles_on_school_id (school_id) -# index_profiles_on_umid (umid) UNIQUE -# index_profiles_on_user_id (user_id) -# school_id_idx (school_id) -# user_id_idx (user_id) +# campus_id_idx (campus_id) +# class_level_id_idx (class_level_id) +# id_unq_idx (id) UNIQUE +# index_profiles_on_campus_id (campus_id) +# index_profiles_on_class_level_id (class_level_id) +# index_profiles_on_school_id (school_id) +# index_profiles_on_umid (umid) UNIQUE +# index_profiles_on_user_id (user_id) +# school_id_idx (school_id) +# user_id_idx (user_id) # # Foreign Keys # -# fk_rails_... (campus_address_id => addresses.id) # fk_rails_... (campus_id => campuses.id) # fk_rails_... (class_level_id => class_levels.id) -# fk_rails_... (home_address_id => addresses.id) # fk_rails_... (school_id => schools.id) # fk_rails_... (user_id => users.id) # @@ -56,14 +50,11 @@ RSpec.describe Profile do let(:user) { create(:user) } - let(:addresses) { create_list(:address, 2) } let(:associated_records) do { class_level: create(:class_level), school: create(:school), - campus: create(:campus), - home_address: addresses.first, - campus_address: addresses.second + campus: create(:campus) } end @@ -159,26 +150,6 @@ it 'belongs to campus' do expect(profile.campus).to eq(associated_records[:campus]) end - - it 'belongs to home_address' do - expect(profile.home_address).to eq(associated_records[:home_address]) - end - - it 'belongs to campus_address' do - expect(profile.campus_address).to eq(associated_records[:campus_address]) - end - - it 'accepts nested attributes for home_address' do - profile_attributes = attributes_for(:profile, home_address_attributes: attributes_for(:address)) - profile = described_class.new(profile_attributes) - expect(profile.home_address).to be_present - end - - it 'accepts nested attributes for campus_address' do - profile_attributes = attributes_for(:profile, campus_address_attributes: attributes_for(:address)) - profile = described_class.new(profile_attributes) - expect(profile.campus_address).to be_present - end end describe 'callbacks' do @@ -202,9 +173,7 @@ { class_level: create(:class_level), school: create(:school), - campus: create(:campus), - home_address: create(:address), - campus_address: create(:address) + campus: create(:campus) } end diff --git a/spec/policies/address_policy_spec.rb b/spec/policies/address_policy_spec.rb deleted file mode 100644 index 2db4e901..00000000 --- a/spec/policies/address_policy_spec.rb +++ /dev/null @@ -1,103 +0,0 @@ -# spec/policies/address_policy_spec.rb -require 'rails_helper' - -RSpec.describe AddressPolicy do - subject { described_class.new(user, address) } - - let(:owned_address) { create(:address) } - let(:other_address) { create(:address) } - let(:address) { owned_address } # Default address for tests - - let(:address_owner_user) { create(:user) } - let(:axis_mundi_user) { create(:user) } - let(:other_user) { create(:user) } - - let(:axis_mundi_role) { create(:role, kind: 'Axis Mundi') } - - before do - # Assign the Axis Mundi role to the axis_mundi_user - create(:user_role, user: axis_mundi_user, role: axis_mundi_role) - - # Create a profile for the address_owner_user with the owned_address as home_address - create(:profile, user: address_owner_user, home_address: owned_address) - end - - context 'when user is axis mundi' do - let(:user) { axis_mundi_user } - - it { is_expected.to permit_action(:index) } - it { is_expected.to permit_action(:show) } - it { is_expected.to permit_action(:create) } - it { is_expected.to permit_action(:new) } - it { is_expected.to permit_action(:update) } - it { is_expected.to permit_action(:edit) } - it { is_expected.to permit_action(:destroy) } - end - - context 'when user is the owner of the address' do - let(:user) { address_owner_user } - - it { is_expected.not_to permit_action(:index) } - it { is_expected.to permit_action(:show) } - it { is_expected.to permit_action(:create) } - it { is_expected.to permit_action(:new) } - it { is_expected.to permit_action(:update) } - it { is_expected.to permit_action(:edit) } - it { is_expected.not_to permit_action(:destroy) } - end - - context 'when user owns a different address' do - let(:user) { address_owner_user } - let(:address) { other_address } - - it { is_expected.not_to permit_action(:show) } - it { is_expected.not_to permit_action(:update) } - end - - context 'when user is not the owner and not axis mundi' do - let(:user) { other_user } - - it { is_expected.not_to permit_action(:index) } - it { is_expected.not_to permit_action(:show) } - it { is_expected.not_to permit_action(:create) } - it { is_expected.not_to permit_action(:new) } - it { is_expected.not_to permit_action(:update) } - it { is_expected.not_to permit_action(:edit) } - it { is_expected.not_to permit_action(:destroy) } - end - - context 'when user is nil (not logged in)' do - let(:user) { nil } - - it { is_expected.not_to permit_action(:index) } - it { is_expected.not_to permit_action(:show) } - it { is_expected.not_to permit_action(:create) } - it { is_expected.not_to permit_action(:new) } - it { is_expected.not_to permit_action(:update) } - it { is_expected.not_to permit_action(:edit) } - it { is_expected.not_to permit_action(:destroy) } - end - - describe 'Scope' do - subject { Pundit.policy_scope(user, Address) } - - let!(:address1) { create(:address) } - let!(:address2) { create(:address) } - - context 'when user is axis mundi' do - let(:user) { axis_mundi_user } - - it 'includes all addresses' do - expect(subject).to include(address1, address2) - end - end - - context 'when user is not axis mundi' do - let(:user) { other_user } - - it 'returns an empty scope' do - expect(subject).to be_empty - end - end - end -end diff --git a/spec/policies/profile_policy_spec.rb b/spec/policies/profile_policy_spec.rb index ec7714b6..cc254a35 100644 --- a/spec/policies/profile_policy_spec.rb +++ b/spec/policies/profile_policy_spec.rb @@ -7,8 +7,7 @@ create(:profile, accepted_financial_aid_notice: true, preferred_first_name: 'John', preferred_last_name: 'Doe', umid: '12345678', grad_date: Date.today + 1.year, degree: 'Bachelor', class_level_id: create(:class_level).id, campus_id: create(:campus).id, - school_id: create(:school).id, home_address: create(:address), - campus_address: create(:address)) + school_id: create(:school).id) end let(:axis_mundi_role) { create(:role, kind: 'Axis Mundi') } @@ -46,25 +45,25 @@ let(:user) { create(:user) } # The user we're testing let(:another_user) { create(:user) } # A different user let(:profile) { create(:profile, user: another_user) } # Profile belongs to another user - + it 'permits new and create actions' do # Ensure the user does not have a profile expect(user.profile).to be_nil - + # Test new? policy expect(subject).to permit_action(:new) - + # Test create? policy expect(subject).to permit_action(:create) end - + it 'forbids show, update, and destroy actions' do # Test show? policy expect(subject).not_to permit_action(:show) - + # Test update? policy expect(subject).not_to permit_action(:update) - + # Test destroy? policy expect(subject).not_to permit_action(:destroy) end diff --git a/spec/support/user_creation_helpers.rb b/spec/support/user_creation_helpers.rb index 3d624f83..ca258034 100644 --- a/spec/support/user_creation_helpers.rb +++ b/spec/support/user_creation_helpers.rb @@ -30,9 +30,7 @@ def create_ugrad_student_with_profile(class_level_name) campus: create(:campus), grad_date: Date.today + 1.year, degree: "Bachelor's", - umid: format('%08d', rand(10000000..99999999)), - home_address: create(:address, address_type: create(:address_type, :home)), - campus_address: create(:address, address_type: create(:address_type, :campus)) + umid: format('%08d', rand(10000000..99999999)) ) user @@ -64,9 +62,7 @@ def create_gradstudent_with_profile(class_level_name) campus: create(:campus), grad_date: Date.today + 1.year, degree: "Master's", - umid: format('%08d', rand(10000000..99999999)), - home_address: create(:address, address_type: create(:address_type, :home)), - campus_address: create(:address, address_type: create(:address_type, :campus)) + umid: format('%08d', rand(10000000..99999999)) ) user