diff --git a/Gemfile b/Gemfile index 92333274c73..8e415c3b503 100644 --- a/Gemfile +++ b/Gemfile @@ -132,7 +132,7 @@ gem "aws-sdk-s3" # Used to resize user images gem "image_processing" -# Used to provide clean urls like /microcosm/mappingdc +# Used to provide clean urls like /community/mappingdc gem "friendly_id" # Gems useful for development diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index 5ec56cae19a..6f4d061fa7b 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -18,7 +18,7 @@ def initialize(user) can :index, ChangesetComment can [:confirm, :confirm_resend, :confirm_email], :confirmation can [:index, :rss, :show, :comments], DiaryEntry - can [:index], MicrocosmLink + can [:index], CommunityLink can [:index], Note can [:lost_password, :reset_password], :password can [:index, :show], Redaction @@ -32,7 +32,7 @@ def initialize(user) can [:history, :version], OldNode can [:history, :version], OldWay can [:history, :version], OldRelation - can [:index, :show], Microcosm + can [:index, :show], Community end if user&.active? @@ -56,9 +56,9 @@ def initialize(user) can [:new, :create], Report can [:mine, :new, :create, :edit, :update, :destroy], Trace can [:account, :go_public], User - can [:create, :new], Microcosm - can [:edit, :update], Microcosm, { :organizer_id => user.id } - can [:edit, :create, :destroy, :new, :update], MicrocosmLink, { :microcosm => { :organizer_id => user.id } } + can [:create, :new], Community + can [:edit, :update], Community, :organizer_id => user.id + can [:edit, :create, :destroy, :new, :update], CommunityLink, :community => { :organizer_id => user.id } if user.moderator? can [:hide, :hidecomment], DiaryEntry diff --git a/app/assets/javascripts/communities.js b/app/assets/javascripts/communities.js new file mode 100644 index 00000000000..42ef8954b26 --- /dev/null +++ b/app/assets/javascripts/communities.js @@ -0,0 +1,10 @@ +/*global showMap,formMapInput*/ + + +$(document).ready(function () { + if ($("#community_map_form").length) { + formMapInput("community_map_form", "community"); + } else if ($("#community_map").length) { + showMap("community_map"); + } +}); diff --git a/app/assets/javascripts/microcosms.js b/app/assets/javascripts/microcosms.js deleted file mode 100644 index ccd587a62f1..00000000000 --- a/app/assets/javascripts/microcosms.js +++ /dev/null @@ -1,10 +0,0 @@ -/*global showMap,formMapInput*/ - - -$(document).ready(function () { - if ($("#microcosm_map_form").length) { - formMapInput("microcosm_map_form", "microcosm"); - } else if ($("#microcosm_map").length) { - showMap("microcosm_map"); - } -}); diff --git a/app/assets/stylesheets/microcosms.scss b/app/assets/stylesheets/communities.scss similarity index 63% rename from app/assets/stylesheets/microcosms.scss rename to app/assets/stylesheets/communities.scss index 00da4e4fcd6..367b97dbdb7 100644 --- a/app/assets/stylesheets/microcosms.scss +++ b/app/assets/stylesheets/communities.scss @@ -1,8 +1,8 @@ -// Place all the styles related to the Microcosms controller here. +// Place all the styles related to the Communities controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: https://sass-lang.com/ -.mic_details { +.community_details { label { font-weight: bold; } diff --git a/app/controllers/microcosms_controller.rb b/app/controllers/communities_controller.rb similarity index 68% rename from app/controllers/microcosms_controller.rb rename to app/controllers/communities_controller.rb index 241bb6cc444..cc0c3b4ebd4 100644 --- a/app/controllers/microcosms_controller.rb +++ b/app/controllers/communities_controller.rb @@ -1,8 +1,8 @@ -class MicrocosmsController < ApplicationController +class CommunitiesController < ApplicationController layout "site" before_action :authorize_web - before_action :set_microcosm, :only => [:edit, :show, :update] + before_action :set_community, :only => [:edit, :show, :update] helper_method :recent_changesets @@ -15,44 +15,44 @@ def index @user = User.active.where(:display_name => display_name).first if @user @title = t ".title", :display_name => @user.display_name - @microcosms_organized = @user.microcosms_organized + @communities_organized = @user.communities_organized else render_unknown_user display_name return end elsif current_user @title = t ".title", :display_name => current_user.display_name - @microcosms_organized = current_user.microcosms_organized + @communities_organized = current_user.communities_organized end # Using Arel.sql here because we're using known-safe values. - @all_microcosms = Microcosm.order(Arel.sql(sunniest_communities)) + @all_communities = Community.order(Arel.sql(sunniest_communities)) end - # GET /microcosms/mycity - # GET /microcosms/mycity.json + # GET /communities/mycity + # GET /communities/mycity.json def show; end def new @title = t ".title" - @microcosm = Microcosm.new + @community = Community.new end def edit; end def create - @microcosm = Microcosm.new(microcosm_params) - @microcosm.organizer = current_user - if @microcosm.save - redirect_to @microcosm, :notice => t(".success") + @community = Community.new(community_params) + @community.organizer = current_user + if @community.save + redirect_to @community, :notice => t(".success") else render "new" end end def update - if @microcosm.update(microcosm_params) - redirect_to @microcosm, :notice => t(".success") + if @community.update(community_params) + redirect_to @community, :notice => t(".success") else flash.now[:alert] = t(".failure") render :edit @@ -62,7 +62,7 @@ def update private def recent_changesets - bbox = @microcosm.bbox.to_scaled + bbox = @community.bbox.to_scaled Changeset .where("min_lon < ? and max_lon > ? and min_lat < ? and max_lat > ?", bbox.max_lon.to_i, bbox.min_lon.to_i, bbox.max_lat.to_i, bbox.min_lat.to_i) @@ -70,7 +70,7 @@ def recent_changesets end ## - # Build an ORDER BY clause that sorts microcosms such that the ones + # Build an ORDER BY clause that sorts communities such that the ones # getting the most sunlight are ranked highest. These are the groups # where people are awake and mapping. # @@ -81,19 +81,19 @@ def sunniest_communities minute_of_day = "(60 * EXTRACT(HOUR FROM current_timestamp) + EXTRACT(MINUTE FROM current_timestamp))::numeric" # longitude facing the sun lfts = "((#{brightest_minute_of_day} - #{minute_of_day}) / 4)" - # find shortest span between lfts and the microcosm longitude + # find shortest span between lfts and the community longitude # pg doesn't have mod for floats, so convert to numeric clockwise_delta = "((#{lfts} - longitude::numeric + 360) % 360)" anticlockwise_delta = "((longitude::numeric - #{lfts} + 360) % 360)" "least(#{clockwise_delta}, #{anticlockwise_delta})" end - def set_microcosm - @microcosm = Microcosm.friendly.find(params[:id]) + def set_community + @community = Community.friendly.find(params[:id]) end - def microcosm_params - params.require(:microcosm).permit( + def community_params + params.require(:community).permit( :name, :location, :latitude, :longitude, :min_lat, :max_lat, :min_lon, :max_lon, :description diff --git a/app/controllers/community_links_controller.rb b/app/controllers/community_links_controller.rb new file mode 100644 index 00000000000..87874ec55ab --- /dev/null +++ b/app/controllers/community_links_controller.rb @@ -0,0 +1,61 @@ +class CommunityLinksController < ApplicationController + layout "site" + before_action :authorize_web + + before_action :set_link, :only => [:destroy, :edit, :update] + + load_and_authorize_resource :except => [:create, :new] + authorize_resource + + def index + @community = Community.friendly.find(params[:community_id]) + @links = @community.community_links + end + + def new + return "missing parameter community_id" unless params.key?(:community_id) + + @community = Community.friendly.find(params[:community_id]) + @title = t ".title" + @link = CommunityLink.new + @link.community_id = params[:community_id] + end + + def edit; end + + def create + @community = Community.friendly.find(params[:community_id]) + @link = @community.community_links.build(link_params) + if @link.save + response.set_header("link_id", @link.id) # for testing + redirect_to @link.community, :notice => t(".success") + else + render "new" + end + end + + def update + if @link.update(link_params) + redirect_to @link.community, :notice => t(".success") + else + flash.now[:alert] = t(".failure") + render :edit + end + end + + def destroy + community_id = @link.community_id + @link.delete + redirect_to community_path(community_id) + end + + private + + def set_link + @link = CommunityLink.find(params[:id]) + end + + def link_params + params.require(:community_link).permit(:community_id, :site, :url) + end +end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 6a95926377b..ab229aa176f 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -14,7 +14,7 @@ def index @title = t ".title" @issue_types = [] - @issue_types.push("Microcosm", "Note") if current_user.moderator? + @issue_types.push("Community", "Note") if current_user.moderator? @issue_types.push("DiaryEntry", "DiaryComment", "User") if current_user.administrator? @users = User.joins(:roles).where(:user_roles => { :role => current_user.roles.map(&:role) }).distinct diff --git a/app/controllers/microcosm_links_controller.rb b/app/controllers/microcosm_links_controller.rb deleted file mode 100644 index 97c0796935b..00000000000 --- a/app/controllers/microcosm_links_controller.rb +++ /dev/null @@ -1,61 +0,0 @@ -class MicrocosmLinksController < ApplicationController - layout "site" - before_action :authorize_web - - before_action :set_link, :only => [:destroy, :edit, :update] - - load_and_authorize_resource :except => [:create, :new] - authorize_resource - - def index - @microcosm = Microcosm.friendly.find(params[:microcosm_id]) - @links = @microcosm.microcosm_links - end - - def new - return "missing parameter microcosm_id" unless params.key?(:microcosm_id) - - @microcosm = Microcosm.friendly.find(params[:microcosm_id]) - @title = t ".title" - @link = MicrocosmLink.new - @link.microcosm_id = params[:microcosm_id] - end - - def edit; end - - def create - @microcosm = Microcosm.friendly.find(params[:microcosm_id]) - @link = @microcosm.microcosm_links.build(link_params) - if @link.save - response.set_header("link_id", @link.id) # for testing - redirect_to @link.microcosm, :notice => t(".success") - else - render "new" - end - end - - def update - if @link.update(link_params) - redirect_to @link.microcosm, :notice => t(".success") - else - flash.now[:alert] = t(".failure") - render :edit - end - end - - def destroy - microcosm_id = @link.microcosm_id - @link.delete - redirect_to microcosm_path(microcosm_id) - end - - private - - def set_link - @link = MicrocosmLink.find(params[:id]) - end - - def link_params - params.require(:microcosm_link).permit(:microcosm_id, :site, :url) - end -end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 28021548266..0c96515ac5a 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -56,7 +56,7 @@ def issue_params def default_assigned_role case issue_params[:reportable_type] - when "Microcosm", "Note" + when "Community", "Note" "moderator" when "User" case report_params[:category] diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index d8c2092f962..29236dfeae1 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -7,8 +7,8 @@ def reportable_url(reportable) user_url(reportable) when DiaryComment diary_entry_url(reportable.diary_entry.user, reportable.diary_entry, :anchor => "comment#{reportable.id}") - when Microcosm - microcosm_url(reportable) + when Community + community_url(reportable) when Note note_url(reportable) end @@ -22,7 +22,7 @@ def reportable_title(reportable) reportable.display_name when DiaryComment I18n.t("issues.helper.reportable_title.diary_comment", :entry_title => reportable.diary_entry.title, :comment_id => reportable.id) - when Microcosm + when Community reportable.name when Note I18n.t("issues.helper.reportable_title.note", :note_id => reportable.id) diff --git a/app/models/microcosm.rb b/app/models/community.rb similarity index 90% rename from app/models/microcosm.rb rename to app/models/community.rb index 262fea548ee..a76864c51b4 100644 --- a/app/models/microcosm.rb +++ b/app/models/community.rb @@ -1,6 +1,6 @@ # == Schema Information # -# Table name: microcosms +# Table name: communities # # id :bigint(8) not null, primary key # name :string not null @@ -17,15 +17,15 @@ # created_at :datetime not null # updated_at :datetime not null # -# At this time a microcosm has one organizer. The first organizer is -# the user that created the microcosm. +# At this time a community has one organizer. The first organizer is +# the user that created the community. -class Microcosm < ApplicationRecord +class Community < ApplicationRecord extend FriendlyId friendly_id :name, :use => :slugged belongs_to :organizer, :class_name => "User" - has_many :microcosm_links + has_many :community_links validates :name, :presence => true, :length => 1..255, :characters => true validates :description, :presence => true, :length => 1..1023, :characters => true diff --git a/app/models/microcosm_link.rb b/app/models/community_link.rb similarity index 69% rename from app/models/microcosm_link.rb rename to app/models/community_link.rb index 5d0c9a1a106..95e7f1bba9b 100644 --- a/app/models/microcosm_link.rb +++ b/app/models/community_link.rb @@ -1,9 +1,9 @@ # == Schema Information # -# Table name: microcosm_links +# Table name: community_links # # id :bigint(8) not null, primary key -# microcosm_id :integer not null +# community_id :integer not null # site :string not null # url :string not null # created_at :datetime not null @@ -11,11 +11,11 @@ # # Indexes # -# index_microcosm_links_on_microcosm_id (microcosm_id) +# index_community_links_on_community_id (community_id) # -class MicrocosmLink < ApplicationRecord - belongs_to :microcosm +class CommunityLink < ApplicationRecord + belongs_to :community validates :site, :presence => true, :length => 1..255, :characters => true validates :url, :presence => true, :length => 1..255, :url => { :schemes => ["https"] } end diff --git a/app/models/issue.rb b/app/models/issue.rb index ee8daf67243..86732984979 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -86,7 +86,7 @@ def set_reported_user self.reported_user = case reportable.class.name when "User" reportable - when "Microcosm" + when "Community" reportable.organizer when "Note" reportable.author diff --git a/app/models/report.rb b/app/models/report.rb index 7d95a9a3977..d9babd0500c 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -31,7 +31,7 @@ class Report < ApplicationRecord def self.categories_for(reportable) case reportable.class.name when "DiaryEntry", "DiaryComment" then %w[spam offensive threat other] - when "Microcosm" then %w[spam offensive other] + when "Community" then %w[spam offensive other] when "User" then %w[spam offensive threat vandal other] when "Note" then %w[spam personal abusive other] else %w[other] diff --git a/app/models/user.rb b/app/models/user.rb index a4b3ea6f5ac..1bf54ef77dc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -83,7 +83,7 @@ class User < ApplicationRecord has_many :reports - has_many :microcosms_organized, :class_name => "Microcosm", :foreign_key => :organizer_id, :inverse_of => :organizer + has_many :communities_organized, :class_name => "Community", :foreign_key => :organizer_id, :inverse_of => :organizer scope :visible, -> { where(:status => %w[pending active confirmed]) } scope :active, -> { where(:status => %w[active confirmed]) } diff --git a/app/views/microcosms/_form.html.erb b/app/views/communities/_form.html.erb similarity index 51% rename from app/views/microcosms/_form.html.erb rename to app/views/communities/_form.html.erb index 5af06ce77ff..e21cf5335ca 100644 --- a/app/views/microcosms/_form.html.erb +++ b/app/views/communities/_form.html.erb @@ -1,33 +1,30 @@ -<%= stylesheet_link_tag "microcosms" %> -<%= javascript_include_tag "microcosms" %> +<%= stylesheet_link_tag "communities" %> +<%= javascript_include_tag "communities" %> -

- All fields are required. -

-<%= bootstrap_form_for @microcosm do |form| %> - <%= form.text_field :name, :id => :microcosm_name %> - <%= form.text_field :location, :id => :microcosm_location %> +<%= bootstrap_form_for @community do |form| %> + <%= form.text_field :name, :id => :community_name %> + <%= form.text_field :location, :id => :community_location %>
- <%= form.text_field :latitude, :wrapper_class => "col-sm-6", :id => :microcosm_latitude %> - <%= form.text_field :longitude, :wrapper_class => "col-sm-6", :id => :microcosm_longitude %> + <%= form.text_field :latitude, :wrapper_class => "col-sm-6", :id => :community_latitude %> + <%= form.text_field :longitude, :wrapper_class => "col-sm-6", :id => :community_longitude %>
-
-
+
+
- <%= form.text_field :max_lat, :wrapper_class => "col-sm-4", :id => :microcosm_max_lat %> + <%= form.text_field :max_lat, :wrapper_class => "col-sm-4", :id => :community_max_lat %>
- <%= form.text_field :min_lon, :wrapper_class => "col-sm-4", :id => :microcosm_min_lon %> + <%= form.text_field :min_lon, :wrapper_class => "col-sm-4", :id => :community_min_lon %>
- <%= form.text_field :max_lon, :wrapper_class => "col-sm-4", :id => :microcosm_max_lon %> + <%= form.text_field :max_lon, :wrapper_class => "col-sm-4", :id => :community_max_lon %>
- <%= form.text_field :min_lat, :wrapper_class => "col-sm-4", :id => :microcosm_min_lat %> + <%= form.text_field :min_lat, :wrapper_class => "col-sm-4", :id => :community_min_lat %>
- <%= form.text_area :description, :id => :microcosm_description %> + <%= form.text_area :description, :id => :community_description %> <%= form.primary %> <% end %> diff --git a/app/views/microcosms/_index_list.html.erb b/app/views/communities/_index_list.html.erb similarity index 54% rename from app/views/microcosms/_index_list.html.erb rename to app/views/communities/_index_list.html.erb index d555a31a054..dca28e37064 100644 --- a/app/views/microcosms/_index_list.html.erb +++ b/app/views/communities/_index_list.html.erb @@ -1,21 +1,21 @@ -<% if !microcosms.empty? %> +<% if !communities.empty? %>

<%= header %>

- <% microcosms.each do |microcosm| %> + <% communities.each do |community| %> diff --git a/app/views/communities/edit.html.erb b/app/views/communities/edit.html.erb new file mode 100644 index 00000000000..9964fc500a2 --- /dev/null +++ b/app/views/communities/edit.html.erb @@ -0,0 +1,3 @@ +

<%= t(".edit_community") %>

+ +<%= render "form", :community => @community %> diff --git a/app/views/communities/index.html.erb b/app/views/communities/index.html.erb new file mode 100644 index 00000000000..e2f1b7ba321 --- /dev/null +++ b/app/views/communities/index.html.erb @@ -0,0 +1,18 @@ +<% content_for :heading do %> +

<%= t(".title") %>

+ +<% end %> + +<% if @communities_organized %> + <%= render :partial => "index_list", :locals => { :communities => @communities_organized, :header => t(".communities_organized") } %> +<% end %> + +

+ <%= t(".sorted_by") %> +

+ +<%= render :partial => "index_list", :locals => { :communities => @all_communities, :header => t(".all") } %> diff --git a/app/views/microcosms/new.html.erb b/app/views/communities/new.html.erb similarity index 58% rename from app/views/microcosms/new.html.erb rename to app/views/communities/new.html.erb index 5469d3b8a6f..f948ff9a7b8 100644 --- a/app/views/microcosms/new.html.erb +++ b/app/views/communities/new.html.erb @@ -2,4 +2,4 @@

<%= @title %>

<% end %> -<%= render "form", :microcosm => @microcosm %> +<%= render "form", :community => @community %> diff --git a/app/views/microcosms/show.html.erb b/app/views/communities/show.html.erb similarity index 61% rename from app/views/microcosms/show.html.erb rename to app/views/communities/show.html.erb index 475855b4db6..86b3ac26569 100644 --- a/app/views/microcosms/show.html.erb +++ b/app/views/communities/show.html.erb @@ -1,14 +1,14 @@ -<%= stylesheet_link_tag "microcosms" %> -<%= javascript_include_tag "microcosms" %> +<%= stylesheet_link_tag "communities" %> +<%= javascript_include_tag "communities" %> <% content_for :heading do %>

- <%= "#{@microcosm.name} " + t(".header_title") %> + <%= "#{@community.name} " + t(".header_title") %>

<% if current_user %> - <%= report_link(t(".report"), @microcosm) %> - <% if current_user == @microcosm.organizer %> - <%= link_to t(".edit"), edit_microcosm_path(@microcosm) %> + <%= report_link(t(".report"), @community) %> + <% if current_user == @community.organizer %> + <%= link_to t(".edit"), edit_community_path(@community) %> <% end %> <% end %> <% end %> @@ -17,28 +17,28 @@
<%# TODO: replace these attributes @map_coords %> - <%= tag.div :id => "microcosm_map", :class => "content_map", :data => { :lat => @microcosm.latitude, :lon => @microcosm.longitude, :zoom => 11 } %> + <%= tag.div :id => "community_map", :class => "content_map", :data => { :lat => @community.latitude, :lon => @community.longitude, :zoom => 11 } %>
-
+

- <%= link_to @microcosm.name, @microcosm %> + <%= link_to @community.name, @community %>

- <%= @microcosm.location %>, <%= @microcosm.latitude %>, <%= @microcosm.longitude %> + <%= @community.location %>, <%= @community.latitude %>, <%= @community.longitude %>

- <%= auto_link @microcosm.description %> + <%= auto_link @community.description %>

- <%= link_to @microcosm.organizer.display_name, user_path(@microcosm.organizer) %> + <%= link_to @community.organizer.display_name, user_path(@community.organizer) %>
    - <% @microcosm.microcosm_links.each do |link| %> + <% @community.community_links.each do |link| %>
  • <%= link.site %>
  • diff --git a/app/views/microcosm_links/_form.html.erb b/app/views/community_links/_form.html.erb similarity index 62% rename from app/views/microcosm_links/_form.html.erb rename to app/views/community_links/_form.html.erb index b739d64bfd6..97f8ec220ac 100644 --- a/app/views/microcosm_links/_form.html.erb +++ b/app/views/community_links/_form.html.erb @@ -1,4 +1,4 @@ -<%= bootstrap_form_for [@microcosm, @link] do |form| %> +<%= bootstrap_form_for [@community, @link] do |form| %> <%= form.text_field :site %> <%= form.text_field :url %> <%= form.primary %> diff --git a/app/views/community_links/edit.html.erb b/app/views/community_links/edit.html.erb new file mode 100644 index 00000000000..f2d508679a4 --- /dev/null +++ b/app/views/community_links/edit.html.erb @@ -0,0 +1,3 @@ +

    <%= t(".edit_community_link") %>

    + +<%= render "form", :link => @link %> diff --git a/app/views/microcosm_links/index.html.erb b/app/views/community_links/index.html.erb similarity index 74% rename from app/views/microcosm_links/index.html.erb rename to app/views/community_links/index.html.erb index 63bd12f926c..f2941ca60ff 100644 --- a/app/views/microcosm_links/index.html.erb +++ b/app/views/community_links/index.html.erb @@ -2,7 +2,7 @@

    <%= t(".title") %>

    <% end %> @@ -17,8 +17,8 @@ <%= link_to link.site, "https://#{link.url}" %>
<% end %> diff --git a/app/views/microcosm_links/new.html.erb b/app/views/community_links/new.html.erb similarity index 100% rename from app/views/microcosm_links/new.html.erb rename to app/views/community_links/new.html.erb diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index de2a46ed92f..8b741b28c1d 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -44,8 +44,8 @@ <% end -%> <% end %> - <% end %> -
  • <%= link_to t("layouts.microcosms"), microcosms_path, :class => "dropdown-item" %>
  • +
  • <%= link_to t("layouts.communities"), communities_path, :class => "dropdown-item" %>
  • <%= link_to t("layouts.gps_traces"), traces_path, :class => "dropdown-item" %>
  • <%= link_to t("layouts.user_diaries"), diary_entries_path, :class => "dropdown-item" %>
  • <%= link_to t("layouts.communities"), community_index_path, :class => "dropdown-item" %>
  • diff --git a/app/views/microcosm_links/edit.html.erb b/app/views/microcosm_links/edit.html.erb deleted file mode 100644 index 0a01e19b627..00000000000 --- a/app/views/microcosm_links/edit.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -

    <%= t(".edit_microcosm_link") %>

    - -<%= render "form", :link => @link %> diff --git a/app/views/microcosms/edit.html.erb b/app/views/microcosms/edit.html.erb deleted file mode 100644 index 43953e43b52..00000000000 --- a/app/views/microcosms/edit.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -

    <%= t(".edit_microcosm") %>

    - -<%= render "form", :microcosm => @microcosm %> diff --git a/app/views/microcosms/index.html.erb b/app/views/microcosms/index.html.erb deleted file mode 100644 index c2d2c8d3508..00000000000 --- a/app/views/microcosms/index.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -<% content_for :heading do %> -

    <%= t(".title") %>

    - -<% end %> - -<% if @microcosms_organized %> - <%= render :partial => "index_list", :locals => { :microcosms => @microcosms_organized, :header => t(".microcosms_organized") } %> -<% end %> - -

    - <%= t(".sorted_by") %> -

    - -<%= render :partial => "index_list", :locals => { :microcosms => @all_microcosms, :header => t(".all") } %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 549d092e9a2..ceffb4a504d 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -17,7 +17,7 @@ <%= link_to t(".my notes"), user_notes_path(@user) %>
  • - <%= link_to t(".my microcosms"), user_microcosms_path(@user) %> + <%= link_to t(".my communities"), user_communities_path(@user) %>
  • <%= link_to t(".my traces"), :controller => "traces", :action => "mine" %> @@ -64,7 +64,7 @@ <%= link_to t(".notes"), user_notes_path(@user) %>
  • - <%= link_to t(".microcosms"), user_microcosms_path(@user) %> + <%= link_to t(".communities"), user_communities_path(@user) %>
  • <%= link_to t(".traces"), :controller => "traces", :action => "index", :display_name => @user.display_name %> diff --git a/config/locales/en.yml b/config/locales/en.yml index a36f1f419ae..5440d342071 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -9,7 +9,7 @@ en: file: prompt: Choose file label: - microcosm: + community: description: "Description" lat: "Latitude" location: "Location" @@ -20,6 +20,9 @@ en: min_lon: "Minimum Longitude" name: "Name" submit: + community: + create: "Create Community" + update: "Update Community" diary_comment: create: Comment diary_entry: @@ -35,9 +38,6 @@ en: oauth2_application: create: Register update: Update - microcosm: - create: "Create Microcosm" - update: "Update Microcosm" redaction: create: Create redaction update: Save redaction @@ -160,10 +160,7 @@ en: pass_crypt: "Password" pass_crypt_confirmation: "Confirm Password" help: - doorkeeper/application: - confidential: "Application will be used where the client secret can be kept confidential (native mobile apps and single page apps are not confidential)" - redirect_uri: "Use one line per URI" - microcosm: + community: latitude: decimal location: for example city name and country longitude: decimal @@ -171,6 +168,9 @@ en: max_lon: decimal min_lat: decimal min_lon: decimal + doorkeeper/application: + confidential: "Application will be used where the client secret can be kept confidential (native mobile apps and single page apps are not confidential)" + redirect_uri: "Use one line per URI" trace: tagstring: comma delimited user_block: @@ -480,6 +480,48 @@ en: title_particular: "OpenStreetMap changeset #%{changeset_id} discussion" timeout: sorry: "Sorry, the list of changeset comments you requested took too long to retrieve." + community_links: + create: + success: "Community Link was successfully created." + edit: + edit_community_link: "Edit Community Link" + index: + delete: "Delete" + edit: "Edit" + new: "New" + title: "Community Links" + new: + all: "All" + title: "New Community Link" + update: + failure: "The community link could not be updated." + success: "The community link was successfully updated." + communities: + create: + success: "Community was successfully created." + edit: + edit_community: "Edit Community" + index: + all: "All Communities" + longitude: "Longitude" + communities_organized: "Communities Organized" + new: "New" + new_title: "Create a new community" + sorted_by: "Sorted by longitude and time of day." + title: "Communities" + new: + title: "New Community" + show: + edit: "Edit" + header_title: "Community" + links: "Links" + organizer: "Organizer" + recent_changes: "Recent Changes" + report: "Report" + review_requested: "review requested" + update: + failure: "The community could not be updated." + success: "The community was successfully updated." dashboards: contact: km away: "%{count}km away" @@ -1470,6 +1512,10 @@ en: unable_to_fix: You are unable to fix the problem yourself or with the help of your fellow community members resolve_with_user: You have already tried to resolve the problem with the user concerned categories: + community: + spam_label: The community is/contains spam + offensive_label: This community entry is obscene/offensive + other_label: Other diary_entry: spam_label: This diary entry is/contains spam offensive_label: This diary entry is obscene/offensive @@ -1480,10 +1526,6 @@ en: offensive_label: This diary comment is obscene/offensive threat_label: This diary comment contains a threat other_label: Other - microcosm: - spam_label: The microcosm is/contains spam - offensive_label: This microcosm entry is obscene/offensive - other_label: Other user: spam_label: This user profile is/contains spam offensive_label: This user profile is obscene/offensive @@ -1509,7 +1551,6 @@ en: home: Go to Home Location logout: Log Out log_in: Log In - microcosms: Microcosms sign_up: Sign Up start_mapping: Start Mapping edit: Edit @@ -1548,48 +1589,6 @@ en: text: Make a Donation learn_more: "Learn More" more: More - microcosm_links: - create: - success: "Microcosm Link was successfully created." - edit: - edit_microcosm_link: "Edit Microcosm Link" - index: - delete: "Delete" - edit: "Edit" - new: "New" - title: "Microcosm Links" - new: - all: "All" - title: "New Microcosm Link" - update: - failure: "The microcosm link could not be updated." - success: "The microcosm link was successfully updated." - microcosms: - create: - success: "Microcosm was successfully created." - edit: - edit_microcosm: "Edit Microcosm" - index: - all: "All Microcosms" - longitude: "Longitude" - microcosms_organized: "Microcosms Organized" - new: "New" - new_title: "Create a new microcosm" - sorted_by: "Sorted by longitude and time of day." - title: "Microcosms" - new: - title: "New Microcosm" - show: - edit: "Edit" - header_title: "Microcosm" - links: "Links" - organizer: "Organizer" - recent_changes: "Recent Changes" - report: "Report" - review_requested: "review requested" - update: - failure: "The microcosm could not be updated." - success: "The microcosm was successfully updated." user_mailer: diary_comment_notification: subject: "[OpenStreetMap] %{user} commented on a diary entry" @@ -2734,12 +2733,13 @@ en: body: "Sorry, there is no user with the name %{user}. Please check your spelling, or maybe the link you clicked is wrong." deleted: "deleted" show: + communities: Communities + my communities: My Communities my diary: My Diary my edits: My Edits my traces: My Traces my notes: My Notes my messages: My Messages - my microcosms: My Microcosms my profile: My Profile my settings: My Settings my comments: My Comments @@ -2752,7 +2752,6 @@ en: diary: Diary edits: Edits traces: Traces - microcosms: Microcosms notes: Map Notes remove as friend: Unfriend add as friend: Add Friend diff --git a/config/routes.rb b/config/routes.rb index 4d033d65e93..e2b101020fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -323,14 +323,14 @@ # user nested resources resources :users, :path => "user", :param => :display_name do - resources :microcosms, :only => [:index] + resources :communities, :only => [:index] end - # microcosms - resources :microcosms do - resources :microcosm_links, :only => [:create, :index, :new] + # communities + resources :communities do + resources :community_links, :only => [:create, :index, :new] end - resources :microcosm_links, :only => [:destroy, :edit, :update] + resources :community_links, :only => [:destroy, :edit, :update] # errors match "/403", :to => "errors#forbidden", :via => :all diff --git a/db/migrate/20210517030520_create_microcosms.rb b/db/migrate/20210517030520_create_communities.rb similarity index 86% rename from db/migrate/20210517030520_create_microcosms.rb rename to db/migrate/20210517030520_create_communities.rb index 7071afa4800..7b0e3d3a4af 100644 --- a/db/migrate/20210517030520_create_microcosms.rb +++ b/db/migrate/20210517030520_create_communities.rb @@ -1,6 +1,6 @@ -class CreateMicrocosms < ActiveRecord::Migration[5.2] +class CreateCommunities < ActiveRecord::Migration[5.2] def change - create_table :microcosms do |t| + create_table :communities do |t| t.string :name, :null => false t.text :description, :null => false t.references :organizer, :null => false, :foreign_key => { :to_table => :users } diff --git a/db/migrate/20220821143545_create_community_links.rb b/db/migrate/20220821143545_create_community_links.rb new file mode 100644 index 00000000000..9fed2274f42 --- /dev/null +++ b/db/migrate/20220821143545_create_community_links.rb @@ -0,0 +1,11 @@ +class CreateCommunityLinks < ActiveRecord::Migration[7.0] + def change + create_table :community_links do |t| + t.references :community, :null => false, :foreign_key => true, :index => true + t.string :site, :null => false + t.string :url, :null => false + + t.timestamps + end + end +end diff --git a/db/migrate/20220821143545_create_microcosm_links.rb b/db/migrate/20220821143545_create_microcosm_links.rb deleted file mode 100644 index b4436415950..00000000000 --- a/db/migrate/20220821143545_create_microcosm_links.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateMicrocosmLinks < ActiveRecord::Migration[7.0] - def change - create_table :microcosm_links do |t| - t.references :microcosm, :null => false, :foreign_key => true, :index => true - t.string :site, :null => false - t.string :url, :null => false - - t.timestamps - end - end -end diff --git a/db/structure.sql b/db/structure.sql index 09378f87e2c..275a5db83f2 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -391,6 +391,80 @@ CREATE SEQUENCE public.client_applications_id_seq ALTER SEQUENCE public.client_applications_id_seq OWNED BY public.client_applications.id; +-- +-- Name: communities; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.communities ( + id bigint NOT NULL, + name character varying NOT NULL, + description text NOT NULL, + organizer_id bigint NOT NULL, + slug character varying NOT NULL, + location character varying NOT NULL, + latitude double precision NOT NULL, + longitude double precision NOT NULL, + min_lat double precision NOT NULL, + max_lat double precision NOT NULL, + min_lon double precision NOT NULL, + max_lon double precision NOT NULL, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL +); + + +-- +-- Name: communities_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.communities_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: communities_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.communities_id_seq OWNED BY public.communities.id; + + +-- +-- Name: community_links; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.community_links ( + id bigint NOT NULL, + community_id bigint NOT NULL, + site character varying NOT NULL, + url character varying NOT NULL, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: community_links_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.community_links_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: community_links_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.community_links_id_seq OWNED BY public.community_links.id; + + -- -- Name: current_node_tags; Type: TABLE; Schema: public; Owner: - -- @@ -938,80 +1012,6 @@ CREATE SEQUENCE public.messages_id_seq ALTER SEQUENCE public.messages_id_seq OWNED BY public.messages.id; --- --- Name: microcosm_links; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.microcosm_links ( - id bigint NOT NULL, - microcosm_id bigint NOT NULL, - site character varying NOT NULL, - url character varying NOT NULL, - created_at timestamp(6) without time zone NOT NULL, - updated_at timestamp(6) without time zone NOT NULL -); - - --- --- Name: microcosm_links_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.microcosm_links_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: microcosm_links_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.microcosm_links_id_seq OWNED BY public.microcosm_links.id; - - --- --- Name: microcosms; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.microcosms ( - id bigint NOT NULL, - name character varying NOT NULL, - description text NOT NULL, - organizer_id bigint NOT NULL, - slug character varying NOT NULL, - location character varying NOT NULL, - latitude double precision NOT NULL, - longitude double precision NOT NULL, - min_lat double precision NOT NULL, - max_lat double precision NOT NULL, - min_lon double precision NOT NULL, - max_lon double precision NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL -); - - --- --- Name: microcosms_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.microcosms_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: microcosms_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.microcosms_id_seq OWNED BY public.microcosms.id; - - -- -- Name: node_tags; Type: TABLE; Schema: public; Owner: - -- @@ -1685,6 +1685,20 @@ ALTER TABLE ONLY public.changesets ALTER COLUMN id SET DEFAULT nextval('public.c ALTER TABLE ONLY public.client_applications ALTER COLUMN id SET DEFAULT nextval('public.client_applications_id_seq'::regclass); +-- +-- Name: communities id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.communities ALTER COLUMN id SET DEFAULT nextval('public.communities_id_seq'::regclass); + + +-- +-- Name: community_links id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.community_links ALTER COLUMN id SET DEFAULT nextval('public.community_links_id_seq'::regclass); + + -- -- Name: current_nodes id; Type: DEFAULT; Schema: public; Owner: - -- @@ -1776,20 +1790,6 @@ ALTER TABLE ONLY public.issues ALTER COLUMN id SET DEFAULT nextval('public.issue ALTER TABLE ONLY public.messages ALTER COLUMN id SET DEFAULT nextval('public.messages_id_seq'::regclass); --- --- Name: microcosm_links id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.microcosm_links ALTER COLUMN id SET DEFAULT nextval('public.microcosm_links_id_seq'::regclass); - - --- --- Name: microcosms id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.microcosms ALTER COLUMN id SET DEFAULT nextval('public.microcosms_id_seq'::regclass); - - -- -- Name: note_comments id; Type: DEFAULT; Schema: public; Owner: - -- @@ -1945,6 +1945,22 @@ ALTER TABLE ONLY public.client_applications ADD CONSTRAINT client_applications_pkey PRIMARY KEY (id); +-- +-- Name: communities communities_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.communities + ADD CONSTRAINT communities_pkey PRIMARY KEY (id); + + +-- +-- Name: community_links community_links_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.community_links + ADD CONSTRAINT community_links_pkey PRIMARY KEY (id); + + -- -- Name: current_node_tags current_node_tags_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -2105,22 +2121,6 @@ ALTER TABLE ONLY public.messages ADD CONSTRAINT messages_pkey PRIMARY KEY (id); --- --- Name: microcosm_links microcosm_links_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.microcosm_links - ADD CONSTRAINT microcosm_links_pkey PRIMARY KEY (id); - - --- --- Name: microcosms microcosms_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.microcosms - ADD CONSTRAINT microcosms_pkey PRIMARY KEY (id); - - -- -- Name: node_tags node_tags_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -2564,6 +2564,27 @@ CREATE UNIQUE INDEX index_client_applications_on_key ON public.client_applicatio CREATE INDEX index_client_applications_on_user_id ON public.client_applications USING btree (user_id); +-- +-- Name: index_communities_on_organizer_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_communities_on_organizer_id ON public.communities USING btree (organizer_id); + + +-- +-- Name: index_communities_on_slug; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_communities_on_slug ON public.communities USING btree (slug); + + +-- +-- Name: index_community_links_on_community_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_community_links_on_community_id ON public.community_links USING btree (community_id); + + -- -- Name: index_diary_entry_subscriptions_on_diary_entry_id; Type: INDEX; Schema: public; Owner: - -- @@ -2648,27 +2669,6 @@ CREATE INDEX index_issues_on_status ON public.issues USING btree (status); CREATE INDEX index_issues_on_updated_by ON public.issues USING btree (updated_by); --- --- Name: index_microcosm_links_on_microcosm_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_microcosm_links_on_microcosm_id ON public.microcosm_links USING btree (microcosm_id); - - --- --- Name: index_microcosms_on_organizer_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_microcosms_on_organizer_id ON public.microcosms USING btree (organizer_id); - - --- --- Name: index_microcosms_on_slug; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_microcosms_on_slug ON public.microcosms USING btree (slug); - - -- -- Name: index_note_comments_on_author_id_and_created_at; Type: INDEX; Schema: public; Owner: - -- @@ -3161,27 +3161,19 @@ ALTER TABLE ONLY public.diary_entry_subscriptions -- --- Name: oauth_access_grants fk_rails_330c32d8d9; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.oauth_access_grants - ADD CONSTRAINT fk_rails_330c32d8d9 FOREIGN KEY (resource_owner_id) REFERENCES public.users(id) NOT VALID; - - --- --- Name: microcosm_links fk_rails_4e3be5d646; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: communities fk_rails_15754625a4; Type: FK CONSTRAINT; Schema: public; Owner: - -- -ALTER TABLE ONLY public.microcosm_links - ADD CONSTRAINT fk_rails_4e3be5d646 FOREIGN KEY (microcosm_id) REFERENCES public.microcosms(id); +ALTER TABLE ONLY public.communities + ADD CONSTRAINT fk_rails_15754625a4 FOREIGN KEY (organizer_id) REFERENCES public.users(id); -- --- Name: microcosms fk_rails_682f8f4a39; Type: FK CONSTRAINT; Schema: public; Owner: - +-- Name: oauth_access_grants fk_rails_330c32d8d9; Type: FK CONSTRAINT; Schema: public; Owner: - -- -ALTER TABLE ONLY public.microcosms - ADD CONSTRAINT fk_rails_682f8f4a39 FOREIGN KEY (organizer_id) REFERENCES public.users(id); +ALTER TABLE ONLY public.oauth_access_grants + ADD CONSTRAINT fk_rails_330c32d8d9 FOREIGN KEY (resource_owner_id) REFERENCES public.users(id) NOT VALID; -- @@ -3232,6 +3224,14 @@ ALTER TABLE ONLY public.oauth_access_tokens ADD CONSTRAINT fk_rails_ee63f25419 FOREIGN KEY (resource_owner_id) REFERENCES public.users(id) NOT VALID; +-- +-- Name: community_links fk_rails_f60a749c39; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.community_links + ADD CONSTRAINT fk_rails_f60a749c39 FOREIGN KEY (community_id) REFERENCES public.communities(id); + + -- -- Name: friends friends_friend_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -3652,3 +3652,5 @@ INSERT INTO "schema_migrations" (version) VALUES ('7'), ('8'), ('9'); + + diff --git a/foo b/foo deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/abilities/abilities_test.rb b/test/abilities/abilities_test.rb index 5e3076457af..59b10a61dec 100644 --- a/test/abilities/abilities_test.rb +++ b/test/abilities/abilities_test.rb @@ -26,15 +26,15 @@ class GuestAbilityTest < AbilityTest end end - test "microcosm permissions for a guest" do + test "community permissions for a guest" do ability = Ability.new nil [:index, :show].each do |action| - assert ability.can?(action, Microcosm), "should be able to #{action} Microcosms" + assert ability.can?(action, Community), "should be able to #{action} Communities" end [:edit].each do |action| - assert ability.cannot?(action, Microcosm), "should not be able to #{action} Microcosms" + assert ability.cannot?(action, Community), "should not be able to #{action} Communities" end end @@ -73,11 +73,11 @@ class UserAbilityTest < AbilityTest end # This does not take into account object level access control. - test "microcosm permissions for a user" do + test "community permissions for a user" do ability = Ability.new create(:user) [:create, :edit].each do |action| - assert ability.can?(action, Microcosm), "should be able to #{action} Microcosms" + assert ability.can?(action, Community), "should be able to #{action} Communities" end end end diff --git a/test/controllers/communities_controller_test.rb b/test/controllers/communities_controller_test.rb new file mode 100644 index 00000000000..b9f2776dd91 --- /dev/null +++ b/test/controllers/communities_controller_test.rb @@ -0,0 +1,262 @@ +require "test_helper" + +class CommunitiesControllerTest < ActionDispatch::IntegrationTest + ## + # test all routes which lead to this controller + # Following guidance from Ruby on Rails Guide + # https://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers + # + def test_routes + assert_routing( + { :path => "/communities", :method => :get }, + { :controller => "communities", :action => "index" } + ) + assert_routing( + { :path => "/communities/1", :method => :get }, + { :controller => "communities", :action => "show", :id => "1" } + ) + assert_routing( + { :path => "/communities/mdc", :method => :get }, + { :controller => "communities", :action => "show", :id => "mdc" } + ) + assert_routing( + { :path => "/communities/mdc/edit", :method => :get }, + { :controller => "communities", :action => "edit", :id => "mdc" } + ) + assert_routing( + { :path => "/communities/mdc", :method => :put }, + { :controller => "communities", :action => "update", :id => "mdc" } + ) + assert_routing( + { :path => "/communities/new", :method => :get }, + { :controller => "communities", :action => "new" } + ) + assert_routing( + { :path => "/communities", :method => :post }, + { :controller => "communities", :action => "create" } + ) + end + + def test_index_get + # arrange + c = create(:community) + # act + get communities_path + # assert + assert_response :success + assert_template "index" + assert_match c.name, response.body + end + + def test_index_with_specific_user + # arrange + c = create(:community) + # act + get user_communities_path(c.organizer.display_name) + # assert + assert_response :success + assert_template "index" + assert_match c.name, response.body + end + + def test_index_current_user + # arrange + c = create(:community) + session_for(c.organizer) + # act + get communities_path + # assert + assert_response :success + assert_template "index" + assert_match c.name, response.body + end + + def test_index_user_does_not_exist + # arrange + create(:community) + # act + get "/user/user_dne/communities" + # assert + assert_response :not_found + assert_no_missing_translations + end + + def test_show_get + # arrange + c = create(:community) + ch = create(:changeset) + # Make sure this changeset is in the community area. + min_lat = (c.min_lat * GeoRecord::SCALE).to_i + max_lat = (c.max_lat * GeoRecord::SCALE).to_i + min_lon = (c.min_lon * GeoRecord::SCALE).to_i + max_lon = (c.max_lon * GeoRecord::SCALE).to_i + ch.min_lat = rand(min_lat...max_lat) + ch.max_lat = rand(min_lat...max_lat) + ch.min_lon = rand(min_lon...max_lon) + ch.max_lon = rand(min_lon...max_lon) + ch.save! + create(:changeset_tag, :changeset => ch, :k => "comment", :v => "test comment") + # act + get community_path(c) + # assert + assert_response :success + assert_template("show") + assert_match c.name, response.body + assert_match c.description, response.body + assert_match "test comment", response.body + end + + def test_edit_get_no_session + # arrange + c = create(:community) + # act + get edit_community_path(c) + # assert + assert_response :redirect + assert_redirected_to login_path(:referer => edit_community_path(c)) + end + + def test_update_as_non_organizer + # Should this test be in abilities_test.rb? + # arrange + c = create(:community) + other_user = create(:user) + session_for(other_user) + # act + put community_path(c), :params => { :community => c.as_json }, :xhr => true + # assert + assert_redirected_to :controller => :errors, :action => :forbidden + end + + def test_update_put_success + # TODO: When community_member is created switch to using that factory. + # arrange + c1 = create(:community) # original object + c2 = build(:community) # new data + session_for(c1.organizer) + + # act + # Update c1 with the values from c2. + put community_url(c1), :params => { :community => c2.as_json }, :xhr => true + + # assert + assert_redirected_to community_path(c1) + assert_equal I18n.t("communities.update.success"), flash[:notice] + c1.reload + # Assign the id of c1 to c2, so we can do an equality test easily. + c2.id = c1.id + assert_equal(c2, c1) + end + + def test_update_put_failure + # TODO: When community_member is created switch to using that factory. + # arrange + c = create(:community) # original object + session_for(c.organizer) + form = c.attributes.except("id", "created_at", "updated_at", "slug") + # Force an update failure based on validation. + form["latitude"] = 100.0 + + # act + assert_difference "Community.count", 0 do + put community_url(c), :params => { :community => form.as_json }, :xhr => true + end + + # assert + assert_equal I18n.t("communities.update.failure"), flash[:alert] + end + + def test_new_no_login + # Make sure that you are redirected to the login page when you + # are not logged in + # act + get new_community_path + # assert + assert_response :redirect + assert_redirected_to login_path(:referer => new_community_path) + end + + def test_new_form + # Now try again when logged in + # arrange + session_for(create(:user)) + # act + get new_community_path + # assert + assert_response :success + # assert_select "title", :text => /New Community/, :count => 1 + assert_select "div.content-heading", :count => 1 do + assert_select "h1", :text => /Community/, :count => 1 + end + assert_select "div#content", :count => 1 do + assert_select "form[action='/communities'][method=post]", :count => 1 do + assert_select "input#community_location[name='community[location]']", :count => 1 + assert_select "input#community_latitude[name='community[latitude]']", :count => 1 + assert_select "input#community_longitude[name='community[longitude]']", :count => 1 + assert_select "input#community_min_lat[name='community[min_lat]']", :count => 1 + assert_select "input#community_max_lat[name='community[max_lat]']", :count => 1 + assert_select "input#community_min_lon[name='community[min_lon]']", :count => 1 + assert_select "input#community_max_lon[name='community[max_lon]']", :count => 1 + assert_select "textarea#community_description[name='community[description]']", :count => 1 + assert_select "input", :count => 10 + end + end + end + + def test_create_when_save_works + # arrange + c_orig = create(:community) + session_for(c_orig.organizer) + + # act + c_new_slug = nil + assert_difference "Community.count", 1 do + post communities_url, :params => { :community => c_orig.as_json }, :xhr => true + c_new_slug = @response.headers["Location"].split("/")[-1] + end + + # assert + assert_equal I18n.t("communities.create.success"), flash[:notice] + c_new = Community.find_by(:slug => c_new_slug) + # Assign the id c_new to c_orig, so we can do an equality test easily. + c_orig.id = c_new.id + assert_equal(c_orig, c_new) + end + + def test_create_when_save_fails + # arrange + session_for(create(:user)) + c = create(:community) + form = c.attributes.except("id", "created_at", "updated_at", "slug") + form["latitude"] = 100.0 + + # act and assert + assert_difference "Community.count", 0 do + post communities_path, :params => { :community => form.as_json }, :xhr => true + assert_response :success + assert_template "new" + end + end + + def test_create_with_coords_out_of_range + # arrange + u = create(:user) + session_for(u) + c_orig = create(:community) + c_orig.longitude = -200 + + # act + c_new_slug = nil + assert_difference "Community.count", 1 do + post communities_url, :params => { :community => c_orig.as_json }, :xhr => true + c_new_slug = @response.headers["Location"].split("/")[-1] + end + + # assert + assert_equal I18n.t("communities.create.success"), flash[:notice] + c_new = Community.find_by(:slug => c_new_slug) + # Assign the id c_new to c_orig, so we can do an equality test easily. + c_orig.id = c_new.id + assert_equal 160, c_new.longitude + end +end diff --git a/test/controllers/community_links_controller_test.rb b/test/controllers/community_links_controller_test.rb new file mode 100644 index 00000000000..79a8d245d6b --- /dev/null +++ b/test/controllers/community_links_controller_test.rb @@ -0,0 +1,204 @@ +require "test_helper" +require "minitest/mock" + +class CommunityLinksControllerTest < ActionDispatch::IntegrationTest + ## + # test all routes which lead to this controller + # Following guidance from Ruby on Rails Guide + # https://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers + + def test_routes + assert_routing( + { :path => "/communities/foo/community_links", :method => :get }, + { :controller => "community_links", :action => "index", :community_id => "foo" } + ) + assert_routing( + { :path => "/community_links/1/edit", :method => :get }, + { :controller => "community_links", :action => "edit", :id => "1" } + ) + assert_routing( + { :path => "/community_links/1", :method => :put }, + { :controller => "community_links", :action => "update", :id => "1" } + ) + assert_routing( + { :path => "/communities/foo/community_links/new", :method => :get }, + { :controller => "community_links", :action => "new", :community_id => "foo" } + ) + assert_routing( + { :path => "/communities/foo/community_links", :method => :post }, + { :controller => "community_links", :action => "create", :community_id => "foo" } + ) + end + + def test_index_get + # arrange + c = create(:community) + link = create(:community_link, :community_id => c.id) + # act + get community_community_links_path(c.id) + # assert + assert_response :success + assert_template "index" + assert_match link.site, response.body + end + + def test_edit_get_no_session + # arrange + l = create(:community_link) + # act + get edit_community_link_path(l) + # assert + assert_response :redirect + assert_redirected_to login_path(:referer => edit_community_link_path(l)) + end + + def test_update_as_non_organizer + # Should this test be in abilities_test.rb? + # arrange + link = create(:community_link) + session_for(create(:user)) + # act + put community_link_path link, :community_link => link + # assert + assert_redirected_to :controller => :errors, :action => :forbidden + end + + def test_update_put_success + # TODO: When community_member is created switch to using that factory. + # arrange + c = create(:community) + link1 = create(:community_link, :community_id => c.id) # original object + link2 = build(:community_link, :community_id => c.id) # new data + link_2_form = link2.attributes.except("id", "created_at", "updated_at") + session_for(c.organizer) + + # act + # Update link1 with the values from link2. + put community_link_url(link1), :params => { :community_link => link_2_form.as_json }, :xhr => true + + # assert + assert_redirected_to community_path(link1.community) + assert_equal I18n.t("community_links.update.success"), flash[:notice] + link1.reload + # Assign the id of link1 to link2, so we can do an equality test easily. + link2.id = link1.id + assert_equal(link2, link1) + end + + def test_update_put_failure + # arrange + mic = create(:community) # original object + session_for(mic.organizer) + link = create(:community_link, :community_id => mic.id) # original object + def link.update(_params) + false + end + + controller_mock = CommunityLinksController.new + def controller_mock.set_link + @link = CommunityLink.new + end + + def controller_mock.render(_partial) + # Can't do assert_equal here. + # assert_equal :edit, partial + end + + # act + CommunityLinksController.stub :new, controller_mock do + CommunityLink.stub :new, link do + assert_difference "CommunityLink.count", 0 do + put community_link_url(link), :params => { :community_link => link.as_json }, :xhr => true + end + end + end + + # assert + assert_equal I18n.t("community_links.update.failure"), flash[:alert] + end + + def test_new_no_login + # Make sure that you are redirected to the login page when you + # are not logged in + # arrange + c = create(:community) + # act + get new_community_community_link_path(c) + # assert + assert_response :redirect + assert_redirected_to login_path(:referer => new_community_community_link_path(c)) + end + + def test_new_form + # Now try again when logged in + # arrange + c = create(:community) + session_for(c.organizer) + # act + get new_community_community_link_path(c) + # assert + assert_response :success + assert_select "div.content-heading", :count => 1 do + assert_select "h1", :text => /Community Link/, :count => 1 + end + action = community_community_links_path(c) + assert_select "div#content", :count => 1 do + assert_select "form[action='#{action}'][method=post]", :count => 1 do + assert_select "input#community_link_site[name='community_link[site]']", :count => 1 + assert_select "input#community_link_url[name='community_link[url]']", :count => 1 + assert_select "input", :count => 4 + end + end + end + + def test_create_when_save_works + # arrange + c = create(:community) + link_orig = create(:community_link, :community => c) + form = link_orig.attributes.except("id", "created_at", "updated_at") + session_for(c.organizer) + + # act + link_new_id = nil + assert_difference "CommunityLink.count", 1 do + post community_community_links_path c.id, :community_link => form + link_new_id = @response.headers["link_id"] + end + + # assert + # Not sure what's going on with this assigns magic. + # assert_redirected_to "/community/#{assigns(:community_link).id}" + assert_equal I18n.t("community_links.create.success"), flash[:notice] + link_new = CommunityLink.find_by(:id => link_new_id) + # Assign the id link_new to link_orig, so we can do an equality test easily. + link_orig.id = link_new.id + assert_equal(link_orig, link_new) + end + + def test_create_when_save_fails + # arrange + mic = create(:community) + session_for(mic.organizer) + link = build(:community_link, :community => mic, :url => "invalid url") + form = link.attributes.except("id", "created_at", "updated_at") + + # act and assert + assert_no_difference "CommunityLink.count", 0 do + post community_community_links_path :community_link => form, :community_id => mic.id + end + + assert_template :new + end + + def test_delete + # arrange + mic = create(:community) + link = create(:community_link, :community_id => mic.id) + session_for(mic.organizer) + + # act and assert + assert_difference "CommunityLink.count", -1 do + delete community_link_path(:id => link.id) + end + end +end diff --git a/test/controllers/microcosm_links_controller_test.rb b/test/controllers/microcosm_links_controller_test.rb deleted file mode 100644 index fa0d6566708..00000000000 --- a/test/controllers/microcosm_links_controller_test.rb +++ /dev/null @@ -1,204 +0,0 @@ -require "test_helper" -require "minitest/mock" - -class MicrocosmLinksControllerTest < ActionDispatch::IntegrationTest - ## - # test all routes which lead to this controller - # Following guidance from Ruby on Rails Guide - # https://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers - - def test_routes - assert_routing( - { :path => "/microcosms/foo/microcosm_links", :method => :get }, - { :controller => "microcosm_links", :action => "index", :microcosm_id => "foo" } - ) - assert_routing( - { :path => "/microcosm_links/1/edit", :method => :get }, - { :controller => "microcosm_links", :action => "edit", :id => "1" } - ) - assert_routing( - { :path => "/microcosm_links/1", :method => :put }, - { :controller => "microcosm_links", :action => "update", :id => "1" } - ) - assert_routing( - { :path => "/microcosms/foo/microcosm_links/new", :method => :get }, - { :controller => "microcosm_links", :action => "new", :microcosm_id => "foo" } - ) - assert_routing( - { :path => "/microcosms/foo/microcosm_links", :method => :post }, - { :controller => "microcosm_links", :action => "create", :microcosm_id => "foo" } - ) - end - - def test_index_get - # arrange - m = create(:microcosm) - link = create(:microcosm_link, :microcosm_id => m.id) - # act - get microcosm_microcosm_links_path(m.id) - # assert - assert_response :success - assert_template "index" - assert_match link.site, response.body - end - - def test_edit_get_no_session - # arrange - l = create(:microcosm_link) - # act - get edit_microcosm_link_path(l) - # assert - assert_response :redirect - assert_redirected_to login_path(:referer => edit_microcosm_link_path(l)) - end - - def test_update_as_non_organizer - # Should this test be in abilities_test.rb? - # arrange - link = create(:microcosm_link) - session_for(create(:user)) - # act - put microcosm_link_path link, :microcosm_link => link - # assert - assert_redirected_to :controller => :errors, :action => :forbidden - end - - def test_update_put_success - # TODO: When microcosm_member is created switch to using that factory. - # arrange - m = create(:microcosm) - link1 = create(:microcosm_link, :microcosm_id => m.id) # original object - link2 = build(:microcosm_link, :microcosm_id => m.id) # new data - link_2_form = link2.attributes.except("id", "created_at", "updated_at") - session_for(m.organizer) - - # act - # Update m1 with the values from m2. - put microcosm_link_url(link1), :params => { :microcosm_link => link_2_form.as_json }, :xhr => true - - # assert - assert_redirected_to microcosm_path(link1.microcosm) - assert_equal I18n.t("microcosm_links.update.success"), flash[:notice] - link1.reload - # Assign the id of link1 to link2, so we can do an equality test easily. - link2.id = link1.id - assert_equal(link2, link1) - end - - def test_update_put_failure - # arrange - mic = create(:microcosm) # original object - session_for(mic.organizer) - link = create(:microcosm_link, :microcosm_id => mic.id) # original object - def link.update(_params) - false - end - - controller_mock = MicrocosmLinksController.new - def controller_mock.set_link - @link = MicrocosmLink.new - end - - def controller_mock.render(_partial) - # Can't do assert_equal here. - # assert_equal :edit, partial - end - - # act - MicrocosmLinksController.stub :new, controller_mock do - MicrocosmLink.stub :new, link do - assert_difference "MicrocosmLink.count", 0 do - put microcosm_link_url(link), :params => { :microcosm_link => link.as_json }, :xhr => true - end - end - end - - # assert - assert_equal I18n.t("microcosm_links.update.failure"), flash[:alert] - end - - def test_new_no_login - # Make sure that you are redirected to the login page when you - # are not logged in - # arrange - m = create(:microcosm) - # act - get new_microcosm_microcosm_link_path(m) - # assert - assert_response :redirect - assert_redirected_to login_path(:referer => new_microcosm_microcosm_link_path(m)) - end - - def test_new_form - # Now try again when logged in - # arrange - m = create(:microcosm) - session_for(m.organizer) - # act - get new_microcosm_microcosm_link_path(m) - # assert - assert_response :success - assert_select "div.content-heading", :count => 1 do - assert_select "h1", :text => /Microcosm Link/, :count => 1 - end - action = microcosm_microcosm_links_path(m) - assert_select "div#content", :count => 1 do - assert_select "form[action='#{action}'][method=post]", :count => 1 do - assert_select "input#microcosm_link_site[name='microcosm_link[site]']", :count => 1 - assert_select "input#microcosm_link_url[name='microcosm_link[url]']", :count => 1 - assert_select "input", :count => 4 - end - end - end - - def test_create_when_save_works - # arrange - m = create(:microcosm) - link_orig = create(:microcosm_link, :microcosm => m) - form = link_orig.attributes.except("id", "created_at", "updated_at") - session_for(m.organizer) - - # act - link_new_id = nil - assert_difference "MicrocosmLink.count", 1 do - post microcosm_microcosm_links_path m.id, :microcosm_link => form - link_new_id = @response.headers["link_id"] - end - - # assert - # Not sure what's going on with this assigns magic. - # assert_redirected_to "/microcosm/#{assigns(:microcosm_link).id}" - assert_equal I18n.t("microcosm_links.create.success"), flash[:notice] - link_new = MicrocosmLink.find_by(:id => link_new_id) - # Assign the id m_new to m_orig, so we can do an equality test easily. - link_orig.id = link_new.id - assert_equal(link_orig, link_new) - end - - def test_create_when_save_fails - # arrange - mic = create(:microcosm) - session_for(mic.organizer) - link = build(:microcosm_link, :microcosm => mic, :url => "invalid url") - form = link.attributes.except("id", "created_at", "updated_at") - - # act and assert - assert_no_difference "MicrocosmLink.count", 0 do - post microcosm_microcosm_links_path :microcosm_link => form, :microcosm_id => mic.id - end - - assert_template :new - end - - def test_delete - # arrange - mic = create(:microcosm) - link = create(:microcosm_link, :microcosm_id => mic.id) - session_for(mic.organizer) - - # act and assert - assert_difference "MicrocosmLink.count", -1 do - delete microcosm_link_path(:id => link.id) - end - end -end diff --git a/test/controllers/microcosms_controller_test.rb b/test/controllers/microcosms_controller_test.rb deleted file mode 100644 index 3e0b530cdb2..00000000000 --- a/test/controllers/microcosms_controller_test.rb +++ /dev/null @@ -1,262 +0,0 @@ -require "test_helper" - -class MicrocosmsControllerTest < ActionDispatch::IntegrationTest - ## - # test all routes which lead to this controller - # Following guidance from Ruby on Rails Guide - # https://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers - # - def test_routes - assert_routing( - { :path => "/microcosms", :method => :get }, - { :controller => "microcosms", :action => "index" } - ) - assert_routing( - { :path => "/microcosms/1", :method => :get }, - { :controller => "microcosms", :action => "show", :id => "1" } - ) - assert_routing( - { :path => "/microcosms/mdc", :method => :get }, - { :controller => "microcosms", :action => "show", :id => "mdc" } - ) - assert_routing( - { :path => "/microcosms/mdc/edit", :method => :get }, - { :controller => "microcosms", :action => "edit", :id => "mdc" } - ) - assert_routing( - { :path => "/microcosms/mdc", :method => :put }, - { :controller => "microcosms", :action => "update", :id => "mdc" } - ) - assert_routing( - { :path => "/microcosms/new", :method => :get }, - { :controller => "microcosms", :action => "new" } - ) - assert_routing( - { :path => "/microcosms", :method => :post }, - { :controller => "microcosms", :action => "create" } - ) - end - - def test_index_get - # arrange - m = create(:microcosm) - # act - get microcosms_path - # assert - assert_response :success - assert_template "index" - assert_match m.name, response.body - end - - def test_index_with_specific_user - # arrange - m = create(:microcosm) - # act - get user_microcosms_path(m.organizer.display_name) - # assert - assert_response :success - assert_template "index" - assert_match m.name, response.body - end - - def test_index_current_user - # arrange - m = create(:microcosm) - session_for(m.organizer) - # act - get microcosms_path - # assert - assert_response :success - assert_template "index" - assert_match m.name, response.body - end - - def test_index_user_does_not_exist - # arrange - create(:microcosm) - # act - get "/user/user_dne/microcosms" - # assert - assert_response :not_found - assert_no_missing_translations - end - - def test_show_get - # arrange - m = create(:microcosm) - ch = create(:changeset) - # Make sure this changeset is in the microcosm area. - min_lat = (m.min_lat * GeoRecord::SCALE).to_i - max_lat = (m.max_lat * GeoRecord::SCALE).to_i - min_lon = (m.min_lon * GeoRecord::SCALE).to_i - max_lon = (m.max_lon * GeoRecord::SCALE).to_i - ch.min_lat = rand(min_lat...max_lat) - ch.max_lat = rand(min_lat...max_lat) - ch.min_lon = rand(min_lon...max_lon) - ch.max_lon = rand(min_lon...max_lon) - ch.save! - create(:changeset_tag, :changeset => ch, :k => "comment", :v => "test comment") - # act - get microcosm_path(m) - # assert - assert_response :success - assert_template("show") - assert_match m.name, response.body - assert_match m.description, response.body - assert_match "test comment", response.body - end - - def test_edit_get_no_session - # arrange - m = create(:microcosm) - # act - get edit_microcosm_path(m) - # assert - assert_response :redirect - assert_redirected_to login_path(:referer => edit_microcosm_path(m)) - end - - def test_update_as_non_organizer - # Should this test be in abilities_test.rb? - # arrange - m = create(:microcosm) - other_user = create(:user) - session_for(other_user) - # act - put microcosm_path(m), :params => { :microcosm => m.as_json }, :xhr => true - # assert - assert_redirected_to :controller => :errors, :action => :forbidden - end - - def test_update_put_success - # TODO: When microcosm_member is created switch to using that factory. - # arrange - m1 = create(:microcosm) # original object - m2 = build(:microcosm) # new data - session_for(m1.organizer) - - # act - # Update m1 with the values from m2. - put microcosm_url(m1), :params => { :microcosm => m2.as_json }, :xhr => true - - # assert - assert_redirected_to microcosm_path(m1) - assert_equal I18n.t("microcosms.update.success"), flash[:notice] - m1.reload - # Assign the id of m1 to m2, so we can do an equality test easily. - m2.id = m1.id - assert_equal(m2, m1) - end - - def test_update_put_failure - # TODO: When microcosm_member is created switch to using that factory. - # arrange - m1 = create(:microcosm) # original object - session_for(m1.organizer) - form = m1.attributes.except("id", "created_at", "updated_at", "slug") - # Force an update failure based on validation. - form["latitude"] = 100.0 - - # act - assert_difference "Microcosm.count", 0 do - put microcosm_url(m1), :params => { :microcosm => form.as_json }, :xhr => true - end - - # assert - assert_equal I18n.t("microcosms.update.failure"), flash[:alert] - end - - def test_new_no_login - # Make sure that you are redirected to the login page when you - # are not logged in - # act - get new_microcosm_path - # assert - assert_response :redirect - assert_redirected_to login_path(:referer => new_microcosm_path) - end - - def test_new_form - # Now try again when logged in - # arrange - session_for(create(:user)) - # act - get new_microcosm_path - # assert - assert_response :success - # assert_select "title", :text => /New Microcosm/, :count => 1 - assert_select "div.content-heading", :count => 1 do - assert_select "h1", :text => /Microcosm/, :count => 1 - end - assert_select "div#content", :count => 1 do - assert_select "form[action='/microcosms'][method=post]", :count => 1 do - assert_select "input#microcosm_location[name='microcosm[location]']", :count => 1 - assert_select "input#microcosm_latitude[name='microcosm[latitude]']", :count => 1 - assert_select "input#microcosm_longitude[name='microcosm[longitude]']", :count => 1 - assert_select "input#microcosm_min_lat[name='microcosm[min_lat]']", :count => 1 - assert_select "input#microcosm_max_lat[name='microcosm[max_lat]']", :count => 1 - assert_select "input#microcosm_min_lon[name='microcosm[min_lon]']", :count => 1 - assert_select "input#microcosm_max_lon[name='microcosm[max_lon]']", :count => 1 - assert_select "textarea#microcosm_description[name='microcosm[description]']", :count => 1 - assert_select "input", :count => 10 - end - end - end - - def test_create_when_save_works - # arrange - m_orig = create(:microcosm) - session_for(m_orig.organizer) - - # act - m_new_slug = nil - assert_difference "Microcosm.count", 1 do - post microcosms_url, :params => { :microcosm => m_orig.as_json }, :xhr => true - m_new_slug = @response.headers["Location"].split("/")[-1] - end - - # assert - assert_equal I18n.t("microcosms.create.success"), flash[:notice] - m_new = Microcosm.find_by(:slug => m_new_slug) - # Assign the id m_new to m_orig, so we can do an equality test easily. - m_orig.id = m_new.id - assert_equal(m_orig, m_new) - end - - def test_create_when_save_fails - # arrange - session_for(create(:user)) - m = create(:microcosm) - form = m.attributes.except("id", "created_at", "updated_at", "slug") - form["latitude"] = 100.0 - - # act and assert - assert_difference "Microcosm.count", 0 do - post microcosms_path, :params => { :microcosm => form.as_json }, :xhr => true - assert_response :success - assert_template "new" - end - end - - def test_create_with_coords_out_of_range - # arrange - u = create(:user) - session_for(u) - m_orig = create(:microcosm) - m_orig.longitude = -200 - - # act - m_new_slug = nil - assert_difference "Microcosm.count", 1 do - post microcosms_url, :params => { :microcosm => m_orig.as_json }, :xhr => true - m_new_slug = @response.headers["Location"].split("/")[-1] - end - - # assert - assert_equal I18n.t("microcosms.create.success"), flash[:notice] - m_new = Microcosm.find_by(:slug => m_new_slug) - # Assign the id m_new to m_orig, so we can do an equality test easily. - m_orig.id = m_new.id - assert_equal 160, m_new.longitude - end -end diff --git a/test/factories/microcosms.rb b/test/factories/communities.rb similarity index 90% rename from test/factories/microcosms.rb rename to test/factories/communities.rb index 637e94f9893..0f63059ce2d 100644 --- a/test/factories/microcosms.rb +++ b/test/factories/communities.rb @@ -1,5 +1,5 @@ FactoryBot.define do - factory :microcosm do + factory :community do # Make sure the ranges make sense. lat1 = Random.rand(-90.0..90.0) lat2 = Random.rand(-90.0..90.0) @@ -10,7 +10,7 @@ lat = Random.rand(lat1..lat2) lon = Random.rand(lon1..lon2) - sequence(:name) { |n| "Microcosm #{n}" } + sequence(:name) { |n| "Community #{n}" } sequence(:description) { |n| "This is description #{n}" } sequence(:location) { |n| "This is location #{n}" } organizer :factory => :user diff --git a/test/factories/microcosm_links.rb b/test/factories/community_links.rb similarity index 67% rename from test/factories/microcosm_links.rb rename to test/factories/community_links.rb index ca66b642157..715a2c636dc 100644 --- a/test/factories/microcosm_links.rb +++ b/test/factories/community_links.rb @@ -1,6 +1,6 @@ FactoryBot.define do - factory :microcosm_link do - microcosm + factory :community_link do + community site { "website" } url { "https://example.com" } end diff --git a/test/models/microcosm_link_test.rb b/test/models/community_link_test.rb similarity index 69% rename from test/models/microcosm_link_test.rb rename to test/models/community_link_test.rb index 42ae734828d..842d65b0e5f 100644 --- a/test/models/microcosm_link_test.rb +++ b/test/models/community_link_test.rb @@ -1,11 +1,11 @@ require "test_helper" -class MicrocosmLinkTest < ActiveSupport::TestCase - def test_microcosm_link_validations +class CommunityLinkTest < ActiveSupport::TestCase + def test_community_link_validations validate({}, true) - validate({ :microcosm_id => nil }, false) - validate({ :microcosm_id => "" }, false) + validate({ :community_id => nil }, false) + validate({ :community_id => "" }, false) validate({ :site => nil }, false) validate({ :site => "" }, false) diff --git a/test/models/microcosm_test.rb b/test/models/community_test.rb similarity index 88% rename from test/models/microcosm_test.rb rename to test/models/community_test.rb index d4c483fd696..85fe75649bb 100644 --- a/test/models/microcosm_test.rb +++ b/test/models/community_test.rb @@ -1,7 +1,7 @@ require "test_helper" -class MicrocosmTest < ActiveSupport::TestCase - def test_microcosm_validations +class CommunityTest < ActiveSupport::TestCase + def test_community_validations validate({}, true) validate({ :name => nil }, false) @@ -44,13 +44,13 @@ def test_microcosm_validations def test_bbox # arrange - m = create(:microcosm) - m.min_lat = 10 - m.max_lat = 20 - m.min_lon = 30 - m.max_lon = 40 + c = create(:community) + c.min_lat = 10 + c.max_lat = 20 + c.min_lon = 30 + c.max_lon = 40 # act - b = m.bbox + b = c.bbox # assert assert_equal 10, b.min_lat assert_equal 20, b.max_lat diff --git a/test/models/issue_test.rb b/test/models/issue_test.rb index cb077ae141a..82e3683f5e5 100644 --- a/test/models/issue_test.rb +++ b/test/models/issue_test.rb @@ -12,7 +12,7 @@ def test_assigned_role def test_reported_user create(:language, :code => "en") user = create(:user) - microcosm = create(:microcosm) + community = create(:community) note = create(:note_comment, :author => create(:user)).note anonymous_note = create(:note_comment, :author => nil).note diary_entry = create(:diary_entry) @@ -22,9 +22,9 @@ def test_reported_user issue.save! assert_equal issue.reported_user, user - issue = build(:issue, :reportable => microcosm, :assigned_role => "moderator") + issue = build(:issue, :reportable => community, :assigned_role => "moderator") issue.save! - assert_equal issue.reported_user, microcosm.organizer + assert_equal issue.reported_user, community.organizer issue = build(:issue, :reportable => note, :assigned_role => "administrator") issue.save! diff --git a/test/system/report_microcosm_test.rb b/test/system/report_community_test.rb similarity index 55% rename from test/system/report_microcosm_test.rb rename to test/system/report_community_test.rb index adc63385e21..71ae798df3e 100644 --- a/test/system/report_microcosm_test.rb +++ b/test/system/report_community_test.rb @@ -1,28 +1,28 @@ require "application_system_test_case" -class ReportMicrocosmTest < ApplicationSystemTestCase +class ReportCommunityTest < ApplicationSystemTestCase def setup create(:language, :code => "en") - @microcosm = create(:microcosm) + @community = create(:community) end def test_no_link_when_not_logged_in - visit microcosm_path(@microcosm) - assert page.has_content?(@microcosm.name) + visit community_path(@community) + assert page.has_content?(@community.name) - assert_not page.has_content?(I18n.t("microcosms.show.report")) + assert_not page.has_content?(I18n.t("communities.show.report")) end def test_it_works sign_in_as(create(:user)) - visit microcosm_path(@microcosm) - assert page.has_content? @microcosm.name + visit community_path(@community) + assert page.has_content? @community.name - click_on I18n.t("microcosms.show.report") + click_on I18n.t("communities.show.report") assert page.has_content? "Report" assert page.has_content? I18n.t("reports.new.disclaimer.intro") - choose I18n.t("reports.new.categories.microcosm.spam_label") + choose I18n.t("reports.new.categories.community.spam_label") fill_in "report_details", :with => "This comment is spam" assert_difference "Issue.count", 1 do click_on "Create Report"
  • -

    <%= link_to microcosm.name, microcosm %>

    +

    <%= link_to community.name, community %>

    - <%= microcosm.location %> + <%= community.location %>
    - (<%= number_with_precision(microcosm.latitude) %>°, <%= number_with_precision(microcosm.longitude) %>°) + (<%= number_with_precision(community.latitude) %>°, <%= number_with_precision(community.longitude) %>°)

    - <%= microcosm.description %> + <%= community.description %>

    - <%= link_to t(".edit"), edit_microcosm_link_path(link) %> - <%= link_to t(".delete"), microcosm_link_path(link), :method => :delete %> + <%= link_to t(".edit"), edit_community_link_path(link) %> + <%= link_to t(".delete"), community_link_path(link), :method => :delete %>