diff --git a/app/controllers/user_followings_controller.rb b/app/controllers/user_followings_controller.rb new file mode 100644 index 00000000..94ac0d89 --- /dev/null +++ b/app/controllers/user_followings_controller.rb @@ -0,0 +1,61 @@ +class UserFollowingsController < ApplicationController + before_action :set_user_following, only: [:show, :edit, :update, :destroy] + + # GET /user_followings + def index + @user_followings = UserFollowing.all + end + + # GET /user_followings/1 + def show + end + + # GET /user_followings/new + def new + @user_following = UserFollowing.new + end + + # GET /user_followings/1/edit + def edit + end + + # POST /user_followings + def create + @user_following = UserFollowing.new(user_following_params.merge({user_id: current_user.id})) + + if @user_following.save + redirect_to @user_following.followed_user, notice: "You're now following #{@user_following.followed_user.name.presence || 'this user'}" + else + render :new + end + end + + # PATCH/PUT /user_followings/1 + def update + if @user_following.update(user_following_params) + redirect_to @user_following, notice: 'User following was successfully updated.' + else + render :edit + end + end + + # DELETE /user_followings/1 + def destroy + user = @user_following.followed_user + + @user_following.destroy + redirect_to user, notice: "You're no longer following this user." + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_user_following + @user_following = UserFollowing.find(params[:id]) + end + + # Only allow a trusted parameter "white list" through. + def user_following_params + params.require(:user_following).permit(:followed_user_id) + end +end diff --git a/app/helpers/user_followings_helper.rb b/app/helpers/user_followings_helper.rb new file mode 100644 index 00000000..4a62dd04 --- /dev/null +++ b/app/helpers/user_followings_helper.rb @@ -0,0 +1,2 @@ +module UserFollowingsHelper +end diff --git a/app/models/user_following.rb b/app/models/user_following.rb new file mode 100644 index 00000000..741e5a09 --- /dev/null +++ b/app/models/user_following.rb @@ -0,0 +1,4 @@ +class UserFollowing < ApplicationRecord + belongs_to :user + belongs_to :followed_user, class_name: User.name +end diff --git a/app/models/users/user.rb b/app/models/users/user.rb index b61caa18..71ade066 100644 --- a/app/models/users/user.rb +++ b/app/models/users/user.rb @@ -42,6 +42,16 @@ class User < ApplicationRecord referral.referrer unless referral.nil? end + has_many :user_followings, dependent: :destroy + has_many :followed_users, through: :user_followings, source: :followed_user + # has_many :followed_by_users, through: :user_followings, source: :user # todo unsure how to actually write this, so we do it manually below + def followed_by_users + User.where(id: UserFollowing.where(followed_user_id: self.id).pluck(:user_id)) + end + def followed_by?(user) + followed_by_users.pluck(:id).include?(user.id) + end + has_many :votes, dependent: :destroy has_many :raffle_entries, dependent: :destroy diff --git a/app/views/user_followings/_form.html.erb b/app/views/user_followings/_form.html.erb new file mode 100644 index 00000000..78756237 --- /dev/null +++ b/app/views/user_followings/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_with(model: user_following, local: true) do |form| %> + <% if user_following.errors.any? %> +
+

<%= pluralize(user_following.errors.count, "error") %> prohibited this user_following from being saved:

+ + +
+ <% end %> + +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/user_followings/edit.html.erb b/app/views/user_followings/edit.html.erb new file mode 100644 index 00000000..25061959 --- /dev/null +++ b/app/views/user_followings/edit.html.erb @@ -0,0 +1,6 @@ +

Editing User Following

+ +<%= render 'form', user_following: @user_following %> + +<%= link_to 'Show', @user_following %> | +<%= link_to 'Back', user_followings_path %> diff --git a/app/views/user_followings/index.html.erb b/app/views/user_followings/index.html.erb new file mode 100644 index 00000000..46a9e10e --- /dev/null +++ b/app/views/user_followings/index.html.erb @@ -0,0 +1,25 @@ +

<%= notice %>

+ +

User Followings

+ + + + + + + + + + <% @user_followings.each do |user_following| %> + + + + + + <% end %> + +
<%= link_to 'Show', user_following %><%= link_to 'Edit', edit_user_following_path(user_following) %><%= link_to 'Destroy', user_following, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New User Following', new_user_following_path %> diff --git a/app/views/user_followings/new.html.erb b/app/views/user_followings/new.html.erb new file mode 100644 index 00000000..2884b6aa --- /dev/null +++ b/app/views/user_followings/new.html.erb @@ -0,0 +1,5 @@ +

New User Following

+ +<%= render 'form', user_following: @user_following %> + +<%= link_to 'Back', user_followings_path %> diff --git a/app/views/user_followings/show.html.erb b/app/views/user_followings/show.html.erb new file mode 100644 index 00000000..057482cb --- /dev/null +++ b/app/views/user_followings/show.html.erb @@ -0,0 +1,4 @@ +

<%= notice %>

+ +<%= link_to 'Edit', edit_user_following_path(@user_following) %> | +<%= link_to 'Back', user_followings_path %> diff --git a/app/views/users/profile/_actions.html.erb b/app/views/users/profile/_actions.html.erb index d0f03629..e2a72682 100644 --- a/app/views/users/profile/_actions.html.erb +++ b/app/views/users/profile/_actions.html.erb @@ -6,10 +6,34 @@ - <%= link_to Thredded::UrlsHelper.send_private_message_path(current_user: current_user, to: @user), class: 'collection-item' do %> + <% if user_signed_in? %> + <% if @user.followed_by?(current_user) %> + <%= form_for(current_user.user_followings.find_by(followed_user_id: @user.id), method: :delete) do |f| %> + <%= f.hidden_field :followed_user_id, value: @user.id %> + <%= link_to '#', onclick: "$('.edit_user_following').first().submit()", class: 'collection-item' do %> + Unfollow this user + + how_to_reg + + <% end %> + <% end %> + <% else %> + <%= form_for UserFollowing.new, method: :post do |f| %> + <%= f.hidden_field :followed_user_id, value: @user.id %> + <%= link_to '#', onclick: "$('#new_user_following').submit()", class: 'collection-item' do %> + Follow this user + + <%= User.icon %> + + <% end %> + <% end %> + <% end %> + <% end %> + + <%= link_to Thredded::UrlsHelper.send_private_message_path(current_user: current_user, to: @user), class: 'collection-item blue-text' do %> Send a message - forum + forum <% end %> diff --git a/config/routes.rb b/config/routes.rb index 6473fcb0..b433a8fc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,6 +20,7 @@ Rails.application.routes.draw do # todo page tags here end end + resources :user_followings get '/@:username', to: 'users#show', as: :profile_by_username resources :documents do diff --git a/db/migrate/20200328191204_create_user_followings.rb b/db/migrate/20200328191204_create_user_followings.rb new file mode 100644 index 00000000..ab9f9d96 --- /dev/null +++ b/db/migrate/20200328191204_create_user_followings.rb @@ -0,0 +1,10 @@ +class CreateUserFollowings < ActiveRecord::Migration[6.0] + def change + create_table :user_followings do |t| + t.references :user, null: false, foreign_key: true + t.references :followed_user, null: false, index: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index de7c3ccc..eed1abd0 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.define(version: 2020_03_02_022930) do +ActiveRecord::Schema.define(version: 2020_03_28_191204) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false @@ -41,22 +41,6 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do t.index ["user_id"], name: "index_api_keys_on_user_id" end - create_table "application_integrations", force: :cascade do |t| - t.integer "user_id", null: false - t.string "name" - t.string "description" - t.string "organization_name" - t.string "organization_url" - t.string "website_url" - t.string "privacy_policy_url" - t.string "token" - t.datetime "last_used_at" - t.string "authorization_callback_url" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - t.index ["user_id"], name: "index_application_integrations_on_user_id" - end - create_table "archenemyships", force: :cascade do |t| t.integer "user_id" t.integer "character_id" @@ -1036,15 +1020,6 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do t.index ["entity_type", "entity_id"], name: "index_document_entities_on_entity_type_and_entity_id" end - create_table "document_notes", force: :cascade do |t| - t.integer "document_id", null: false - t.string "title" - t.string "notes" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - t.index ["document_id"], name: "index_document_notes_on_document_id" - end - create_table "documents", force: :cascade do |t| t.integer "user_id" t.text "body" @@ -1074,7 +1049,6 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do t.integer "father_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.index "\"father_id\", \"character_id\", \"deleted_at\"", name: "index_fatherships_on_father_id_and_character_id_and_deleted_at" end create_table "flora_eaten_bies", force: :cascade do |t| @@ -1394,7 +1368,7 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do t.datetime "updated_at", null: false t.string "src_file_name" t.string "src_content_type" - t.integer "src_file_size" + t.bigint "src_file_size" t.datetime "src_updated_at" t.index ["content_type", "content_id"], name: "index_image_uploads_on_content_type_and_content_id" t.index ["user_id"], name: "index_image_uploads_on_user_id" @@ -1682,6 +1656,324 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do t.index ["user_id"], name: "index_locations_on_user_id" end + create_table "lore_believers", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "believer_id" + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["lore_id"], name: "index_lore_believers_on_lore_id" + t.index ["user_id"], name: "index_lore_believers_on_user_id" + end + + create_table "lore_buildings", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "building_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["building_id"], name: "index_lore_buildings_on_building_id" + t.index ["lore_id"], name: "index_lore_buildings_on_lore_id" + t.index ["user_id"], name: "index_lore_buildings_on_user_id" + end + + create_table "lore_characters", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "character_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["character_id"], name: "index_lore_characters_on_character_id" + t.index ["lore_id"], name: "index_lore_characters_on_lore_id" + t.index ["user_id"], name: "index_lore_characters_on_user_id" + end + + create_table "lore_conditions", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "condition_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["condition_id"], name: "index_lore_conditions_on_condition_id" + t.index ["lore_id"], name: "index_lore_conditions_on_lore_id" + t.index ["user_id"], name: "index_lore_conditions_on_user_id" + end + + create_table "lore_continents", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "continent_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["continent_id"], name: "index_lore_continents_on_continent_id" + t.index ["lore_id"], name: "index_lore_continents_on_lore_id" + t.index ["user_id"], name: "index_lore_continents_on_user_id" + end + + create_table "lore_countries", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "country_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["country_id"], name: "index_lore_countries_on_country_id" + t.index ["lore_id"], name: "index_lore_countries_on_lore_id" + t.index ["user_id"], name: "index_lore_countries_on_user_id" + end + + create_table "lore_created_traditions", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "created_tradition_id" + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["lore_id"], name: "index_lore_created_traditions_on_lore_id" + t.index ["user_id"], name: "index_lore_created_traditions_on_user_id" + end + + create_table "lore_creatures", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "creature_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["creature_id"], name: "index_lore_creatures_on_creature_id" + t.index ["lore_id"], name: "index_lore_creatures_on_lore_id" + t.index ["user_id"], name: "index_lore_creatures_on_user_id" + end + + create_table "lore_deities", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "deity_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["deity_id"], name: "index_lore_deities_on_deity_id" + t.index ["lore_id"], name: "index_lore_deities_on_lore_id" + t.index ["user_id"], name: "index_lore_deities_on_user_id" + end + + create_table "lore_floras", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "flora_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["flora_id"], name: "index_lore_floras_on_flora_id" + t.index ["lore_id"], name: "index_lore_floras_on_lore_id" + t.index ["user_id"], name: "index_lore_floras_on_user_id" + end + + create_table "lore_foods", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "food_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["food_id"], name: "index_lore_foods_on_food_id" + t.index ["lore_id"], name: "index_lore_foods_on_lore_id" + t.index ["user_id"], name: "index_lore_foods_on_user_id" + end + + create_table "lore_governments", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "government_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["government_id"], name: "index_lore_governments_on_government_id" + t.index ["lore_id"], name: "index_lore_governments_on_lore_id" + t.index ["user_id"], name: "index_lore_governments_on_user_id" + end + + create_table "lore_groups", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "group_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["group_id"], name: "index_lore_groups_on_group_id" + t.index ["lore_id"], name: "index_lore_groups_on_lore_id" + t.index ["user_id"], name: "index_lore_groups_on_user_id" + end + + create_table "lore_jobs", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "job_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["job_id"], name: "index_lore_jobs_on_job_id" + t.index ["lore_id"], name: "index_lore_jobs_on_lore_id" + t.index ["user_id"], name: "index_lore_jobs_on_user_id" + end + + create_table "lore_landmarks", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "landmark_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["landmark_id"], name: "index_lore_landmarks_on_landmark_id" + t.index ["lore_id"], name: "index_lore_landmarks_on_lore_id" + t.index ["user_id"], name: "index_lore_landmarks_on_user_id" + end + + create_table "lore_magics", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "magic_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["lore_id"], name: "index_lore_magics_on_lore_id" + t.index ["magic_id"], name: "index_lore_magics_on_magic_id" + t.index ["user_id"], name: "index_lore_magics_on_user_id" + end + + create_table "lore_original_languages", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "original_language_id" + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["lore_id"], name: "index_lore_original_languages_on_lore_id" + t.index ["user_id"], name: "index_lore_original_languages_on_user_id" + end + + create_table "lore_planets", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "planet_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["lore_id"], name: "index_lore_planets_on_lore_id" + t.index ["planet_id"], name: "index_lore_planets_on_planet_id" + t.index ["user_id"], name: "index_lore_planets_on_user_id" + end + + create_table "lore_races", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "race_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["lore_id"], name: "index_lore_races_on_lore_id" + t.index ["race_id"], name: "index_lore_races_on_race_id" + t.index ["user_id"], name: "index_lore_races_on_user_id" + end + + create_table "lore_related_lores", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "related_lore_id" + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["lore_id"], name: "index_lore_related_lores_on_lore_id" + t.index ["user_id"], name: "index_lore_related_lores_on_user_id" + end + + create_table "lore_religions", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "religion_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["lore_id"], name: "index_lore_religions_on_lore_id" + t.index ["religion_id"], name: "index_lore_religions_on_religion_id" + t.index ["user_id"], name: "index_lore_religions_on_user_id" + end + + create_table "lore_schools", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "school_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["lore_id"], name: "index_lore_schools_on_lore_id" + t.index ["school_id"], name: "index_lore_schools_on_school_id" + t.index ["user_id"], name: "index_lore_schools_on_user_id" + end + + create_table "lore_sports", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "sport_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["lore_id"], name: "index_lore_sports_on_lore_id" + t.index ["sport_id"], name: "index_lore_sports_on_sport_id" + t.index ["user_id"], name: "index_lore_sports_on_user_id" + end + + create_table "lore_technologies", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "technology_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["lore_id"], name: "index_lore_technologies_on_lore_id" + t.index ["technology_id"], name: "index_lore_technologies_on_technology_id" + t.index ["user_id"], name: "index_lore_technologies_on_user_id" + end + + create_table "lore_towns", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "town_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["lore_id"], name: "index_lore_towns_on_lore_id" + t.index ["town_id"], name: "index_lore_towns_on_town_id" + t.index ["user_id"], name: "index_lore_towns_on_user_id" + end + + create_table "lore_traditions", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "tradition_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["lore_id"], name: "index_lore_traditions_on_lore_id" + t.index ["tradition_id"], name: "index_lore_traditions_on_tradition_id" + t.index ["user_id"], name: "index_lore_traditions_on_user_id" + end + + create_table "lore_variations", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "variation_id" + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["lore_id"], name: "index_lore_variations_on_lore_id" + t.index ["user_id"], name: "index_lore_variations_on_user_id" + end + + create_table "lore_vehicles", force: :cascade do |t| + t.integer "lore_id", null: false + t.integer "vehicle_id", null: false + t.integer "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["lore_id"], name: "index_lore_vehicles_on_lore_id" + t.index ["user_id"], name: "index_lore_vehicles_on_user_id" + t.index ["vehicle_id"], name: "index_lore_vehicles_on_vehicle_id" + end + + create_table "lores", force: :cascade do |t| + t.string "name" + t.integer "user_id", null: false + t.integer "universe_id" + t.datetime "deleted_at" + t.datetime "archived_at" + t.string "privacy" + t.boolean "favorite" + t.string "page_type", default: "Lore" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["universe_id"], name: "index_lores_on_universe_id" + t.index ["user_id"], name: "index_lores_on_user_id" + end + create_table "magic_deityships", force: :cascade do |t| t.integer "user_id" t.integer "magic_id" @@ -1743,7 +2035,6 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do t.integer "mother_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.index "\"mother_id\", \"character_id\", \"deleted_at\"", name: "index_motherships_on_mother_id_and_character_id_and_deleted_at" end create_table "notable_cities_relationships", force: :cascade do |t| @@ -2802,7 +3093,6 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do t.string "page_type", default: "Universe" t.datetime "archived_at" t.boolean "favorite" - t.index "\"user_id\", \"universe_id\", \"deleted_at\"", name: "index_universes_on_user_id_and_universe_id_and_deleted_at" t.index ["deleted_at", "id"], name: "index_universes_on_deleted_at_and_id" t.index ["deleted_at", "user_id"], name: "index_universes_on_deleted_at_and_user_id" t.index ["deleted_at"], name: "index_universes_on_deleted_at" @@ -2818,6 +3108,15 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do t.index ["user_id"], name: "index_user_content_type_activators_on_user_id" end + create_table "user_followings", force: :cascade do |t| + t.integer "user_id", null: false + t.integer "followed_user_id", null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["followed_user_id"], name: "index_user_followings_on_followed_user_id" + t.index ["user_id"], name: "index_user_followings_on_user_id" + end + create_table "users", force: :cascade do |t| t.string "name" t.string "email", null: false @@ -2854,7 +3153,6 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do t.string "interests" t.string "forums_badge_text" t.boolean "keyboard_shortcuts_preference" - t.date "birthday" t.string "favorite_book" t.string "website" t.string "inspirations" @@ -2910,7 +3208,6 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "api_keys", "users" - add_foreign_key "application_integrations", "users" add_foreign_key "buildings", "universes" add_foreign_key "buildings", "users" add_foreign_key "character_birthtowns", "characters" @@ -2967,6 +3264,8 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do add_foreign_key "continents", "users" add_foreign_key "contributors", "universes" add_foreign_key "contributors", "users" + add_foreign_key "countries", "universes" + add_foreign_key "countries", "users" add_foreign_key "country_bordering_countries", "countries" add_foreign_key "country_bordering_countries", "users" add_foreign_key "country_creatures", "countries" @@ -2993,6 +3292,8 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do add_foreign_key "country_towns", "countries" add_foreign_key "country_towns", "towns" add_foreign_key "country_towns", "users" + add_foreign_key "deities", "universes" + add_foreign_key "deities", "users" add_foreign_key "deity_abilities", "deities" add_foreign_key "deity_abilities", "users" add_foreign_key "deity_character_children", "deities" @@ -3033,8 +3334,10 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do add_foreign_key "document_categories", "document_analyses" add_foreign_key "document_concepts", "document_analyses" add_foreign_key "document_entities", "document_analyses" - add_foreign_key "document_notes", "documents" + add_foreign_key "documents", "universes" add_foreign_key "documents", "users" + add_foreign_key "floras", "universes" + add_foreign_key "floras", "users" add_foreign_key "foods", "universes" add_foreign_key "foods", "users" add_foreign_key "government_creatures", "creatures" @@ -3053,6 +3356,8 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do add_foreign_key "government_technologies", "governments" add_foreign_key "government_technologies", "technologies" add_foreign_key "government_technologies", "users" + add_foreign_key "governments", "universes" + add_foreign_key "governments", "users" add_foreign_key "group_creatures", "creatures" add_foreign_key "group_creatures", "groups" add_foreign_key "group_creatures", "users" @@ -3073,6 +3378,8 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do add_foreign_key "landmark_floras", "users" add_foreign_key "landmark_nearby_towns", "landmarks" add_foreign_key "landmark_nearby_towns", "users" + add_foreign_key "landmarks", "universes" + add_foreign_key "landmarks", "users" add_foreign_key "location_capital_towns", "locations" add_foreign_key "location_capital_towns", "users" add_foreign_key "location_landmarks", "landmarks" @@ -3082,6 +3389,87 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do add_foreign_key "location_largest_towns", "users" add_foreign_key "location_notable_towns", "locations" add_foreign_key "location_notable_towns", "users" + add_foreign_key "lore_believers", "lores" + add_foreign_key "lore_believers", "users" + add_foreign_key "lore_buildings", "buildings" + add_foreign_key "lore_buildings", "lores" + add_foreign_key "lore_buildings", "users" + add_foreign_key "lore_characters", "characters" + add_foreign_key "lore_characters", "lores" + add_foreign_key "lore_characters", "users" + add_foreign_key "lore_conditions", "conditions" + add_foreign_key "lore_conditions", "lores" + add_foreign_key "lore_conditions", "users" + add_foreign_key "lore_continents", "continents" + add_foreign_key "lore_continents", "lores" + add_foreign_key "lore_continents", "users" + add_foreign_key "lore_countries", "countries" + add_foreign_key "lore_countries", "lores" + add_foreign_key "lore_countries", "users" + add_foreign_key "lore_created_traditions", "lores" + add_foreign_key "lore_created_traditions", "users" + add_foreign_key "lore_creatures", "creatures" + add_foreign_key "lore_creatures", "lores" + add_foreign_key "lore_creatures", "users" + add_foreign_key "lore_deities", "deities" + add_foreign_key "lore_deities", "lores" + add_foreign_key "lore_deities", "users" + add_foreign_key "lore_floras", "floras" + add_foreign_key "lore_floras", "lores" + add_foreign_key "lore_floras", "users" + add_foreign_key "lore_foods", "foods" + add_foreign_key "lore_foods", "lores" + add_foreign_key "lore_foods", "users" + add_foreign_key "lore_governments", "governments" + add_foreign_key "lore_governments", "lores" + add_foreign_key "lore_governments", "users" + add_foreign_key "lore_groups", "groups" + add_foreign_key "lore_groups", "lores" + add_foreign_key "lore_groups", "users" + add_foreign_key "lore_jobs", "jobs" + add_foreign_key "lore_jobs", "lores" + add_foreign_key "lore_jobs", "users" + add_foreign_key "lore_landmarks", "landmarks" + add_foreign_key "lore_landmarks", "lores" + add_foreign_key "lore_landmarks", "users" + add_foreign_key "lore_magics", "lores" + add_foreign_key "lore_magics", "magics" + add_foreign_key "lore_magics", "users" + add_foreign_key "lore_original_languages", "lores" + add_foreign_key "lore_original_languages", "users" + add_foreign_key "lore_planets", "lores" + add_foreign_key "lore_planets", "planets" + add_foreign_key "lore_planets", "users" + add_foreign_key "lore_races", "lores" + add_foreign_key "lore_races", "races" + add_foreign_key "lore_races", "users" + add_foreign_key "lore_related_lores", "lores" + add_foreign_key "lore_related_lores", "users" + add_foreign_key "lore_religions", "lores" + add_foreign_key "lore_religions", "religions" + add_foreign_key "lore_religions", "users" + add_foreign_key "lore_schools", "lores" + add_foreign_key "lore_schools", "schools" + add_foreign_key "lore_schools", "users" + add_foreign_key "lore_sports", "lores" + add_foreign_key "lore_sports", "sports" + add_foreign_key "lore_sports", "users" + add_foreign_key "lore_technologies", "lores" + add_foreign_key "lore_technologies", "technologies" + add_foreign_key "lore_technologies", "users" + add_foreign_key "lore_towns", "lores" + add_foreign_key "lore_towns", "towns" + add_foreign_key "lore_towns", "users" + add_foreign_key "lore_traditions", "lores" + add_foreign_key "lore_traditions", "traditions" + add_foreign_key "lore_traditions", "users" + add_foreign_key "lore_variations", "lores" + add_foreign_key "lore_variations", "users" + add_foreign_key "lore_vehicles", "lores" + add_foreign_key "lore_vehicles", "users" + add_foreign_key "lore_vehicles", "vehicles" + add_foreign_key "lores", "universes" + add_foreign_key "lores", "users" add_foreign_key "notice_dismissals", "users" add_foreign_key "page_tags", "users" add_foreign_key "paypal_invoices", "page_unlock_promo_codes" @@ -3124,6 +3512,8 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do add_foreign_key "planet_towns", "planets" add_foreign_key "planet_towns", "towns" add_foreign_key "planet_towns", "users" + add_foreign_key "planets", "universes" + add_foreign_key "planets", "users" add_foreign_key "promotions", "page_unlock_promo_codes" add_foreign_key "promotions", "users" add_foreign_key "raffle_entries", "users" @@ -3137,6 +3527,8 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do add_foreign_key "sports", "users" add_foreign_key "subscriptions", "billing_plans" add_foreign_key "subscriptions", "users" + add_foreign_key "technologies", "universes" + add_foreign_key "technologies", "users" add_foreign_key "technology_characters", "characters" add_foreign_key "technology_characters", "technologies" add_foreign_key "technology_characters", "users" @@ -3164,6 +3556,10 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do add_foreign_key "technology_towns", "technologies" add_foreign_key "technology_towns", "towns" add_foreign_key "technology_towns", "users" + add_foreign_key "thredded_messageboard_users", "thredded_messageboards", on_delete: :cascade + add_foreign_key "thredded_messageboard_users", "thredded_user_details", on_delete: :cascade + add_foreign_key "thredded_user_post_notifications", "thredded_posts", column: "post_id", on_delete: :cascade + add_foreign_key "thredded_user_post_notifications", "users", on_delete: :cascade add_foreign_key "town_citizens", "towns" add_foreign_key "town_citizens", "users" add_foreign_key "town_countries", "countries" @@ -3183,9 +3579,12 @@ ActiveRecord::Schema.define(version: 2020_03_02_022930) do add_foreign_key "town_languages", "users" add_foreign_key "town_nearby_landmarks", "towns" add_foreign_key "town_nearby_landmarks", "users" + add_foreign_key "towns", "universes" + add_foreign_key "towns", "users" add_foreign_key "traditions", "universes" add_foreign_key "traditions", "users" add_foreign_key "user_content_type_activators", "users" + add_foreign_key "user_followings", "users" add_foreign_key "vehicles", "universes" add_foreign_key "vehicles", "users" add_foreign_key "votes", "users" diff --git a/test/controllers/user_followings_controller_test.rb b/test/controllers/user_followings_controller_test.rb new file mode 100644 index 00000000..21c64e5d --- /dev/null +++ b/test/controllers/user_followings_controller_test.rb @@ -0,0 +1,48 @@ +require 'test_helper' + +class UserFollowingsControllerTest < ActionDispatch::IntegrationTest + setup do + @user_following = user_followings(:one) + end + + test "should get index" do + get user_followings_url + assert_response :success + end + + test "should get new" do + get new_user_following_url + assert_response :success + end + + test "should create user_following" do + assert_difference('UserFollowing.count') do + post user_followings_url, params: { user_following: { } } + end + + assert_redirected_to user_following_url(UserFollowing.last) + end + + test "should show user_following" do + get user_following_url(@user_following) + assert_response :success + end + + test "should get edit" do + get edit_user_following_url(@user_following) + assert_response :success + end + + test "should update user_following" do + patch user_following_url(@user_following), params: { user_following: { } } + assert_redirected_to user_following_url(@user_following) + end + + test "should destroy user_following" do + assert_difference('UserFollowing.count', -1) do + delete user_following_url(@user_following) + end + + assert_redirected_to user_followings_url + end +end diff --git a/test/fixtures/user_followings.yml b/test/fixtures/user_followings.yml new file mode 100644 index 00000000..4bd07908 --- /dev/null +++ b/test/fixtures/user_followings.yml @@ -0,0 +1,9 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + user: one + followed_user: one + +two: + user: two + followed_user: two diff --git a/test/models/user_following_test.rb b/test/models/user_following_test.rb new file mode 100644 index 00000000..9042b3ce --- /dev/null +++ b/test/models/user_following_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserFollowingTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/user_followings_test.rb b/test/system/user_followings_test.rb new file mode 100644 index 00000000..ef34465f --- /dev/null +++ b/test/system/user_followings_test.rb @@ -0,0 +1,41 @@ +require "application_system_test_case" + +class UserFollowingsTest < ApplicationSystemTestCase + setup do + @user_following = user_followings(:one) + end + + test "visiting the index" do + visit user_followings_url + assert_selector "h1", text: "User Followings" + end + + test "creating a User following" do + visit user_followings_url + click_on "New User Following" + + click_on "Create User following" + + assert_text "User following was successfully created" + click_on "Back" + end + + test "updating a User following" do + visit user_followings_url + click_on "Edit", match: :first + + click_on "Update User following" + + assert_text "User following was successfully updated" + click_on "Back" + end + + test "destroying a User following" do + visit user_followings_url + page.accept_confirm do + click_on "Destroy", match: :first + end + + assert_text "User following was successfully destroyed" + end +end