Compare commits
6 commits
develop
...
add-user-r
Author | SHA1 | Date | |
---|---|---|---|
|
0bbe838483 | ||
|
245bb88112 | ||
|
706e094c90 | ||
|
3348ea7b54 | ||
|
a737bd3cfd | ||
|
58d81e239b |
30 changed files with 9556 additions and 197 deletions
2
Gemfile
2
Gemfile
|
@ -38,7 +38,7 @@ gem 'uglifier'
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
gem 'brakeman', require: false
|
gem 'brakeman', require: false
|
||||||
gem 'factory_bot_rails'
|
gem 'factory_girl_rails'
|
||||||
gem 'json-schema'
|
gem 'json-schema'
|
||||||
gem 'rspec-rails'
|
gem 'rspec-rails'
|
||||||
gem 'shoulda-matchers'
|
gem 'shoulda-matchers'
|
||||||
|
|
|
@ -105,10 +105,10 @@ GEM
|
||||||
actionmailer (>= 4.0, < 6)
|
actionmailer (>= 4.0, < 6)
|
||||||
activesupport (>= 4.0, < 6)
|
activesupport (>= 4.0, < 6)
|
||||||
execjs (2.7.0)
|
execjs (2.7.0)
|
||||||
factory_bot (4.8.2)
|
factory_girl (4.8.0)
|
||||||
activesupport (>= 3.0.0)
|
activesupport (>= 3.0.0)
|
||||||
factory_bot_rails (4.8.2)
|
factory_girl_rails (4.8.0)
|
||||||
factory_bot (~> 4.8.2)
|
factory_girl (~> 4.8.0)
|
||||||
railties (>= 3.0.0)
|
railties (>= 3.0.0)
|
||||||
faker (1.8.4)
|
faker (1.8.4)
|
||||||
i18n (~> 0.5)
|
i18n (~> 0.5)
|
||||||
|
@ -311,7 +311,7 @@ DEPENDENCIES
|
||||||
doorkeeper
|
doorkeeper
|
||||||
dotenv-rails
|
dotenv-rails
|
||||||
exception_notification
|
exception_notification
|
||||||
factory_bot_rails
|
factory_girl_rails
|
||||||
faker
|
faker
|
||||||
httparty
|
httparty
|
||||||
jquery-rails
|
jquery-rails
|
||||||
|
|
|
@ -62,7 +62,6 @@ class AccessController < ApplicationController
|
||||||
request = AccessRequest.find(params[:request_id])
|
request = AccessRequest.find(params[:request_id])
|
||||||
request.approve
|
request.approve
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js
|
|
||||||
format.json do
|
format.json do
|
||||||
head :ok
|
head :ok
|
||||||
end
|
end
|
||||||
|
@ -74,7 +73,6 @@ class AccessController < ApplicationController
|
||||||
request = AccessRequest.find(params[:request_id])
|
request = AccessRequest.find(params[:request_id])
|
||||||
request.deny
|
request.deny
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js
|
|
||||||
format.json do
|
format.json do
|
||||||
head :ok
|
head :ok
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,6 @@ class ApplicationController < ActionController::Base
|
||||||
include Pundit
|
include Pundit
|
||||||
include PunditExtra
|
include PunditExtra
|
||||||
rescue_from Pundit::NotAuthorizedError, with: :handle_unauthorized
|
rescue_from Pundit::NotAuthorizedError, with: :handle_unauthorized
|
||||||
protect_from_forgery(with: :exception)
|
|
||||||
|
|
||||||
before_action :invite_link
|
before_action :invite_link
|
||||||
before_action :prepare_exception_notifier
|
before_action :prepare_exception_notifier
|
||||||
|
@ -23,14 +22,7 @@ class ApplicationController < ActionController::Base
|
||||||
helper_method :admin?
|
helper_method :admin?
|
||||||
|
|
||||||
def handle_unauthorized
|
def handle_unauthorized
|
||||||
if authenticated? && (params[:controller] == 'maps') && (params[:action] == 'show')
|
head :forbidden
|
||||||
redirect_to request_access_map_path(params[:id])
|
|
||||||
elsif authenticated?
|
|
||||||
redirect_to root_path, notice: "You don't have permission to see that page."
|
|
||||||
else
|
|
||||||
store_location_for(resource, request.fullpath)
|
|
||||||
redirect_to sign_in_path, notice: 'Try signing in to do that.'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -41,19 +33,19 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
def require_no_user
|
def require_no_user
|
||||||
return true unless authenticated?
|
return true unless authenticated?
|
||||||
redirect_to edit_user_path(user), notice: 'You must be logged out.'
|
head :forbidden
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_user
|
def require_user
|
||||||
return true if authenticated?
|
return true if authenticated?
|
||||||
redirect_to sign_in_path, notice: 'You must be logged in.'
|
head :forbidden
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_admin
|
def require_admin
|
||||||
return true if authenticated? && admin?
|
return true if authenticated? && admin?
|
||||||
redirect_to root_url, notice: 'You need to be an admin for that.'
|
head :forbidden
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,81 +1,35 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class MetacodeSetsController < ApplicationController
|
class MetacodeSetsController < ApplicationController
|
||||||
before_action :require_admin
|
include MetacodesHelper
|
||||||
|
before_action :require_admin, except: :index
|
||||||
|
|
||||||
# GET /metacode_sets
|
# GET /metacode_sets
|
||||||
# GET /metacode_sets.json
|
|
||||||
def index
|
def index
|
||||||
@metacode_sets = MetacodeSet.order('name').all
|
@metacode_sets = MetacodeSet.order('name').all
|
||||||
|
render json: metacode_sets_json
|
||||||
respond_to do |format|
|
|
||||||
format.html # index.html.erb
|
|
||||||
format.json { render json: @metacode_sets }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
### SHOW IS NOT CURRENTLY IN USE
|
|
||||||
# GET /metacode_sets/1
|
|
||||||
# GET /metacode_sets/1.json
|
|
||||||
# def show
|
|
||||||
# @metacode_set = MetacodeSet.find(params[:id])
|
|
||||||
#
|
|
||||||
# respond_to do |format|
|
|
||||||
# format.html # show.html.erb
|
|
||||||
# format.json { render json: @metacode_set }
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
# GET /metacode_sets/new
|
|
||||||
# GET /metacode_sets/new.json
|
|
||||||
def new
|
|
||||||
@metacode_set = MetacodeSet.new
|
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.html # new.html.erb
|
|
||||||
format.json { render json: @metacode_set }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# GET /metacode_sets/1/edit
|
|
||||||
def edit
|
|
||||||
@metacode_set = MetacodeSet.find(params[:id])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /metacode_sets
|
# POST /metacode_sets
|
||||||
# POST /metacode_sets.json
|
|
||||||
def create
|
def create
|
||||||
@user = current_user
|
@user = current_user
|
||||||
@metacode_set = MetacodeSet.new(metacode_set_params)
|
@metacode_set = MetacodeSet.new(metacode_set_params)
|
||||||
@metacode_set.user_id = @user.id
|
@metacode_set.user_id = @user.id
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
if @metacode_set.save
|
if @metacode_set.save
|
||||||
# create the InMetacodeSet for all the metacodes that were selected for the set
|
# create the InMetacodeSet for all the metacodes that were selected for the set
|
||||||
@metacodes = params[:metacodes][:value].split(',')
|
@metacodes = params[:metacodes][:value].split(',')
|
||||||
@metacodes.each do |m|
|
@metacodes.each do |m|
|
||||||
InMetacodeSet.create(metacode_id: m, metacode_set_id: @metacode_set.id)
|
InMetacodeSet.create(metacode_id: m, metacode_set_id: @metacode_set.id)
|
||||||
end
|
end
|
||||||
format.html do
|
render json: @metacode_set, status: :created
|
||||||
redirect_to metacode_sets_url,
|
|
||||||
notice: 'Metacode set was successfully created.'
|
|
||||||
end
|
|
||||||
format.json do
|
|
||||||
render json: @metacode_set, status: :created, location: metacode_sets_url
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
format.html { render action: 'new' }
|
render json: @metacode_set.errors, status: :unprocessable_entity
|
||||||
format.json { render json: @metacode_set.errors, status: :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# PUT /metacode_sets/1
|
# PUT /metacode_sets/1
|
||||||
# PUT /metacode_sets/1.json
|
|
||||||
def update
|
def update
|
||||||
@metacode_set = MetacodeSet.find(params[:id])
|
@metacode_set = MetacodeSet.find(params[:id])
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
if @metacode_set.update_attributes(metacode_set_params)
|
if @metacode_set.update_attributes(metacode_set_params)
|
||||||
|
|
||||||
# build an array of the IDs of the metacodes currently in the set
|
# build an array of the IDs of the metacodes currently in the set
|
||||||
|
@ -96,29 +50,19 @@ class MetacodeSetsController < ApplicationController
|
||||||
InMetacodeSet.create(metacode_id: m, metacode_set_id: @metacode_set.id)
|
InMetacodeSet.create(metacode_id: m, metacode_set_id: @metacode_set.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
format.html { redirect_to metacode_sets_url, notice: 'Metacode set was successfully updated.' }
|
head :no_content
|
||||||
format.json { head :no_content }
|
|
||||||
else
|
else
|
||||||
format.html { render action: 'edit' }
|
render json: @metacode_set.errors, status: :unprocessable_entity
|
||||||
format.json { render json: @metacode_set.errors, status: :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE /metacode_sets/1
|
# DELETE /metacode_sets/1
|
||||||
# DELETE /metacode_sets/1.json
|
|
||||||
def destroy
|
def destroy
|
||||||
@metacode_set = MetacodeSet.find(params[:id])
|
@metacode_set = MetacodeSet.find(params[:id])
|
||||||
|
|
||||||
# delete everything that tracks what's in the set
|
# delete everything that tracks what's in the set
|
||||||
@metacode_set.in_metacode_sets.each(&:destroy)
|
@metacode_set.in_metacode_sets.each(&:destroy)
|
||||||
|
|
||||||
@metacode_set.destroy
|
@metacode_set.destroy
|
||||||
|
head :no_content
|
||||||
respond_to do |format|
|
|
||||||
format.html { redirect_to metacode_sets_url }
|
|
||||||
format.json { head :no_content }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -2,76 +2,39 @@
|
||||||
|
|
||||||
class MetacodesController < ApplicationController
|
class MetacodesController < ApplicationController
|
||||||
before_action :require_admin, except: %i[index show]
|
before_action :require_admin, except: %i[index show]
|
||||||
before_action :set_metacode, only: %i[edit update]
|
before_action :set_metacode, only: %i[update]
|
||||||
|
|
||||||
# GET /metacodes
|
# GET /metacodes
|
||||||
# GET /metacodes.json
|
|
||||||
def index
|
def index
|
||||||
@metacodes = Metacode.order('name').all
|
@metacodes = Metacode.order('name').all
|
||||||
|
render json: @metacodes
|
||||||
respond_to do |format|
|
|
||||||
format.html do
|
|
||||||
return unless require_admin
|
|
||||||
render :index
|
|
||||||
end
|
|
||||||
format.json { render json: @metacodes }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /metacodes/1.json
|
# GET /metacodes/1
|
||||||
# GET /metacodes/Action.json
|
# GET /metacodes/Action
|
||||||
# GET /metacodes/action.json
|
# GET /metacodes/action
|
||||||
def show
|
def show
|
||||||
@metacode = Metacode.where('DOWNCASE(name) = ?', downcase(params[:name])).first if params[:name]
|
@metacode = Metacode.where('DOWNCASE(name) = ?', downcase(params[:name])).first if params[:name]
|
||||||
set_metacode unless @metacode
|
set_metacode unless @metacode
|
||||||
|
render json: @metacode
|
||||||
respond_to do |format|
|
|
||||||
format.json { render json: @metacode }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# GET /metacodes/new
|
|
||||||
# GET /metacodes/new.json
|
|
||||||
def new
|
|
||||||
@metacode = Metacode.new
|
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.html
|
|
||||||
format.json { render json: @metacode }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# GET /metacodes/1/edit
|
|
||||||
def edit
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /metacodes
|
# POST /metacodes
|
||||||
# POST /metacodes.json
|
|
||||||
def create
|
def create
|
||||||
@metacode = Metacode.new(metacode_params)
|
@metacode = Metacode.new(metacode_params)
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
if @metacode.save
|
if @metacode.save
|
||||||
format.html { redirect_to metacodes_url, notice: 'Metacode was successfully created.' }
|
render json: @metacode, status: :created
|
||||||
format.json { render json: @metacode, status: :created, location: metacodes_url }
|
|
||||||
else
|
else
|
||||||
format.html { render :new }
|
render json: @metacode.errors, status: :unprocessable_entity
|
||||||
format.json { render json: @metacode.errors, status: :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# PUT /metacodes/1
|
# PUT /metacodes/1
|
||||||
# PUT /metacodes/1.json
|
|
||||||
def update
|
def update
|
||||||
respond_to do |format|
|
|
||||||
if @metacode.update(metacode_params)
|
if @metacode.update(metacode_params)
|
||||||
format.html { redirect_to metacodes_url, notice: 'Metacode was successfully updated.' }
|
head :no_content
|
||||||
format.json { head :no_content }
|
|
||||||
else
|
else
|
||||||
format.html { render :edit }
|
render json: @metacode.errors, status: :unprocessable_entity
|
||||||
format.json { render json: @metacode.errors, status: :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,23 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
respond_to :html, :json
|
respond_to :html, :json
|
||||||
|
|
||||||
|
# GET /users/current
|
||||||
|
def current
|
||||||
|
if current_user
|
||||||
|
# these are just options, saying include these values, they aren't the values themselves
|
||||||
|
render json: current_user.to_json({
|
||||||
|
follows: true,
|
||||||
|
email: true,
|
||||||
|
follow_settings: true,
|
||||||
|
emails_allowed: true,
|
||||||
|
inviteCode: true,
|
||||||
|
unread_notifications_count: user_unread_notifications_count
|
||||||
|
})
|
||||||
|
else
|
||||||
|
render json: nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# GET /users/1.json
|
# GET /users/1.json
|
||||||
def show
|
def show
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
|
@ -42,7 +59,7 @@ class UsersController < ApplicationController
|
||||||
correct_pass = @user.valid_password?(params[:current_password])
|
correct_pass = @user.valid_password?(params[:current_password])
|
||||||
|
|
||||||
if correct_pass && @user.update_attributes(user_params)
|
if correct_pass && @user.update_attributes(user_params)
|
||||||
update_follow_settings(@user, params[:settings])
|
update_follow_settings(@user, params[:settings]) if is_tester(@user)
|
||||||
@user.image = nil if params[:remove_image] == '1'
|
@user.image = nil if params[:remove_image] == '1'
|
||||||
@user.save
|
@user.save
|
||||||
sign_in(@user, bypass: true)
|
sign_in(@user, bypass: true)
|
||||||
|
|
|
@ -5,7 +5,7 @@ module ApplicationHelper
|
||||||
"#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '')
|
"#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '')
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_unread_notification_count
|
def user_unread_notifications_count
|
||||||
return 0 if current_user.nil?
|
return 0 if current_user.nil?
|
||||||
@uunc ||= current_user.mailboxer_notification_receipts.reduce(0) do |total, receipt|
|
@uunc ||= current_user.mailboxer_notification_receipts.reduce(0) do |total, receipt|
|
||||||
receipt.is_read ? total : total + 1
|
receipt.is_read ? total : total + 1
|
||||||
|
|
|
@ -52,27 +52,30 @@ module MetacodesHelper
|
||||||
|
|
||||||
def metacode_sets_json
|
def metacode_sets_json
|
||||||
metacode_sets = []
|
metacode_sets = []
|
||||||
|
if current_user
|
||||||
metacode_sets << {
|
metacode_sets << {
|
||||||
name: 'Recently Used',
|
name: 'Recently Used',
|
||||||
metacodes: user_recent_metacodes
|
description: 'Your recently used metacodes',
|
||||||
.map { |m| { id: m.id, icon_path: asset_path(m.icon), name: m.name } }
|
metacodes: user_recent_metacodes.map { |m| m.id }
|
||||||
}
|
}
|
||||||
metacode_sets << {
|
metacode_sets << {
|
||||||
name: 'Most Used',
|
name: 'Most Used',
|
||||||
metacodes: user_most_used_metacodes
|
description: 'Your most used metacodes',
|
||||||
.map { |m| { id: m.id, icon_path: asset_path(m.icon), name: m.name } }
|
metacodes: user_most_used_metacodes.map { |m| m.id }
|
||||||
}
|
}
|
||||||
|
end
|
||||||
metacode_sets += MetacodeSet.order('name').all.map do |set|
|
metacode_sets += MetacodeSet.order('name').all.map do |set|
|
||||||
{
|
{
|
||||||
|
id: set.id,
|
||||||
name: set.name,
|
name: set.name,
|
||||||
metacodes: set.metacodes.order('name')
|
desc: set.desc,
|
||||||
.map { |m| { id: m.id, icon_path: asset_path(m.icon), name: m.name } }
|
metacodes: set.metacodes.order('name').map { |m| m.id }
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
metacode_sets << {
|
metacode_sets << {
|
||||||
name: 'All',
|
name: 'All',
|
||||||
metacodes: Metacode.order('name').all
|
desc: 'A list of all the metacodes',
|
||||||
.map { |m| { id: m.id, icon_path: asset_path(m.icon), name: m.name } }
|
metacodes: Metacode.order('name').all.map { |m| m.id }
|
||||||
}
|
}
|
||||||
metacode_sets.to_json
|
metacode_sets.to_json
|
||||||
end
|
end
|
||||||
|
|
|
@ -70,6 +70,8 @@ class User < ApplicationRecord
|
||||||
json['follow_map_on_contributed'] = settings.follow_map_on_contributed == '1'
|
json['follow_map_on_contributed'] = settings.follow_map_on_contributed == '1'
|
||||||
end
|
end
|
||||||
json['email'] = email if options[:email]
|
json['email'] = email if options[:email]
|
||||||
|
json['invite_code'] = code if options[:inviteCode]
|
||||||
|
json['unread_notifications_count'] = options[:unread_notifications_count] if not options[:unread_notifications_count].nil?
|
||||||
json
|
json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
$('.main-text').text($('.requesterName').text() + ' has been shared on the map and notified.')
|
|
|
@ -1 +0,0 @@
|
||||||
$('.main-text').text('Fair enough.')
|
|
|
@ -1,6 +1,6 @@
|
||||||
<div id="loading"></div>
|
<div id="loading"></div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
Metamaps.ServerData.unreadNotificationsCount = <%= current_user ? user_unread_notification_count : 0 %>
|
Metamaps.ServerData.unreadNotificationsCount = <%= current_user ? user_unread_notifications_count : 0 %>
|
||||||
Metamaps.ServerData.mapIsStarred = <%= current_user && @map && current_user.starred_map?(@map) ? true : false %>
|
Metamaps.ServerData.mapIsStarred = <%= current_user && @map && current_user.starred_map?(@map) ? true : false %>
|
||||||
Metamaps.ServerData.mobileTitle = "<%= yield(:mobile_title) %>"
|
Metamaps.ServerData.mobileTitle = "<%= yield(:mobile_title) %>"
|
||||||
Metamaps.ServerData.ActiveMapper = <%= current_user ? current_user.to_json({follows: true, email: true, follow_settings: true}).html_safe : nil %>
|
Metamaps.ServerData.ActiveMapper = <%= current_user ? current_user.to_json({follows: true, email: true, follow_settings: true}).html_safe : nil %>
|
||||||
|
|
|
@ -6,6 +6,10 @@ Rails.application.configure do
|
||||||
config.log_level = :info
|
config.log_level = :info
|
||||||
config.eager_load = false
|
config.eager_load = false
|
||||||
|
|
||||||
|
config.action_cable.allowed_request_origins = [
|
||||||
|
'http://localhost:3000'
|
||||||
|
]
|
||||||
|
|
||||||
# In the development environment your application's code is reloaded on
|
# In the development environment your application's code is reloaded on
|
||||||
# every request. This slows down response time but is perfect for development
|
# every request. This slows down response time but is perfect for development
|
||||||
# since you don't have to restart the web server when you make code changes.
|
# since you don't have to restart the web server when you make code changes.
|
||||||
|
|
|
@ -5,7 +5,7 @@ Rails.application.configure do
|
||||||
# Settings specified here will take precedence over those in config/application.rb
|
# Settings specified here will take precedence over those in config/application.rb
|
||||||
|
|
||||||
config.action_cable.allowed_request_origins = [
|
config.action_cable.allowed_request_origins = [
|
||||||
'https://metamaps.herokuapp.com', 'http://metamaps.herokuapp.com', 'https://metamaps.cc'
|
'https://metamaps.herokuapp.com', 'https://metamaps.cc'
|
||||||
]
|
]
|
||||||
|
|
||||||
# log to stdout
|
# log to stdout
|
||||||
|
|
|
@ -15,7 +15,6 @@ Metamaps::Application.routes.draw do
|
||||||
get 'starred'
|
get 'starred'
|
||||||
get 'mapper/:id', action: 'mapper'
|
get 'mapper/:id', action: 'mapper'
|
||||||
end
|
end
|
||||||
get :explore, to: redirect('/')
|
|
||||||
|
|
||||||
resources :maps, except: %i[index edit] do
|
resources :maps, except: %i[index edit] do
|
||||||
member do
|
member do
|
||||||
|
@ -70,7 +69,7 @@ Metamaps::Application.routes.draw do
|
||||||
|
|
||||||
resources :metacode_sets, except: [:show]
|
resources :metacode_sets, except: [:show]
|
||||||
|
|
||||||
resources :metacodes, except: [:destroy]
|
resources :metacodes, except: [:new, :edit, :destroy]
|
||||||
get 'metacodes/:name', to: 'metacodes#show'
|
get 'metacodes/:name', to: 'metacodes#show'
|
||||||
|
|
||||||
namespace :search do
|
namespace :search do
|
||||||
|
@ -112,6 +111,9 @@ Metamaps::Application.routes.draw do
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :users, except: %i[index destroy] do
|
resources :users, except: %i[index destroy] do
|
||||||
|
collection do
|
||||||
|
get :current
|
||||||
|
end
|
||||||
member do
|
member do
|
||||||
get :details
|
get :details
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,13 +26,13 @@ At the time of writing, there are four directories in the spec folder. One,
|
||||||
`support`, is for helper functions. `rails_helper.rb` and `spec_helper.rb` are
|
`support`, is for helper functions. `rails_helper.rb` and `spec_helper.rb` are
|
||||||
also for helper functions.
|
also for helper functions.
|
||||||
|
|
||||||
`factories` is for a gem called [factory-bot][factory_bot]. This gem lets you
|
`factories` is for a gem called [factory-girl][factory-girl]. This gem lets you
|
||||||
use the `create` and `build` functions to quickly create the simplest possible
|
use the `create` and `build` functions to quickly create the simplest possible
|
||||||
valid version of a given model. For instance:
|
valid version of a given model. For instance:
|
||||||
|
|
||||||
let(:map1) { create :map }
|
let(:map1) { create :map }
|
||||||
let(:alex) { create :user, name: "Alex" }
|
let(:ronald) { create :user, name: "Ronald" }
|
||||||
let(:map2) { create :map, user: alex }
|
let(:map2) { create :map, user: ronald }
|
||||||
|
|
||||||
As you can see, you can also customize the factories. You can read the full
|
As you can see, you can also customize the factories. You can read the full
|
||||||
documentation at the link above or check the existing specs to see how it works.
|
documentation at the link above or check the existing specs to see how it works.
|
||||||
|
@ -53,5 +53,5 @@ the added code works. This will help in a few ways:
|
||||||
|
|
||||||
Happy testing!
|
Happy testing!
|
||||||
|
|
||||||
[factory-bot]: https://github.com/thoughtbot/factory_bot
|
[factory-girl]: https://github.com/thoughtbot/factory_girl
|
||||||
[rspec-docs]: http://rspec.info
|
[rspec-docs]: http://rspec.info
|
||||||
|
|
9436
package-lock.json
generated
Normal file
9436
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryGirl.define do
|
||||||
factory :access_request do
|
factory :access_request do
|
||||||
map
|
map
|
||||||
user
|
user
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryGirl.define do
|
||||||
factory :mapping do
|
factory :mapping do
|
||||||
xloc 0
|
xloc 0
|
||||||
yloc 0
|
yloc 0
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryGirl.define do
|
||||||
factory :map do
|
factory :map do
|
||||||
sequence(:name) { |n| "Cool Map ##{n}" }
|
sequence(:name) { |n| "Cool Map ##{n}" }
|
||||||
permission :commons
|
permission :commons
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryGirl.define do
|
||||||
factory :message do
|
factory :message do
|
||||||
association :resource, factory: :map
|
association :resource, factory: :map
|
||||||
user
|
user
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryGirl.define do
|
||||||
factory :metacode do
|
factory :metacode do
|
||||||
sequence(:name) { |n| "Cool Metacode ##{n}" }
|
sequence(:name) { |n| "Cool Metacode ##{n}" }
|
||||||
manual_icon 'https://images.com/image.png'
|
manual_icon 'https://images.com/image.png'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryGirl.define do
|
||||||
factory :star do
|
factory :star do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryGirl.define do
|
||||||
factory :synapse do
|
factory :synapse do
|
||||||
sequence(:desc) { |n| "Cool synapse ##{n}" }
|
sequence(:desc) { |n| "Cool synapse ##{n}" }
|
||||||
category :'from-to'
|
category :'from-to'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryGirl.define do
|
||||||
factory :token do
|
factory :token do
|
||||||
user
|
user
|
||||||
description ''
|
description ''
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryGirl.define do
|
||||||
factory :topic do
|
factory :topic do
|
||||||
user
|
user
|
||||||
association :updated_by, factory: :user
|
association :updated_by, factory: :user
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryGirl.define do
|
||||||
factory :user_map do
|
factory :user_map do
|
||||||
map
|
map
|
||||||
user
|
user
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
# have actual codes, you'll need to specify one simple_user and then you
|
# have actual codes, you'll need to specify one simple_user and then you
|
||||||
# can specify other :code_user users based on the pre-existing user's code.
|
# can specify other :code_user users based on the pre-existing user's code.
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryGirl.define do
|
||||||
factory :code_user, class: User do
|
factory :code_user, class: User do
|
||||||
sequence(:name) { |n| "Cool User ##{n}" }
|
sequence(:name) { |n| "Cool User ##{n}" }
|
||||||
sequence(:email) { |n| "cooluser#{n}@cooldomain.com" }
|
sequence(:email) { |n| "cooluser#{n}@cooldomain.com" }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# lets you type create(:user) instead of FactoryBot.create(:user)
|
# lets you type create(:user) instead of FactoryGirl.create(:user)
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.include FactoryBot::Syntax::Methods
|
config.include FactoryGirl::Syntax::Methods
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue