diff --git a/Gemfile b/Gemfile index f2f1302f..fc332e32 100644 --- a/Gemfile +++ b/Gemfile @@ -55,8 +55,8 @@ gem 'slack-notifier' gem 'redcarpet' #markdown formatting # Analytics -gem 'raygun4ruby' gem 'mixpanel-ruby' +gem 'barnes' # Sharing gem 'social-share-button' diff --git a/Gemfile.lock b/Gemfile.lock index 8b343da4..6b281c04 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -83,6 +83,9 @@ GEM babel-source (>= 4.0, < 6) execjs (~> 2.0) backports (3.11.3) + barnes (0.0.7) + multi_json (~> 1) + statsd-ruby (~> 1.1) bcrypt (3.1.12) better_errors (2.4.0) coderay (>= 1.0.0) @@ -202,8 +205,6 @@ GEM activesupport (>= 2) nokogiri (>= 1.4) htmlentities (4.3.4) - httparty (0.16.2) - multi_xml (>= 0.5.2) i18n (1.1.0) concurrent-ruby (~> 1.0) inline_svg (1.3.1) @@ -259,7 +260,6 @@ GEM moneta (1.0.0) multi_json (1.13.1) multi_test (0.1.2) - multi_xml (0.6.0) multipart-post (2.0.0) mustache (1.0.5) nenv (0.3.0) @@ -349,11 +349,6 @@ GEM thor (>= 0.18.1, < 2.0) rainbow (3.0.0) rake (12.3.1) - raygun4ruby (2.7.0) - concurrent-ruby - httparty (> 0.13.7) - json - rack rb-fsevent (0.10.3) rb-gravatar (1.0.5) rb-inotify (0.9.10) @@ -400,7 +395,7 @@ GEM ruby-prof (0.15.9) ruby-progressbar (1.9.0) ruby_dep (1.5.0) - rubyzip (1.2.1) + rubyzip (1.2.2) safe_yaml (1.0.4) sanitize (4.6.5) crass (~> 1.0.2) @@ -444,6 +439,7 @@ GEM sprockets (>= 3.0.0) sqlite3 (1.3.13) stackprof (0.2.12) + statsd-ruby (1.4.0) stripe (3.15.0) faraday (~> 0.10) stripe_event (2.1.1) @@ -510,6 +506,7 @@ DEPENDENCIES authority aws-sdk (~> 1.5) aws-sdk-s3 + barnes better_errors binding_of_caller bullet (>= 5.4) @@ -552,7 +549,6 @@ DEPENDENCIES rails-perftest rails-ujs rails_12factor - raygun4ruby redcarpet rmagick rspec-prof diff --git a/README.rdoc b/README.rdoc index c3b2623d..764ed5d1 100644 --- a/README.rdoc +++ b/README.rdoc @@ -33,9 +33,9 @@ You'll notice there are *a lot* of issues in *a lot* of milestones. Call it feat TL;DR Milestones are independent of each other -- work on whatever you want to see made! -== Installing the notebook stack locally +== Installing the notebook development stack locally -Install ruby 2.5.1 +Install ruby 2.5.1 (using `rbenv`, `rvm`, any other Ruby version manager, or just plain ol' ruby) rbenv install 2.5.1 diff --git a/app/assets/stylesheets/fixes.scss b/app/assets/stylesheets/fixes.scss deleted file mode 100644 index 2b2360e5..00000000 --- a/app/assets/stylesheets/fixes.scss +++ /dev/null @@ -1,11 +0,0 @@ -/* - * These are temporary fixes and/or hacks for issues seen in prod. Every line here - * should be assumed temporary and with an inherit desire to remove it with something - * cleaner. - */ - -// For some reason, the latest materializecss hides checkboxes. This un-hides them. -input[type="checkbox"]:not(:checked), input[type="checkbox"]:checked { - position: inherit !important; - opacity: inherit !important; -} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index efbc52b9..5c95affe 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -43,13 +43,10 @@ class ApplicationController < ActionController::Base return unless user_signed_in? @activated_content_types = ( - Rails.application.config.content_types[:all].map(&:name) & # Use config to dictate order + Rails.application.config.content_types[:all].map(&:name) & # Use config to dictate order, but AND to only include what a user has turned on current_user.user_content_type_activators.pluck(:content_type) ) - @current_user_content = {} - @activated_content_types.each do |content_type| - @current_user_content[content_type] = content_type.constantize.where(user: current_user).to_a - end + @current_user_content = current_user.content(content_types: @activated_content_types) end end diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index ccc35e73..2713217a 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -1,6 +1,6 @@ class ContentController < ApplicationController # todo before_action :load_content to set @content - before_action :authenticate_user!, only: [:index, :new, :create, :edit, :update, :destroy] + before_action :authenticate_user!, only: [:index, :new, :create, :edit, :update, :destroy, :deleted, :attributes] before_action :migrate_old_style_field_values, only: [:show, :edit] before_action :populate_linkable_content_for_each_content_type, only: [:new, :edit] diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index ff3fd13d..7edd9268 100644 --- a/app/controllers/export_controller.rb +++ b/app/controllers/export_controller.rb @@ -27,13 +27,13 @@ class ExportController < ApplicationController def notebook_json report_to_mixpanel 'json', 'notebook' - json_dump = current_user.content.map { |category, content| {"#{category}": fill_relations(content)} }.to_json + json_dump = current_user.content.map { |category, content| {"#{category}": fill_relations(category.constantize, content)} }.to_json send_data json_dump, filename: "notebook-#{Date.today}.json" end def notebook_xml report_to_mixpanel 'xml', 'notebook' - xml_dump = current_user.content.map { |category, content| {"#{category}": fill_relations(content)}}.to_xml + xml_dump = current_user.content.map { |category, content| {"#{category}": fill_relations(category.constantize, content)}}.to_xml send_data xml_dump, filename: "notebook-#{Date.today}.xml" end @@ -88,8 +88,7 @@ class ExportController < ApplicationController end end - def fill_relations ar_relation - ar_class = ar_relation.build.class + def fill_relations(ar_class, ar_relation) attribute_categories = ar_class.attribute_categories(current_user) ar_relation.map do |content| @@ -99,7 +98,7 @@ class ExportController < ApplicationController begin value = content.send(attr.name) rescue - value = Attribute.where(user: current_user, attribute_field: attr, entity: content).first + value = Attribute.find_by(user: current_user, attribute_field: attr, entity_id: content.id, entity_type: ar_class.name) value = value.value if value end next if value.nil? || value.blank? diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index a90a7544..287caf7c 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -37,20 +37,20 @@ class MainController < ApplicationController end def recent_content - content_types = Rails.application.config.content_types[:all] - # todo optimize this / use Attributes - @recent_edits = content_types.flat_map { |klass| - klass.where(user_id: current_user.id) + @recent_edits = @activated_content_types.flat_map { |klass| + klass.constantize + .where(user_id: current_user.id) .order(updated_at: :desc) .limit(100) }.sort_by(&:updated_at) .last(100) .reverse - @recent_creates = content_types.flat_map { |klass| - klass.where(user_id: current_user.id) + @recent_creates = @activated_content_types.flat_map { |klass| + klass.constantize + .where(user_id: current_user.id) .order(created_at: :desc) .limit(100) }.sort_by(&:created_at) @@ -84,10 +84,21 @@ class MainController < ApplicationController def set_random_content @activated_content_types.shuffle.each do |content_type| - if @universe_scope.present? - @content = content_type.constantize.where(user: current_user, universe: @universe_scope).sample + if content_type.downcase == "universe" + if @universe_scope.present? + # when we want to enable prompts for contributing universes we can remove the user: + # selector here, but we will need to verify the user has permission to see the universe + # when we do that, or else prompts could open leak + @content = content_type.constantize.where(user: current_user, id: @universe_scope.id).sample + else + @content = content_type.constantize.where(user: current_user).sample + end else - @content = content_type.constantize.where(user: current_user).sample + if @universe_scope.present? + @content = content_type.constantize.where(user: current_user, universe: @universe_scope).sample + else + @content = content_type.constantize.where(user: current_user).sample + end end return if @content.present? diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 46c6904f..56ede4eb 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -25,10 +25,12 @@ class SearchController < ApplicationController # Returns all attributes on a class that we match against in a search. # Usage: searchable_attributes_for(Character) => [:name, :role, ...] def searchable_attributes_for klass - related_controller = "#{klass.to_s.pluralize}Controller".constantize.new + related_controller = "#{klass.to_s.pluralize}Controller".constantize.new # can throw NameError related_controller.send(:content_param_list).select do |attribute| !attribute.is_a?(Hash) && searchable_attribute?(attribute.to_s) end + rescue NameError # If we don't have a controller for a particular content type, treat it as no results + [] end # Returns whether or not a particular attribute should be included on searches. diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index 17631c73..6bf5b573 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -82,7 +82,7 @@ class SubscriptionsController < ApplicationController end new_plan_id = params[:plan] - result = move_user_to_plan_requested(new_plan_id) + result = move_user_to_plan_requested(new_plan_id) if new_plan_id if result == :payment_method_needed redirect_to payment_info_path(plan: new_plan_id) diff --git a/app/models/concerns/has_content.rb b/app/models/concerns/has_content.rb index e8bc250f..a72b590e 100644 --- a/app/models/concerns/has_content.rb +++ b/app/models/concerns/has_content.rb @@ -19,26 +19,32 @@ module HasContent # characters: [...], # locations: [...] # } - def content - @user_content ||= begin - content_value = {} - Rails.application.config.content_types[:all].each do |type| - relation = type.name.downcase.pluralize.to_sym # :characters - content_value[relation] = send(relation) - end - - content_value - end + def content( + content_types: Rails.application.config.content_types[:all].map(&:name), + page_scoping: { user_id: self.id } + ) + @user_content ||= content_list(page_scoping: page_scoping, content_types: content_types).group_by(&:page_type) end # [..., ...] - def content_list - @user_content_list ||= begin - Rails.application.config.content_types[:all].flat_map do |type| - relation = type.name.downcase.pluralize.to_sym # :characters - send(relation) + def content_list( + content_types: Rails.application.config.content_types[:all].map(&:name), + page_scoping: { user_id: self.id } + ) + # todo we can't select for universe_id here which kind of sucks, so we need to research 1) the repercussions, 2) what to do instead + polymorphic_content_fields = [:id, :name, :page_type, :user_id, :created_at, :updated_at, :deleted_at, :privacy] + + chained_query = nil + (content_types + ["ContentPage"]).each do |content_type| + content_type_class = content_type.constantize + if chained_query.nil? + chained_query = content_type_class.select(*polymorphic_content_fields).where(page_scoping) + else + chained_query = content_type_class.select(*polymorphic_content_fields).where(page_scoping).union(chained_query) end end + + @user_content_list ||= chained_query end # { @@ -46,25 +52,12 @@ module HasContent # locations: [...] # } def content_in_universe universe_id - @user_content_in_universe ||= begin - content_value = {} - Rails.application.config.content_types[:all_non_universe].each do |type| - relation = type.name.downcase.pluralize.to_sym # :characters - content_value[relation] = send(relation).in_universe(universe_id) - end - - content_value - end + @user_content_in_universe ||= content_list(page_scoping: { user_id: self.id, universe_id: universe_id }).group_by(&:page_type) end # 5 def content_count - @user_content_count ||= begin - Rails.application.config.content_types[:all].map do |type| - relation = type.name.downcase.pluralize.to_sym # :characters - send(relation).count - end.sum - end + @user_content_count ||= content_list.count end # { diff --git a/app/models/content_page.rb b/app/models/content_page.rb new file mode 100644 index 00000000..99c38854 --- /dev/null +++ b/app/models/content_page.rb @@ -0,0 +1,4 @@ +class ContentPage < ApplicationRecord + belongs_to :user + belongs_to :universe +end diff --git a/app/services/subscription_service.rb b/app/services/subscription_service.rb index b3da8ce0..e976c0e9 100644 --- a/app/services/subscription_service.rb +++ b/app/services/subscription_service.rb @@ -3,6 +3,7 @@ class SubscriptionService < Service def self.add_subscription(user, plan_id) related_plan = BillingPlan.find_by(stripe_plan_id: plan_id, available: true) + raise "Plan #{plan_id} not available for user #{user.id}" if related_plan.nil? # Add any bonus bandwidth granted by the plan user.update( diff --git a/app/views/cards/user/_recent_activity.html.erb b/app/views/cards/user/_recent_activity.html.erb index 717c3902..5b115de1 100644 --- a/app/views/cards/user/_recent_activity.html.erb +++ b/app/views/cards/user/_recent_activity.html.erb @@ -5,7 +5,7 @@ locals: { title: defined?(title) ? title : 'Recent creations', content_list: content_list, - content_type: Character + content_type: Character # todo why is this hard-coded? } %> diff --git a/app/views/content/cards/_in_universe_content_list.html.erb b/app/views/content/cards/_in_universe_content_list.html.erb index 9489489d..7f6de3fa 100644 --- a/app/views/content/cards/_in_universe_content_list.html.erb +++ b/app/views/content/cards/_in_universe_content_list.html.erb @@ -81,11 +81,11 @@ <% content_list.each do |content| %> - <%= link_to list_name_lookup_cache[content.id].presence || content.name, polymorphic_path(content) %> + <%= link_to list_name_lookup_cache[content.id].presence || content.name, polymorphic_path(content.page_type.downcase, id: content.id) %> <%# truncate(content.description, length: 200) %>
- <%= link_to edit_polymorphic_path(content) do %> + <%= link_to edit_polymorphic_path(content.page_type.downcase, id: content.id) do %> edit <% end %>
diff --git a/app/views/content/list/_list.html.erb b/app/views/content/list/_list.html.erb index ca680bf7..0ac06680 100644 --- a/app/views/content/list/_list.html.erb +++ b/app/views/content/list/_list.html.erb @@ -10,7 +10,7 @@ list_name_lookup_cache = Hash[ name_field.attribute_values.where( entity_type: content_type.name - ).pluck(:entity_id, :value) + ).pluck(:entity_type, :entity_id, :value).map { |page_type, page_id, value| ["#{page_type}_#{page_id}", value]} ] else list_name_lookup_cache = {} @@ -28,7 +28,7 @@ <%= content.class.icon %> <% end %> - <%= link_to (content.respond_to?(:label) ? content.label : list_name_lookup_cache[content.id].presence || content.name), content %> + <%= link_to (content.respond_to?(:label) ? content.label : list_name_lookup_cache["#{content.page_type}_#{content.id}"].presence || content.name), content %> <% universe_field_value = content.universe_field_value %> <% if universe_field_value.present? %> @@ -77,7 +77,7 @@ <% if user_signed_in? && content.user_id == current_user.id %> <%# todo also show if you're a contributor %> - <%= link_to edit_polymorphic_path(content), class: 'js-edit-hover' do %> + <%= link_to edit_polymorphic_path(content.page_type.downcase, id: content.id), class: 'js-edit-hover' do %> edit <% end %> <% end %> @@ -86,6 +86,7 @@ <% end %> <% if local_assigns[:show_add_another_form] && content_list.any? && current_user.can_create?(content_type) %> + <%# todo real permissions here %> <% if content_type == Character || content_type == Location || content_type == Item || current_user.on_premium_plan? %> <% unless content_type == Universe %> <%= render partial: 'content/list/quick_add_form', locals: { content_type: content_type } %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index c93db901..09deac81 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -60,10 +60,10 @@ %>
- <%= f.check_box :email_updates %> <%= f.label :email_updates do %> - We're always working to improve Notebook.ai. Please leave this box checked if you'd like to receive occasional updates about - what's new. + <%= f.check_box :email_updates %> + We're always working to improve Notebook.ai. Please leave this box checked if you'd like to receive occasional updates about + what's new. <% end %>
diff --git a/app/views/devise/registrations/panes/_preferences.html.erb b/app/views/devise/registrations/panes/_preferences.html.erb index 27f13d0c..7b60ba41 100644 --- a/app/views/devise/registrations/panes/_preferences.html.erb +++ b/app/views/devise/registrations/panes/_preferences.html.erb @@ -2,9 +2,9 @@

Your Notebook.ai design

- <%= f.check_box :fluid_preference %> <%= f.label :fluid_preference do %> - I want to use full-width Notebook.ai. Great for small screens, but not so much for very large ones. + <%= f.check_box :fluid_preference %> + I want to use full-width Notebook.ai. Great for small screens, but not so much for very large ones. <% end %>
@@ -14,9 +14,9 @@

Email preferences

- <%= f.check_box :email_updates %> <%= f.label :email_updates do %> - I want to receive occasional updates by email about new Notebook.ai features. + <%= f.check_box :email_updates %> + I want to receive occasional updates by email about new Notebook.ai features. <% end %>
diff --git a/app/views/devise/sessions/_form.html.erb b/app/views/devise/sessions/_form.html.erb index a97e885e..4712947a 100644 --- a/app/views/devise/sessions/_form.html.erb +++ b/app/views/devise/sessions/_form.html.erb @@ -13,17 +13,21 @@
+
<% if devise_mapping.rememberable? -%> - + <%= f.label :remember_me do %> <%= f.check_box :remember_me %> - <%= f.label :remember_me %> - + Remember me + <% end %> <% end -%> - <%= f.submit "Log in", class: 'btn blue' %> +
+
+ <%= f.submit "Log in", class: 'btn blue' %> +


<%= render "devise/shared/links" %>

-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/layouts/_common_head.html.erb b/app/views/layouts/_common_head.html.erb index 4e1e71bc..3db3f207 100644 --- a/app/views/layouts/_common_head.html.erb +++ b/app/views/layouts/_common_head.html.erb @@ -2,14 +2,14 @@ <%= csrf_meta_tags %> <%= stylesheet_link_tag 'application' %> - + - + diff --git a/app/views/layouts/_sidenav.html.erb b/app/views/layouts/_sidenav.html.erb index a5aadd54..50bcbd0d 100644 --- a/app/views/layouts/_sidenav.html.erb +++ b/app/views/layouts/_sidenav.html.erb @@ -93,7 +93,7 @@ @universe_scope.send(pluralized_name).count else ( - @current_user_content[content_type] + + @current_user_content[content_type] || [] + current_user.send("contributable_#{pluralized_name}") + (content_type_klass == Universe ? [] : content_type_klass.where(universe_id: current_user.universes.pluck(:id))) ).uniq.count diff --git a/app/views/layouts/forum.html.erb b/app/views/layouts/forum.html.erb index d7d94430..822a44cf 100644 --- a/app/views/layouts/forum.html.erb +++ b/app/views/layouts/forum.html.erb @@ -2,14 +2,14 @@ <%= stylesheet_link_tag 'application' %> - + - + <%= render 'layouts/favicon' %> diff --git a/app/views/main/dashboard.html.erb b/app/views/main/dashboard.html.erb index 929b9983..a912adc7 100644 --- a/app/views/main/dashboard.html.erb +++ b/app/views/main/dashboard.html.erb @@ -21,13 +21,8 @@ if @universe_scope.present? && content_type != 'Universe' content_list = @universe_scope.send(pluralized_content_name) else - content_list = @current_user_content[content_type] + + content_list = @current_user_content[content_type] || [] + current_user.send("contributable_#{pluralized_content_name}") - - # todo I don't think this is actually necessary anymore, but leaving around for a few days just in case - # if content_type != 'Universe' - # content_list.concat(content_type.constantize.where(universe_id: current_user_universe_ids)) - # end end content_list = content_list.uniq diff --git a/app/views/universes/_picker.html.erb b/app/views/universes/_picker.html.erb index b4040db4..a3e9e456 100644 --- a/app/views/universes/_picker.html.erb +++ b/app/views/universes/_picker.html.erb @@ -20,7 +20,7 @@
  • <%= link_to "All universes", "?universe=all" %>
  • <% if current_user %>
  • - <% (@current_user_content['Universe'] + current_user.contributable_universes).sort_by(&:name).each do |universe| %> + <% ((@current_user_content['Universe'] || []) + current_user.contributable_universes).sort_by(&:name).each do |universe| %>
  • <%= link_to universe.name + (universe.user_id == current_user.id ? '' : ' (contributor)'), "?universe=#{universe.id}" %>
  • <% end %> <% end %> diff --git a/config/initializers/raygun.rb b/config/initializers/raygun.rb deleted file mode 100644 index 9f8f0498..00000000 --- a/config/initializers/raygun.rb +++ /dev/null @@ -1,7 +0,0 @@ -Raygun.setup do |config| - config.api_key = ENV['RAYGUN_API_KEY'] || '' - config.filter_parameters = Rails.application.config.filter_parameters - - # The default is Rails.env.production? - # config.enable_reporting = !Rails.env.development? && !Rails.env.test? -end diff --git a/config/puma.rb b/config/puma.rb index a41b05bb..c1f291a0 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,5 +1,10 @@ require 'puma/plugin/heroku' +require 'barnes' +before_fork do + Barnes.start +end + workers Integer(ENV['WEB_CONCURRENCY'] || 0) threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5) threads threads_count, threads_count diff --git a/db/migrate/20181017202825_add_page_type_column_to_pages.rb b/db/migrate/20181017202825_add_page_type_column_to_pages.rb new file mode 100644 index 00000000..8db4134b --- /dev/null +++ b/db/migrate/20181017202825_add_page_type_column_to_pages.rb @@ -0,0 +1,23 @@ +class AddPageTypeColumnToPages < ActiveRecord::Migration[5.2] + def change + add_column :universes, :page_type, :string + add_column :characters, :page_type, :string + add_column :countries, :page_type, :string + add_column :creatures, :page_type, :string + add_column :deities, :page_type, :string + add_column :floras, :page_type, :string + add_column :governments, :page_type, :string + add_column :groups, :page_type, :string + add_column :items, :page_type, :string + add_column :landmarks, :page_type, :string + add_column :languages, :page_type, :string + add_column :locations, :page_type, :string + add_column :magics, :page_type, :string + add_column :planets, :page_type, :string + add_column :races, :page_type, :string + add_column :religions, :page_type, :string + add_column :scenes, :page_type, :string + add_column :technologies, :page_type, :string + add_column :towns, :page_type, :string + end +end diff --git a/db/migrate/20181017205546_add_defaults_to_new_page_columns.rb b/db/migrate/20181017205546_add_defaults_to_new_page_columns.rb new file mode 100644 index 00000000..2ebd1a21 --- /dev/null +++ b/db/migrate/20181017205546_add_defaults_to_new_page_columns.rb @@ -0,0 +1,23 @@ +class AddDefaultsToNewPageColumns < ActiveRecord::Migration[5.2] + def change + change_column_default :universes, :page_type, 'Universe' + change_column_default :characters, :page_type, 'Character' + change_column_default :countries, :page_type, 'Country' + change_column_default :creatures, :page_type, 'Creature' + change_column_default :deities, :page_type, 'Deity' + change_column_default :floras, :page_type, 'Flora' + change_column_default :governments, :page_type, 'Government' + change_column_default :groups, :page_type, 'Group' + change_column_default :items, :page_type, 'Item' + change_column_default :landmarks, :page_type, 'Landmark' + change_column_default :languages, :page_type, 'Language' + change_column_default :locations, :page_type, 'Location' + change_column_default :magics, :page_type, 'Magic' + change_column_default :planets, :page_type, 'Planet' + change_column_default :races, :page_type, 'Race' + change_column_default :religions, :page_type, 'Religion' + change_column_default :scenes, :page_type, 'Scene' + change_column_default :technologies, :page_type, 'Technology' + change_column_default :towns, :page_type, 'Town' + end +end diff --git a/db/migrate/20181017224014_create_content_pages.rb b/db/migrate/20181017224014_create_content_pages.rb new file mode 100644 index 00000000..ef8c6111 --- /dev/null +++ b/db/migrate/20181017224014_create_content_pages.rb @@ -0,0 +1,15 @@ +class CreateContentPages < ActiveRecord::Migration[5.2] + def change + create_table :content_pages do |t| + t.string :name + t.string :description + t.references :user, foreign_key: true + t.references :universe, foreign_key: true + t.datetime :deleted_at + t.string :privacy + t.string :page_type + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 06976078..f6a66fc1 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: 2018_10_02_170145) do +ActiveRecord::Schema.define(version: 2018_10_17_224014) do create_table "api_keys", force: :cascade do |t| t.integer "user_id" @@ -269,6 +269,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.string "hobbies" t.string "personality_type" t.datetime "deleted_at" + t.string "page_type", default: "Character" t.index ["deleted_at", "id"], name: "index_characters_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_characters_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_characters_on_deleted_at_and_user_id" @@ -295,6 +296,20 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.index ["user_id"], name: "index_content_change_events_on_user_id" end + create_table "content_pages", force: :cascade do |t| + t.string "name" + t.string "description" + t.integer "user_id" + t.integer "universe_id" + t.datetime "deleted_at" + t.string "privacy" + t.string "page_type" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["universe_id"], name: "index_content_pages_on_universe_id" + t.index ["user_id"], name: "index_content_pages_on_user_id" + end + create_table "contributors", force: :cascade do |t| t.integer "universe_id" t.string "email" @@ -327,6 +342,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.datetime "deleted_at" t.string "privacy" t.integer "user_id" + t.string "page_type", default: "Country" t.index ["deleted_at", "id"], name: "index_countries_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_countries_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_countries_on_deleted_at_and_user_id" @@ -469,6 +485,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.string "family" t.string "genus" t.string "species" + t.string "page_type", default: "Creature" t.index ["deleted_at", "id"], name: "index_creatures_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_creatures_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_creatures_on_deleted_at_and_user_id" @@ -508,6 +525,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.datetime "deleted_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "page_type", default: "Deity" t.index ["deleted_at", "id"], name: "index_deities_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_deities_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_deities_on_deleted_at_and_user_id" @@ -780,6 +798,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.string "privacy" t.datetime "deleted_at" t.string "material_uses" + t.string "page_type", default: "Flora" t.index ["deleted_at", "id"], name: "index_floras_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_floras_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_floras_on_deleted_at_and_user_id" @@ -898,6 +917,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.datetime "deleted_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "page_type", default: "Government" t.index ["deleted_at", "id"], name: "index_governments_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_governments_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_governments_on_deleted_at_and_user_id" @@ -988,6 +1008,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.datetime "updated_at", null: false t.string "privacy" t.datetime "deleted_at" + t.string "page_type", default: "Group" t.index ["deleted_at", "id"], name: "index_groups_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_groups_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_groups_on_deleted_at_and_user_id" @@ -1047,6 +1068,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.datetime "updated_at" t.string "privacy", default: "private", null: false t.datetime "deleted_at" + t.string "page_type", default: "Item" t.index ["deleted_at", "id"], name: "index_items_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_items_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_items_on_deleted_at_and_user_id" @@ -1121,6 +1143,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.datetime "deleted_at" t.string "privacy" t.integer "user_id" + t.string "page_type", default: "Landmark" t.index ["deleted_at", "id"], name: "index_landmarks_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_landmarks_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_landmarks_on_deleted_at_and_user_id" @@ -1147,6 +1170,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.datetime "updated_at", null: false t.string "privacy" t.datetime "deleted_at" + t.string "page_type", default: "Language" t.index ["deleted_at", "id"], name: "index_languages_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_languages_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_languages_on_deleted_at_and_user_id" @@ -1255,6 +1279,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.string "founding_story" t.string "sports" t.datetime "deleted_at" + t.string "page_type", default: "Location" t.index ["deleted_at", "id"], name: "index_locations_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_locations_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_locations_on_deleted_at_and_user_id" @@ -1291,6 +1316,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.datetime "updated_at", null: false t.string "privacy" t.datetime "deleted_at" + t.string "page_type", default: "Magic" t.index ["deleted_at", "id"], name: "index_magics_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_magics_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_magics_on_deleted_at_and_user_id" @@ -1511,6 +1537,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "notes" + t.string "page_type", default: "Planet" t.index ["deleted_at", "id"], name: "index_planets_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_planets_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_planets_on_deleted_at_and_user_id" @@ -1547,6 +1574,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.datetime "updated_at", null: false t.string "privacy" t.datetime "deleted_at" + t.string "page_type", default: "Race" t.index ["deleted_at", "id"], name: "index_races_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_races_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_races_on_deleted_at_and_user_id" @@ -1615,6 +1643,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.datetime "updated_at", null: false t.string "privacy" t.datetime "deleted_at" + t.string "page_type", default: "Religion" t.index ["deleted_at", "id"], name: "index_religions_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_religions_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_religions_on_deleted_at_and_user_id" @@ -1675,6 +1704,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.datetime "updated_at", null: false t.string "privacy" t.datetime "deleted_at" + t.string "page_type", default: "Scene" t.index ["deleted_at", "id"], name: "index_scenes_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_scenes_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_scenes_on_deleted_at_and_user_id" @@ -1758,6 +1788,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.datetime "deleted_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "page_type", default: "Technology" t.index ["deleted_at", "id"], name: "index_technologies_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_technologies_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_technologies_on_deleted_at_and_user_id" @@ -2184,6 +2215,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.datetime "deleted_at" t.string "privacy" t.integer "user_id" + t.string "page_type", default: "Town" t.index ["deleted_at", "id"], name: "index_towns_on_deleted_at_and_id" t.index ["deleted_at", "universe_id"], name: "index_towns_on_deleted_at_and_universe_id" t.index ["deleted_at", "user_id"], name: "index_towns_on_deleted_at_and_user_id" @@ -2206,6 +2238,7 @@ ActiveRecord::Schema.define(version: 2018_10_02_170145) do t.string "technology" t.string "genre" t.datetime "deleted_at" + t.string "page_type", default: "Universe" 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" diff --git a/test/fixtures/content_pages.yml b/test/fixtures/content_pages.yml new file mode 100644 index 00000000..24361b4a --- /dev/null +++ b/test/fixtures/content_pages.yml @@ -0,0 +1,19 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + description: MyString + user: one + universe: one + deleted_at: 2018-10-17 17:40:14 + privacy: MyString + page_type: MyString + +two: + name: MyString + description: MyString + user: two + universe: two + deleted_at: 2018-10-17 17:40:14 + privacy: MyString + page_type: MyString diff --git a/test/models/content_page_test.rb b/test/models/content_page_test.rb new file mode 100644 index 00000000..a798e661 --- /dev/null +++ b/test/models/content_page_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ContentPageTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end