Update code style automatically using rubocop gem (#563)

* install rubocop

* 1961 automatic rubocop fixes

* update rubocop.yml to ignore half of the remaining cops

* rubocop lint warnings

* random other warnings fixed
This commit is contained in:
Devin Howard 2016-07-26 08:14:23 +08:00 committed by GitHub
parent 17bccd809a
commit 7d4da81272
109 changed files with 1387 additions and 1570 deletions

14
.rubocop.yml Normal file
View file

@ -0,0 +1,14 @@
AllCops:
TargetRubyVersion: 2.3
Exclude:
- 'db/**/*'
- 'tmp/**/*'
- 'bin/**/*'
- 'vendor/**/*'
- 'app/assets/javascripts/node_modules/**/*'
Rails:
Enabled: true
Metrics/LineLength:
Max: 100

View file

@ -1 +1 @@
ruby-2.1.3 2.1.3

View file

@ -5,7 +5,7 @@ gem 'rails'
gem 'active_model_serializers', '~> 0.8.1' gem 'active_model_serializers', '~> 0.8.1'
gem 'aws-sdk', '< 2.0' gem 'aws-sdk', '< 2.0'
gem 'best_in_place' #in-place editing gem 'best_in_place' # in-place editing
gem 'delayed_job', '~> 4.0.2' gem 'delayed_job', '~> 4.0.2'
gem 'delayed_job_active_record', '~> 4.0.1' gem 'delayed_job_active_record', '~> 4.0.1'
gem 'devise' gem 'devise'
@ -59,4 +59,5 @@ group :development, :test do
gem 'pry-rails' gem 'pry-rails'
gem 'quiet_assets' gem 'quiet_assets'
gem 'tunemygc' gem 'tunemygc'
gem 'rubocop'
end end

View file

@ -40,6 +40,7 @@ GEM
tzinfo (~> 1.1) tzinfo (~> 1.1)
addressable (2.3.8) addressable (2.3.8)
arel (6.0.3) arel (6.0.3)
ast (2.3.0)
aws-sdk (1.66.0) aws-sdk (1.66.0)
aws-sdk-v1 (= 1.66.0) aws-sdk-v1 (= 1.66.0)
aws-sdk-v1 (1.66.0) aws-sdk-v1 (1.66.0)
@ -151,8 +152,11 @@ GEM
cocaine (~> 0.5.5) cocaine (~> 0.5.5)
mime-types mime-types
mimemagic (= 0.3.0) mimemagic (= 0.3.0)
parser (2.3.1.2)
ast (~> 2.2)
pg (0.18.4) pg (0.18.4)
pkg-config (1.1.7) pkg-config (1.1.7)
powerpack (0.1.1)
pry (0.10.3) pry (0.10.3)
coderay (~> 1.1.0) coderay (~> 1.1.0)
method_source (~> 0.8.1) method_source (~> 0.8.1)
@ -202,6 +206,7 @@ GEM
activesupport (= 4.2.6) activesupport (= 4.2.6)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rainbow (2.1.0)
rake (11.2.2) rake (11.2.2)
redis (3.3.0) redis (3.3.0)
responders (2.2.0) responders (2.2.0)
@ -223,6 +228,13 @@ GEM
rspec-mocks (~> 3.4.0) rspec-mocks (~> 3.4.0)
rspec-support (~> 3.4.0) rspec-support (~> 3.4.0)
rspec-support (3.4.1) rspec-support (3.4.1)
rubocop (0.41.1)
parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
sass (3.4.22) sass (3.4.22)
sass-rails (5.0.4) sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
@ -256,6 +268,7 @@ GEM
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (3.0.0) uglifier (3.0.0)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
unicode-display_width (1.1.0)
uservoice-ruby (0.0.11) uservoice-ruby (0.0.11)
ezcrypto (>= 0.7.2) ezcrypto (>= 0.7.2)
json (>= 1.7.5) json (>= 1.7.5)
@ -303,6 +316,7 @@ DEPENDENCIES
rails_12factor rails_12factor
redis redis
rspec-rails rspec-rails
rubocop
sass-rails sass-rails
shoulda-matchers shoulda-matchers
simplecov simplecov

12
Vagrantfile vendored
View file

@ -31,15 +31,15 @@ sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '3112';"
SCRIPT SCRIPT
VAGRANTFILE_API_VERSION = "2" VAGRANTFILE_API_VERSION = '2'.freeze
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "trusty64" config.vm.box = 'trusty64'
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box" config.vm.box_url = 'http://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box'
config.vm.network :forwarded_port, guest: 3000, host: 3000 config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.network :forwarded_port, guest: 5001, host: 5001 config.vm.network :forwarded_port, guest: 5001, host: 5001
config.vm.network "private_network", ip: "10.0.1.11" config.vm.network 'private_network', ip: '10.0.1.11'
config.vm.synced_folder ".", "/vagrant", :nfs => true config.vm.synced_folder '.', '/vagrant', nfs: true
config.vm.provision "shell", inline: $script config.vm.provision 'shell', inline: $script
end end

View file

@ -1,3 +1,2 @@
class Api::MappingsController < API::RestfulController class Api::MappingsController < API::RestfulController
end end

View file

@ -1,3 +1,2 @@
class Api::MapsController < API::RestfulController class Api::MapsController < API::RestfulController
end end

View file

@ -35,9 +35,7 @@ class API::RestfulController < ActionController::Base
def token_user def token_user
token = params[:access_token] token = params[:access_token]
access_token = Token.find_by_token(token) access_token = Token.find_by_token(token)
if access_token @token_user ||= access_token.user if access_token
@token_user ||= access_token.user
end
end end
def doorkeeper_user def doorkeeper_user
@ -49,5 +47,4 @@ class API::RestfulController < ActionController::Base
def permitted_params def permitted_params
@permitted_params ||= PermittedParams.new(params) @permitted_params ||= PermittedParams.new(params)
end end
end end

View file

@ -1,3 +1,2 @@
class Api::SynapsesController < API::RestfulController class Api::SynapsesController < API::RestfulController
end end

View file

@ -1,7 +1,6 @@
class Api::TokensController < API::RestfulController class Api::TokensController < API::RestfulController
def my_tokens def my_tokens
raise Pundit::NotAuthorizedError.new unless current_user raise Pundit::NotAuthorizedError unless current_user
instantiate_collection page_collection: false, timeframe_collection: false instantiate_collection page_collection: false, timeframe_collection: false
respond_with_collection respond_with_collection
end end
@ -15,5 +14,4 @@ class Api::TokensController < API::RestfulController
def visible_records def visible_records
current_user.tokens current_user.tokens
end end
end end

View file

@ -1,3 +1,2 @@
class Api::TopicsController < API::RestfulController class Api::TopicsController < API::RestfulController
end end

View file

@ -20,12 +20,12 @@ class ApplicationController < ActionController::Base
helper_method :admin? helper_method :admin?
def after_sign_in_path_for(resource) def after_sign_in_path_for(resource)
sign_in_url = url_for(:action => 'new', :controller => 'sessions', :only_path => false, :protocol => 'https') sign_in_url = url_for(action: 'new', controller: 'sessions', only_path: false, protocol: 'https')
if request.referer == sign_in_url if request.referer == sign_in_url
super super
elsif params[:uv_login] == "1" elsif params[:uv_login] == '1'
"http://support.metamaps.cc/login_success?sso=" + current_sso_token 'http://support.metamaps.cc/login_success?sso=' + current_sso_token
else else
stored_location_for(resource) || request.referer || root_path stored_location_for(resource) || request.referer || root_path
end end
@ -33,35 +33,35 @@ class ApplicationController < ActionController::Base
def handle_unauthorized def handle_unauthorized
if authenticated? if authenticated?
head :forbidden # TODO make this better head :forbidden # TODO: make this better
else else
redirect_to new_user_session_path, notice: "Try signing in to do that." redirect_to new_user_session_path, notice: 'Try signing in to do that.'
end end
end end
private private
def get_invite_link def get_invite_link
@invite_link = "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : "") @invite_link = "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '')
end end
def require_no_user def require_no_user
if authenticated? if authenticated?
redirect_to edit_user_path(user), notice: "You must be logged out." redirect_to edit_user_path(user), notice: 'You must be logged out.'
return false return false
end end
end end
def require_user def require_user
unless authenticated? unless authenticated?
redirect_to new_user_session_path, notice: "You must be logged in." redirect_to new_user_session_path, notice: 'You must be logged in.'
return false return false
end end
end end
def require_admin def require_admin
unless authenticated? && admin? unless authenticated? && admin?
redirect_to root_url, notice: "You need to be an admin for that." redirect_to root_url, notice: 'You need to be an admin for that.'
return false return false
end end
end end
@ -79,7 +79,7 @@ private
end end
def allow_embedding def allow_embedding
#allow all # allow all
response.headers.except! 'X-Frame-Options' response.headers.except! 'X-Frame-Options'
# or allow a whitelist # or allow a whitelist
# response.headers['X-Frame-Options'] = 'ALLOW-FROM http://blog.metamaps.cc' # response.headers['X-Frame-Options'] = 'ALLOW-FROM http://blog.metamaps.cc'

View file

@ -10,15 +10,15 @@ class MainController < ApplicationController
# home page # home page
def home def home
@maps = policy_scope(Map).order("updated_at DESC").page(1).per(20) @maps = policy_scope(Map).order('updated_at DESC').page(1).per(20)
respond_to do |format| respond_to do |format|
format.html { format.html do
if not authenticated? if !authenticated?
render 'main/home' render 'main/home'
else else
render 'maps/activemaps' render 'maps/activemaps'
end end
} end
end end
end end
@ -29,32 +29,32 @@ class MainController < ApplicationController
term = params[:term] term = params[:term]
user = params[:user] ? params[:user] : false user = params[:user] ? params[:user] : false
if term && !term.empty? && term.downcase[0..3] != "map:" && term.downcase[0..6] != "mapper:" && term.downcase != "topic:" if term && !term.empty? && term.downcase[0..3] != 'map:' && term.downcase[0..6] != 'mapper:' && !term.casecmp('topic:').zero?
#remove "topic:" if appended at beginning # remove "topic:" if appended at beginning
term = term[6..-1] if term.downcase[0..5] == "topic:" term = term[6..-1] if term.downcase[0..5] == 'topic:'
#if desc: search desc instead # if desc: search desc instead
desc = false desc = false
if term.downcase[0..4] == "desc:" if term.downcase[0..4] == 'desc:'
term = term[5..-1] term = term[5..-1]
desc = true desc = true
end end
#if link: search link instead # if link: search link instead
link = false link = false
if term.downcase[0..4] == "link:" if term.downcase[0..4] == 'link:'
term = term[5..-1] term = term[5..-1]
link = true link = true
end end
#check whether there's a filter by metacode as part of the query # check whether there's a filter by metacode as part of the query
filterByMetacode = false filterByMetacode = false
Metacode.all.each do |m| Metacode.all.each do |m|
lOne = m.name.length+1 lOne = m.name.length + 1
lTwo = m.name.length lTwo = m.name.length
if term.downcase[0..lTwo] == m.name.downcase + ":" if term.downcase[0..lTwo] == m.name.downcase + ':'
term = term[lOne..-1] term = term[lOne..-1]
filterByMetacode = m filterByMetacode = m
end end
@ -64,7 +64,7 @@ class MainController < ApplicationController
builder = policy_scope(Topic) builder = policy_scope(Topic)
if filterByMetacode if filterByMetacode
if term == "" if term == ''
builder = builder.none builder = builder.none
else else
builder = builder.where('LOWER("name") like ? OR builder = builder.where('LOWER("name") like ? OR
@ -76,7 +76,7 @@ class MainController < ApplicationController
builder = builder.where('LOWER("desc") like ?', search) builder = builder.where('LOWER("desc") like ?', search)
elsif link elsif link
builder = builder.where('LOWER("link") like ?', search) builder = builder.where('LOWER("link") like ?', search)
else #regular case, just search the name else # regular case, just search the name
builder = builder.where('LOWER("name") like ? OR builder = builder.where('LOWER("name") like ? OR
LOWER("desc") like ? OR LOWER("desc") like ? OR
LOWER("link") like ?', search, search, search) LOWER("link") like ?', search, search, search)
@ -96,14 +96,14 @@ class MainController < ApplicationController
term = params[:term] term = params[:term]
user = params[:user] ? params[:user] : nil user = params[:user] ? params[:user] : nil
if term && !term.empty? && term.downcase[0..5] != "topic:" && term.downcase[0..6] != "mapper:" && term.downcase != "map:" if term && !term.empty? && term.downcase[0..5] != 'topic:' && term.downcase[0..6] != 'mapper:' && !term.casecmp('map:').zero?
#remove "map:" if appended at beginning # remove "map:" if appended at beginning
term = term[4..-1] if term.downcase[0..3] == "map:" term = term[4..-1] if term.downcase[0..3] == 'map:'
#if desc: search desc instead # if desc: search desc instead
desc = false desc = false
if term.downcase[0..4] == "desc:" if term.downcase[0..4] == 'desc:'
term = term[5..-1] term = term[5..-1]
desc = true desc = true
end end
@ -111,10 +111,10 @@ class MainController < ApplicationController
search = '%' + term.downcase + '%' search = '%' + term.downcase + '%'
builder = policy_scope(Map) builder = policy_scope(Map)
if desc builder = if desc
builder = builder.where('LOWER("desc") like ?', search) builder.where('LOWER("desc") like ?', search)
else else
builder = builder.where('LOWER("name") like ?', search) builder.where('LOWER("name") like ?', search)
end end
builder = builder.where(user: user) if user builder = builder.where(user: user) if user
@maps = builder.order(:name) @maps = builder.order(:name)
@ -128,13 +128,13 @@ class MainController < ApplicationController
# get /search/mappers?term=SOMETERM # get /search/mappers?term=SOMETERM
def searchmappers def searchmappers
term = params[:term] term = params[:term]
if term && !term.empty? && term.downcase[0..3] != "map:" && term.downcase[0..5] != "topic:" && term.downcase != "mapper:" if term && !term.empty? && term.downcase[0..3] != 'map:' && term.downcase[0..5] != 'topic:' && !term.casecmp('mapper:').zero?
#remove "mapper:" if appended at beginning # remove "mapper:" if appended at beginning
term = term[7..-1] if term.downcase[0..6] == "mapper:" term = term[7..-1] if term.downcase[0..6] == 'mapper:'
search = term.downcase + '%' search = term.downcase + '%'
skip_policy_scope # TODO builder = policy_scope(User) skip_policy_scope # TODO: builder = policy_scope(User)
builder = User.where('LOWER("name") like ?', search) builder = User.where('LOWER("name") like ?', search)
@mappers = builder.order(:name) @mappers = builder.order(:name)
else else
@ -156,26 +156,26 @@ class MainController < ApplicationController
# remove any duplicate synapse types that just differ by # remove any duplicate synapse types that just differ by
# leading or trailing whitespaces # leading or trailing whitespaces
collectedDesc = [] collectedDesc = []
@synapses.to_a.uniq(&:desc).delete_if {|s| @synapses.to_a.uniq(&:desc).delete_if do |s|
desc = s.desc == nil || s.desc == "" ? "" : s.desc.strip desc = s.desc.nil? || s.desc == '' ? '' : s.desc.strip
if collectedDesc.index(desc) == nil if collectedDesc.index(desc).nil?
collectedDesc.push(desc) collectedDesc.push(desc)
boolean = false false # return this value
else else
boolean = true true # return this value
end
end end
}
elsif topic1id && !topic1id.empty? elsif topic1id && !topic1id.empty?
@one = policy_scope(Synapse).where('node1_id = ? AND node2_id = ?', topic1id, topic2id) @one = policy_scope(Synapse).where('node1_id = ? AND node2_id = ?', topic1id, topic2id)
@two = policy_scope(Synapse).where('node2_id = ? AND node1_id = ?', topic1id, topic2id) @two = policy_scope(Synapse).where('node2_id = ? AND node1_id = ?', topic1id, topic2id)
@synapses = @one + @two @synapses = @one + @two
@synapses.sort! {|s1,s2| s1.desc <=> s2.desc }.to_a @synapses.sort! { |s1, s2| s1.desc <=> s2.desc }.to_a
else else
@synapses = [] @synapses = []
end end
#limit to 5 results # limit to 5 results
@synapses = @synapses.slice(0,5) @synapses = @synapses.slice(0, 5)
render json: autocomplete_synapse_array_json(@synapses) render json: autocomplete_synapse_array_json(@synapses)
end end

View file

@ -1,5 +1,4 @@
class MappingsController < ApplicationController class MappingsController < ApplicationController
before_action :require_user, only: [:create, :update, :destroy] before_action :require_user, only: [:create, :update, :destroy]
after_action :verify_authorized, except: :index after_action :verify_authorized, except: :index
after_action :verify_policy_scoped, only: :index after_action :verify_policy_scoped, only: :index
@ -58,6 +57,7 @@ class MappingsController < ApplicationController
end end
private private
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def mapping_params def mapping_params
params.require(:mapping).permit(:id, :xloc, :yloc, :mappable_id, :mappable_type, :map_id) params.require(:mapping).permit(:id, :xloc, :yloc, :mappable_id, :mappable_type, :map_id)

View file

@ -5,20 +5,20 @@ class MapsController < ApplicationController
respond_to :html, :json, :csv respond_to :html, :json, :csv
autocomplete :map, :name, :full => true, :extra_data => [:user_id] autocomplete :map, :name, full: true, extra_data: [:user_id]
# GET /explore/active # GET /explore/active
def activemaps def activemaps
page = params[:page].present? ? params[:page] : 1 page = params[:page].present? ? params[:page] : 1
@maps = policy_scope(Map).order("updated_at DESC") @maps = policy_scope(Map).order('updated_at DESC')
.page(page).per(20) .page(page).per(20)
respond_to do |format| respond_to do |format|
format.html { format.html do
# root url => main/home. main/home renders maps/activemaps view. # root url => main/home. main/home renders maps/activemaps view.
redirect_to root_url and return if authenticated? redirect_to(root_url) && return if authenticated?
respond_with(@maps, @user) respond_with(@maps, @user)
} end
format.json { render json: @maps } format.json { render json: @maps }
end end
end end
@ -27,9 +27,9 @@ class MapsController < ApplicationController
def featuredmaps def featuredmaps
page = params[:page].present? ? params[:page] : 1 page = params[:page].present? ? params[:page] : 1
@maps = policy_scope( @maps = policy_scope(
Map.where("maps.featured = ? AND maps.permission != ?", Map.where('maps.featured = ? AND maps.permission != ?',
true, "private") true, 'private')
).order("updated_at DESC").page(page).per(20) ).order('updated_at DESC').page(page).per(20)
respond_to do |format| respond_to do |format|
format.html { respond_with(@maps, @user) } format.html { respond_with(@maps, @user) }
@ -39,15 +39,15 @@ class MapsController < ApplicationController
# GET /explore/mine # GET /explore/mine
def mymaps def mymaps
if !authenticated? unless authenticated?
skip_policy_scope skip_policy_scope
return redirect_to explore_active_path return redirect_to explore_active_path
end end
page = params[:page].present? ? params[:page] : 1 page = params[:page].present? ? params[:page] : 1
@maps = policy_scope( @maps = policy_scope(
Map.where("maps.user_id = ?", current_user.id) Map.where('maps.user_id = ?', current_user.id)
).order("updated_at DESC").page(page).per(20) ).order('updated_at DESC').page(page).per(20)
respond_to do |format| respond_to do |format|
format.html { respond_with(@maps, @user) } format.html { respond_with(@maps, @user) }
@ -57,15 +57,15 @@ class MapsController < ApplicationController
# GET /explore/shared # GET /explore/shared
def sharedmaps def sharedmaps
if !authenticated? unless authenticated?
skip_policy_scope skip_policy_scope
return redirect_to explore_active_path return redirect_to explore_active_path
end end
page = params[:page].present? ? params[:page] : 1 page = params[:page].present? ? params[:page] : 1
@maps = policy_scope( @maps = policy_scope(
Map.where("maps.id IN (?)", current_user.shared_maps.map(&:id)) Map.where('maps.id IN (?)', current_user.shared_maps.map(&:id))
).order("updated_at DESC").page(page).per(20) ).order('updated_at DESC').page(page).per(20)
respond_to do |format| respond_to do |format|
format.html { respond_with(@maps, @user) } format.html { respond_with(@maps, @user) }
@ -78,7 +78,7 @@ class MapsController < ApplicationController
page = params[:page].present? ? params[:page] : 1 page = params[:page].present? ? params[:page] : 1
@user = User.find(params[:id]) @user = User.find(params[:id])
@maps = policy_scope(Map.where(user: @user)) @maps = policy_scope(Map.where(user: @user))
.order("updated_at DESC").page(page).per(20) .order('updated_at DESC').page(page).per(20)
respond_to do |format| respond_to do |format|
format.html { respond_with(@maps, @user) } format.html { respond_with(@maps, @user) }
@ -92,16 +92,16 @@ class MapsController < ApplicationController
authorize @map authorize @map
respond_to do |format| respond_to do |format|
format.html { format.html do
@allmappers = @map.contributors @allmappers = @map.contributors
@allcollaborators = @map.editors @allcollaborators = @map.editors
@alltopics = @map.topics.to_a.delete_if {|t| not policy(t).show? } @alltopics = @map.topics.to_a.delete_if { |t| !policy(t).show? }
@allsynapses = @map.synapses.to_a.delete_if {|s| not policy(s).show? } @allsynapses = @map.synapses.to_a.delete_if { |s| !policy(s).show? }
@allmappings = @map.mappings.to_a.delete_if {|m| not policy(m).show? } @allmappings = @map.mappings.to_a.delete_if { |m| !policy(m).show? }
@allmessages = @map.messages.sort_by(&:created_at) @allmessages = @map.messages.sort_by(&:created_at)
respond_with(@allmappers, @allcollaborators, @allmappings, @allsynapses, @alltopics, @allmessages, @map) respond_with(@allmappers, @allcollaborators, @allmappings, @allsynapses, @alltopics, @allmessages, @map)
} end
format.json { render json: @map } format.json { render json: @map }
format.csv { redirect_to action: :export, format: :csv } format.csv { redirect_to action: :export, format: :csv }
format.xls { redirect_to action: :export, format: :xls } format.xls { redirect_to action: :export, format: :xls }
@ -135,10 +135,10 @@ class MapsController < ApplicationController
end end
respond_to do |format| respond_to do |format|
format.json { format.json do
head :ok if valid_event head :ok if valid_event
head :bad_request if not valid_event head :bad_request unless valid_event
} end
end end
end end
@ -149,12 +149,11 @@ class MapsController < ApplicationController
@allmappers = @map.contributors @allmappers = @map.contributors
@allcollaborators = @map.editors @allcollaborators = @map.editors
@alltopics = @map.topics.to_a.delete_if {|t| not policy(t).show? } @alltopics = @map.topics.to_a.delete_if { |t| !policy(t).show? }
@allsynapses = @map.synapses.to_a.delete_if {|s| not policy(s).show? } @allsynapses = @map.synapses.to_a.delete_if { |s| !policy(s).show? }
@allmappings = @map.mappings.to_a.delete_if {|m| not policy(m).show? } @allmappings = @map.mappings.to_a.delete_if { |m| !policy(m).show? }
@json = {}
@json = Hash.new()
@json['map'] = @map @json['map'] = @map
@json['topics'] = @alltopics @json['topics'] = @alltopics
@json['synapses'] = @allsynapses @json['synapses'] = @allsynapses
@ -171,7 +170,7 @@ class MapsController < ApplicationController
# POST maps # POST maps
def create def create
@user = current_user @user = current_user
@map = Map.new() @map = Map.new
@map.name = params[:name] @map.name = params[:name]
@map.desc = params[:desc] @map.desc = params[:desc]
@map.permission = params[:permission] @map.permission = params[:permission]
@ -213,11 +212,11 @@ class MapsController < ApplicationController
if @map.save if @map.save
respond_to do |format| respond_to do |format|
format.json { render :json => @map } format.json { render json: @map }
end end
else else
respond_to do |format| respond_to do |format|
format.json { render :json => "invalid params" } format.json { render json: 'invalid params' }
end end
end end
end end
@ -241,27 +240,27 @@ class MapsController < ApplicationController
@map = Map.find(params[:id]) @map = Map.find(params[:id])
authorize @map authorize @map
userIds = params[:access] || [] userIds = params[:access] || []
added = userIds.select { |uid| added = userIds.select do |uid|
user = User.find(uid) user = User.find(uid)
if user.nil? || (current_user && user == current_user) if user.nil? || (current_user && user == current_user)
false false
else else
not @map.collaborators.include?(user) !@map.collaborators.include?(user)
end end
} end
removed = @map.collaborators.select { |user| not userIds.include?(user.id.to_s) }.map(&:id) removed = @map.collaborators.select { |user| !userIds.include?(user.id.to_s) }.map(&:id)
added.each { |uid| added.each do |uid|
um = UserMap.create({ user_id: uid.to_i, map_id: @map.id }) UserMap.create(user_id: uid.to_i, map_id: @map.id)
user = User.find(uid.to_i) user = User.find(uid.to_i)
MapMailer.invite_to_edit_email(@map, current_user, user).deliver_later MapMailer.invite_to_edit_email(@map, current_user, user).deliver_later
} end
removed.each { |uid| removed.each do |uid|
@map.user_maps.select{ |um| um.user_id == uid }.each{ |um| um.destroy } @map.user_maps.select { |um| um.user_id == uid }.each(&:destroy)
} end
respond_to do |format| respond_to do |format|
format.json do format.json do
render :json => { :message => "Successfully altered edit permissions" } render json: { message: 'Successfully altered edit permissions' }
end end
end end
end end
@ -271,18 +270,18 @@ class MapsController < ApplicationController
@map = Map.find(params[:id]) @map = Map.find(params[:id])
authorize @map authorize @map
png = Base64.decode64(params[:encoded_image]['data:image/png;base64,'.length .. -1]) png = Base64.decode64(params[:encoded_image]['data:image/png;base64,'.length..-1])
StringIO.open(png) do |data| StringIO.open(png) do |data|
data.class.class_eval { attr_accessor :original_filename, :content_type } data.class.class_eval { attr_accessor :original_filename, :content_type }
data.original_filename = "map-" + @map.id.to_s + "-screenshot.png" data.original_filename = 'map-' + @map.id.to_s + '-screenshot.png'
data.content_type = "image/png" data.content_type = 'image/png'
@map.screenshot = data @map.screenshot = data
end end
if @map.save if @map.save
render :json => {:message => "Successfully uploaded the map screenshot."} render json: { message: 'Successfully uploaded the map screenshot.' }
else else
render :json => {:message => "Failed to upload image."} render json: { message: 'Failed to upload image.' }
end end
end end

View file

@ -1,5 +1,4 @@
class MessagesController < ApplicationController class MessagesController < ApplicationController
before_action :require_user, except: [:show] before_action :require_user, except: [:show]
after_action :verify_authorized after_action :verify_authorized
@ -61,7 +60,7 @@ class MessagesController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def message_params def message_params
#params.require(:message).permit(:id, :resource_id, :message) # params.require(:message).permit(:id, :resource_id, :message)
params.permit(:id, :resource_id, :resource_type, :message) params.permit(:id, :resource_id, :resource_type, :message)
end end
end end

View file

@ -1,11 +1,10 @@
class MetacodeSetsController < ApplicationController class MetacodeSetsController < ApplicationController
before_action :require_admin before_action :require_admin
# GET /metacode_sets # GET /metacode_sets
# GET /metacode_sets.json # GET /metacode_sets.json
def index def index
@metacode_sets = MetacodeSet.order("name").all @metacode_sets = MetacodeSet.order('name').all
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
@ -16,14 +15,14 @@ class MetacodeSetsController < ApplicationController
### SHOW IS NOT CURRENTLY IN USE ### SHOW IS NOT CURRENTLY IN USE
# GET /metacode_sets/1 # GET /metacode_sets/1
# GET /metacode_sets/1.json # GET /metacode_sets/1.json
# def show # def show
# @metacode_set = MetacodeSet.find(params[:id]) # @metacode_set = MetacodeSet.find(params[:id])
# #
# respond_to do |format| # respond_to do |format|
# format.html # show.html.erb # format.html # show.html.erb
# format.json { render json: @metacode_set } # format.json { render json: @metacode_set }
# end # end
# end # end
# GET /metacode_sets/new # GET /metacode_sets/new
# GET /metacode_sets/new.json # GET /metacode_sets/new.json
@ -53,12 +52,12 @@ class MetacodeSetsController < ApplicationController
# 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 { redirect_to metacode_sets_url, notice: 'Metacode set was successfully created.' } format.html { redirect_to metacode_sets_url, notice: 'Metacode set was successfully created.' }
format.json { render json: @metacode_set, status: :created, location: metacode_sets_url } format.json { render json: @metacode_set, status: :created, location: metacode_sets_url }
else else
format.html { render action: "new" } format.html { render action: 'new' }
format.json { render json: @metacode_set.errors, status: :unprocessable_entity } format.json { render json: @metacode_set.errors, status: :unprocessable_entity }
end end
end end
@ -73,11 +72,11 @@ class MetacodeSetsController < ApplicationController
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
@currentMetacodes = @metacode_set.metacodes.map{ |m| m.id.to_s } @currentMetacodes = @metacode_set.metacodes.map { |m| m.id.to_s }
# get the list of desired metacodes for the set from the user input and build an array out of it # get the list of desired metacodes for the set from the user input and build an array out of it
@newMetacodes = params[:metacodes][:value].split(',') @newMetacodes = params[:metacodes][:value].split(',')
#remove the metacodes that were in it, but now aren't # remove the metacodes that were in it, but now aren't
@removedMetacodes = @currentMetacodes - @newMetacodes @removedMetacodes = @currentMetacodes - @newMetacodes
@removedMetacodes.each do |m| @removedMetacodes.each do |m|
@inmetacodeset = InMetacodeSet.find_by_metacode_id_and_metacode_set_id(m, @metacode_set.id) @inmetacodeset = InMetacodeSet.find_by_metacode_id_and_metacode_set_id(m, @metacode_set.id)
@ -87,13 +86,13 @@ class MetacodeSetsController < ApplicationController
# add the new metacodes # add the new metacodes
@addedMetacodes = @newMetacodes - @currentMetacodes @addedMetacodes = @newMetacodes - @currentMetacodes
@addedMetacodes.each do |m| @addedMetacodes.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 { redirect_to metacode_sets_url, notice: 'Metacode set was successfully updated.' } format.html { redirect_to metacode_sets_url, notice: 'Metacode set was successfully updated.' }
format.json { head :no_content } format.json { head :no_content }
else else
format.html { render action: "edit" } format.html { render action: 'edit' }
format.json { render json: @metacode_set.errors, status: :unprocessable_entity } format.json { render json: @metacode_set.errors, status: :unprocessable_entity }
end end
end end
@ -104,10 +103,8 @@ class MetacodeSetsController < ApplicationController
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 do |m| @metacode_set.in_metacode_sets.each(&:destroy)
m.destroy
end
@metacode_set.destroy @metacode_set.destroy
@ -122,5 +119,4 @@ class MetacodeSetsController < ApplicationController
def metacode_set_params def metacode_set_params
params.require(:metacode_set).permit(:desc, :mapperContributed, :name) params.require(:metacode_set).permit(:desc, :mapperContributed, :name)
end end
end end

View file

@ -4,16 +4,16 @@ class MetacodesController < ApplicationController
# GET /metacodes # GET /metacodes
# GET /metacodes.json # GET /metacodes.json
def index def index
@metacodes = Metacode.order("name").all @metacodes = Metacode.order('name').all
respond_to do |format| respond_to do |format|
format.html { format.html do
unless authenticated? && user.admin unless authenticated? && user.admin
redirect_to root_url, notice: "You need to be an admin for that." redirect_to root_url, notice: 'You need to be an admin for that.'
return false return false
end end
render :index render :index
} end
format.json { render json: @metacodes } format.json { render json: @metacodes }
end end
end end

View file

@ -19,7 +19,7 @@ class SynapsesController < ApplicationController
# POST /synapses.json # POST /synapses.json
def create def create
@synapse = Synapse.new(synapse_params) @synapse = Synapse.new(synapse_params)
@synapse.desc = "" if @synapse.desc.nil? @synapse.desc = '' if @synapse.desc.nil?
authorize @synapse authorize @synapse
respond_to do |format| respond_to do |format|
@ -35,7 +35,7 @@ class SynapsesController < ApplicationController
# PUT /synapses/1.json # PUT /synapses/1.json
def update def update
@synapse = Synapse.find(params[:id]) @synapse = Synapse.find(params[:id])
@synapse.desc = "" if @synapse.desc.nil? @synapse.desc = '' if @synapse.desc.nil?
authorize @synapse authorize @synapse
respond_to do |format| respond_to do |format|

View file

@ -9,10 +9,10 @@ class TopicsController < ApplicationController
# GET /topics/autocomplete_topic # GET /topics/autocomplete_topic
def autocomplete_topic def autocomplete_topic
term = params[:term] term = params[:term]
if term && !term.empty? @topics = if term && !term.empty?
@topics = policy_scope(Topic.where('LOWER("name") like ?', term.downcase + '%')).order('"name"') policy_scope(Topic.where('LOWER("name") like ?', term.downcase + '%')).order('"name"')
else else
@topics = [] []
end end
render json: autocomplete_array_json(@topics) render json: autocomplete_array_json(@topics)
end end
@ -23,16 +23,16 @@ class TopicsController < ApplicationController
authorize @topic authorize @topic
respond_to do |format| respond_to do |format|
format.html { format.html do
@alltopics = [@topic].concat(policy_scope(Topic.relatives1(@topic.id)).to_a).concat(policy_scope(Topic.relatives2(@topic.id)).to_a) @alltopics = [@topic].concat(policy_scope(Topic.relatives1(@topic.id)).to_a).concat(policy_scope(Topic.relatives2(@topic.id)).to_a)
@allsynapses = policy_scope(Synapse.for_topic(@topic.id)).to_a @allsynapses = policy_scope(Synapse.for_topic(@topic.id)).to_a
puts @alltopics.length puts @alltopics.length
puts @allsynapses.length puts @allsynapses.length
@allcreators = @alltopics.map(&:user).uniq @allcreators = @alltopics.map(&:user).uniq
@allcreators += @allsynapses.map(&:user).uniq @allcreators += @allsynapses.map(&:user).uniq
respond_with(@allsynapses, @alltopics, @allcreators, @topic) respond_with(@allsynapses, @alltopics, @allcreators, @topic)
} end
format.json { render json: @topic } format.json { render json: @topic }
end end
end end
@ -48,7 +48,7 @@ puts @allsynapses.length
@allcreators = @alltopics.map(&:user).uniq @allcreators = @alltopics.map(&:user).uniq
@allcreators += @allsynapses.map(&:user).uniq @allcreators += @allsynapses.map(&:user).uniq
@json = Hash.new() @json = {}
@json['topic'] = @topic @json['topic'] = @topic
@json['creators'] = @allcreators @json['creators'] = @allcreators
@json['relatives'] = @alltopics @json['relatives'] = @alltopics
@ -68,7 +68,7 @@ puts @allsynapses.length
@alltopics = policy_scope(Topic.relatives1(@topic.id)).to_a.concat(policy_scope(Topic.relatives2(@topic.id)).to_a).uniq @alltopics = policy_scope(Topic.relatives1(@topic.id)).to_a.concat(policy_scope(Topic.relatives2(@topic.id)).to_a).uniq
@alltopics.delete_if do |topic| @alltopics.delete_if do |topic|
topicsAlreadyHas.index(topic.id) != nil !topicsAlreadyHas.index(topic.id).nil?
end end
@json = Hash.new(0) @json = Hash.new(0)
@ -90,22 +90,22 @@ puts @allsynapses.length
alltopics = policy_scope(Topic.relatives1(@topic.id)).to_a.concat(policy_scope(Topic.relatives2(@topic.id)).to_a).uniq alltopics = policy_scope(Topic.relatives1(@topic.id)).to_a.concat(policy_scope(Topic.relatives2(@topic.id)).to_a).uniq
alltopics.delete_if do |topic| alltopics.delete_if do |topic|
topicsAlreadyHas.index(topic.id.to_s) != nil !topicsAlreadyHas.index(topic.id.to_s).nil?
end end
#find synapses between topics in alltopics array # find synapses between topics in alltopics array
allsynapses = policy_scope(Synapse.for_topic(@topic.id)).to_a allsynapses = policy_scope(Synapse.for_topic(@topic.id)).to_a
synapse_ids = (allsynapses.map(&:node1_id) + allsynapses.map(&:node2_id)).uniq synapse_ids = (allsynapses.map(&:node1_id) + allsynapses.map(&:node2_id)).uniq
allsynapses.delete_if do |synapse| allsynapses.delete_if do |synapse|
synapse_ids.index(synapse.id) != nil !synapse_ids.index(synapse.id).nil?
end end
creatorsAlreadyHas = params[:creators] ? params[:creators].split(',').map(&:to_i) : [] creatorsAlreadyHas = params[:creators] ? params[:creators].split(',').map(&:to_i) : []
allcreators = (alltopics.map(&:user) + allsynapses.map(&:user)).uniq.delete_if do |user| allcreators = (alltopics.map(&:user) + allsynapses.map(&:user)).uniq.delete_if do |user|
creatorsAlreadyHas.index(user.id) != nil !creatorsAlreadyHas.index(user.id).nil?
end end
@json = Hash.new() @json = {}
@json['topics'] = alltopics @json['topics'] = alltopics
@json['synapses'] = allsynapses @json['synapses'] = allsynapses
@json['creators'] = allcreators @json['creators'] = allcreators

View file

@ -1,5 +1,6 @@
class Users::PasswordsController < Devise::PasswordsController class Users::PasswordsController < Devise::PasswordsController
protected protected
def after_resetting_password_path_for(resource) def after_resetting_password_path_for(resource)
signed_in_root_path(resource) signed_in_root_path(resource)
end end

View file

@ -3,6 +3,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
before_action :configure_account_update_params, only: [:update] before_action :configure_account_update_params, only: [:update]
protected protected
def after_sign_up_path_for(resource) def after_sign_up_path_for(resource)
signed_in_root_path(resource) signed_in_root_path(resource)
end end
@ -12,6 +13,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
end end
private private
def configure_sign_up_params def configure_sign_up_params
devise_parameter_sanitizer.for(:sign_up) << [:name, :joinedwithcode] devise_parameter_sanitizer.for(:sign_up) << [:name, :joinedwithcode]
end end

View file

@ -20,19 +20,17 @@ class UsersController < ApplicationController
def update def update
@user = current_user @user = current_user
if user_params[:password] == "" && user_params[:password_confirmation] == "" if user_params[:password] == '' && user_params[:password_confirmation] == ''
# not trying to change the password # not trying to change the password
if @user.update_attributes(user_params.except(:password, :password_confirmation)) if @user.update_attributes(user_params.except(:password, :password_confirmation))
if params[:remove_image] == "1" @user.image = nil if params[:remove_image] == '1'
@user.image = nil
end
@user.save @user.save
sign_in(@user, :bypass => true) sign_in(@user, bypass: true)
respond_to do |format| respond_to do |format|
format.html { redirect_to root_url, notice: "Account updated!" } format.html { redirect_to root_url, notice: 'Account updated!' }
end end
else else
sign_in(@user, :bypass => true) sign_in(@user, bypass: true)
respond_to do |format| respond_to do |format|
format.html { redirect_to edit_user_path(@user), notice: @user.errors.to_a[0] } format.html { redirect_to edit_user_path(@user), notice: @user.errors.to_a[0] }
end end
@ -42,23 +40,21 @@ 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)
if params[:remove_image] == "1" @user.image = nil if params[:remove_image] == '1'
@user.image = nil
end
@user.save @user.save
sign_in(@user, :bypass => true) sign_in(@user, bypass: true)
respond_to do |format| respond_to do |format|
format.html { redirect_to root_url, notice: "Account updated!" } format.html { redirect_to root_url, notice: 'Account updated!' }
end end
else else
respond_to do |format| respond_to do |format|
if correct_pass if correct_pass
u = User.find(@user.id) u = User.find(@user.id)
sign_in(u, :bypass => true) sign_in(u, bypass: true)
format.html { redirect_to edit_user_path(@user), notice: @user.errors.to_a[0] } format.html { redirect_to edit_user_path(@user), notice: @user.errors.to_a[0] }
else else
sign_in(@user, :bypass => true) sign_in(@user, bypass: true)
format.html { redirect_to edit_user_path(@user), notice: "Incorrect current password" } format.html { redirect_to edit_user_path(@user), notice: 'Incorrect current password' }
end end
end end
end end
@ -69,10 +65,10 @@ class UsersController < ApplicationController
def details def details
@user = User.find(params[:id]) @user = User.find(params[:id])
@details = Hash.new @details = {}
@details['name'] = @user.name @details['name'] = @user.name
@details['created_at'] = @user.created_at.strftime("%m/%d/%Y") @details['created_at'] = @user.created_at.strftime('%m/%d/%Y')
@details['image'] = @user.image.url(:ninetysix) @details['image'] = @user.image.url(:ninetysix)
@details['generation'] = @user.generation @details['generation'] = @user.generation
@details['numSynapses'] = @user.synapses.count @details['numSynapses'] = @user.synapses.count
@ -87,7 +83,7 @@ class UsersController < ApplicationController
@user = current_user @user = current_user
@m = params[:metacodes][:value] @m = params[:metacodes][:value]
@user.settings.metacodes=@m.split(',') @user.settings.metacodes = @m.split(',')
@user.save @user.save

View file

@ -1,22 +1,22 @@
module ApplicationHelper module ApplicationHelper
def get_metacodeset def get_metacodeset
@m = current_user.settings.metacodes @m = current_user.settings.metacodes
set = @m[0].include?("metacodeset") ? MetacodeSet.find(@m[0].sub("metacodeset-","").to_i) : false set = @m[0].include?('metacodeset') ? MetacodeSet.find(@m[0].sub('metacodeset-', '').to_i) : false
return set set
end end
def user_metacodes def user_metacodes
@m = current_user.settings.metacodes @m = current_user.settings.metacodes
set = get_metacodeset set = get_metacodeset
if set @metacodes = if set
@metacodes = set.metacodes.to_a set.metacodes.to_a
else else
@metacodes = Metacode.where(id: @m).to_a Metacode.where(id: @m).to_a
end end
@metacodes.sort! {|m1,m2| m2.name.downcase <=> m1.name.downcase }.rotate!(-1) @metacodes.sort! { |m1, m2| m2.name.downcase <=> m1.name.downcase }.rotate!(-1)
end end
def determine_invite_link def determine_invite_link
"#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : "") "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '')
end end
end end

View file

@ -1,26 +1,9 @@
module DeviseHelper module DeviseHelper
def devise_error_messages! def devise_error_messages!
resource.errors.to_a[0]
message = resource.errors.to_a[0]
#return "" if resource.errors.empty?
#messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
#sentence = I18n.t("errors.messages.not_saved",
# :count => resource.errors.count,
# :resource => resource.class.model_name.human.downcase)
#html = <<-HTML
#<div id="error_explanation">
# <h2>#{sentence}</h2>
# <ul>#{messages}</ul>
#</div>
#HTML
#html.html_safe
end end
def devise_error_messages? def devise_error_messages?
resource.errors.empty? ? false : true resource.errors.empty? ? false : true
end end
end end

View file

@ -1,5 +1,4 @@
module MapsHelper module MapsHelper
## this one is for building our custom JSON autocomplete format for typeahead ## this one is for building our custom JSON autocomplete format for typeahead
def autocomplete_map_array_json(maps) def autocomplete_map_array_json(maps)
temp = [] temp = []
@ -13,13 +12,13 @@ module MapsHelper
map['topicCount'] = m.topics.count map['topicCount'] = m.topics.count
map['synapseCount'] = m.synapses.count map['synapseCount'] = m.synapses.count
map['contributorCount'] = m.contributors.count map['contributorCount'] = m.contributors.count
map['rtype'] = "map" map['rtype'] = 'map'
contributorTip = '' contributorTip = ''
firstContributorImage = 'https://s3.amazonaws.com/metamaps-assets/site/user.png' firstContributorImage = 'https://s3.amazonaws.com/metamaps-assets/site/user.png'
if m.contributors.count > 0 if m.contributors.count > 0
firstContributorImage = m.contributors[0].image.url(:thirtytwo) firstContributorImage = m.contributors[0].image.url(:thirtytwo)
m.contributors.each_with_index do |c, index| m.contributors.each_with_index do |c, _index|
userImage = c.image.url(:thirtytwo) userImage = c.image.url(:thirtytwo)
name = c.name name = c.name
contributorTip += '<li> <img class="tipUserImage" width="25" height="25" src=' + userImage + ' />' + '<span>' + name + '</span> </li>' contributorTip += '<li> <img class="tipUserImage" width="25" height="25" src=' + userImage + ' />' + '<span>' + name + '</span> </li>'
@ -30,7 +29,6 @@ module MapsHelper
temp.push map temp.push map
end end
return temp temp
end end
end end

View file

@ -1,6 +1,4 @@
module SynapsesHelper module SynapsesHelper
## this one is for building our custom JSON autocomplete format for typeahead ## this one is for building our custom JSON autocomplete format for typeahead
def autocomplete_synapse_generic_json(unique) def autocomplete_synapse_generic_json(unique)
temp = [] temp = []
@ -11,7 +9,7 @@ module SynapsesHelper
temp.push synapse temp.push synapse
end end
return temp temp
end end
## this one is for building our custom JSON autocomplete format for typeahead ## this one is for building our custom JSON autocomplete format for typeahead
@ -20,17 +18,16 @@ module SynapsesHelper
synapses.each do |s| synapses.each do |s|
synapse = {} synapse = {}
synapse['id'] = s.id synapse['id'] = s.id
synapse['label'] = s.desc == nil || s.desc == "" ? "(no description)" : s.desc synapse['label'] = s.desc.nil? || s.desc == '' ? '(no description)' : s.desc
synapse['value'] = s.desc synapse['value'] = s.desc
synapse['permission'] = s.permission synapse['permission'] = s.permission
synapse['mapCount'] = s.maps.count synapse['mapCount'] = s.maps.count
synapse['originator'] = s.user.name synapse['originator'] = s.user.name
synapse['originatorImage'] = s.user.image.url(:thirtytwo) synapse['originatorImage'] = s.user.image.url(:thirtytwo)
synapse['rtype'] = "synapse" synapse['rtype'] = 'synapse'
temp.push synapse temp.push synapse
end end
return temp temp
end end
end end

View file

@ -1,5 +1,4 @@
module TopicsHelper module TopicsHelper
## this one is for building our custom JSON autocomplete format for typeahead ## this one is for building our custom JSON autocomplete format for typeahead
def autocomplete_array_json(topics) def autocomplete_array_json(topics)
temp = [] temp = []
@ -16,39 +15,35 @@ module TopicsHelper
topic['synapseCount'] = t.synapses.count topic['synapseCount'] = t.synapses.count
topic['originator'] = t.user.name topic['originator'] = t.user.name
topic['originatorImage'] = t.user.image.url(:thirtytwo) topic['originatorImage'] = t.user.image.url(:thirtytwo)
topic['rtype'] = "topic" topic['rtype'] = 'topic'
topic['inmaps'] = t.inmaps topic['inmaps'] = t.inmaps
topic['inmapsLinks'] = t.inmapsLinks topic['inmapsLinks'] = t.inmapsLinks
temp.push topic temp.push topic
end end
return temp temp
end end
#find all nodes in any given nodes network # find all nodes in any given nodes network
def network(node, array, count) def network(node, array, count)
# recurse starting with a node to find all connected nodes and return an array of topics that constitutes the starting nodes network # recurse starting with a node to find all connected nodes and return an array of topics that constitutes the starting nodes network
# if the array of nodes is empty initialize it # if the array of nodes is empty initialize it
if array.nil? array = [] if array.nil?
array = Array.new
end
# add the node to the array # add the node to the array
array.push(node) array.push(node)
if count == 0 return array if count == 0
return array
end
count = count - 1 count -= 1
# check if each relative is already in the array and if not, call the network function again # check if each relative is already in the array and if not, call the network function again
if not node.relatives.empty? if !node.relatives.empty?
if (node.relatives-array).empty? if (node.relatives - array).empty?
return array return array
else else
(node.relatives-array).each do |relative| (node.relatives - array).each do |relative|
array = (array | network(relative, array, count)) array = (array | network(relative, array, count))
end end
return array return array

View file

@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base class ApplicationMailer < ActionMailer::Base
default from: "team@metamaps.cc" default from: 'team@metamaps.cc'
layout 'mailer' layout 'mailer'
end end

View file

@ -1,5 +1,5 @@
class MapMailer < ApplicationMailer class MapMailer < ApplicationMailer
default from: "team@metamaps.cc" default from: 'team@metamaps.cc'
def invite_to_edit_email(map, inviter, invitee) def invite_to_edit_email(map, inviter, invitee)
@inviter = inviter @inviter = inviter

View file

@ -1,7 +1,7 @@
class Event < ActiveRecord::Base class Event < ActiveRecord::Base
KINDS = %w[user_present_on_map conversation_started_on_map topic_added_to_map synapse_added_to_map] KINDS = %w(user_present_on_map conversation_started_on_map topic_added_to_map synapse_added_to_map).freeze
#has_many :notifications, dependent: :destroy # has_many :notifications, dependent: :destroy
belongs_to :eventable, polymorphic: true belongs_to :eventable, polymorphic: true
belongs_to :map belongs_to :map
belongs_to :user belongs_to :user
@ -10,22 +10,21 @@ class Event < ActiveRecord::Base
after_create :notify_webhooks!, if: :map after_create :notify_webhooks!, if: :map
validates_inclusion_of :kind, :in => KINDS validates :kind, inclusion: { in: KINDS }
validates_presence_of :eventable validates :eventable, presence: true
#def notify!(user) # def notify!(user)
# notifications.create!(user: user) # notifications.create!(user: user)
#end # end
def belongs_to?(this_user) def belongs_to?(this_user)
self.user_id == this_user.id user_id == this_user.id
end end
def notify_webhooks! def notify_webhooks!
#group = self.discussion.group # group = self.discussion.group
self.map.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self } map.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self }
#group.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self } # group.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self }
end end
handle_asynchronously :notify_webhooks! handle_asynchronously :notify_webhooks!
end end

View file

@ -1,18 +1,10 @@
class Events::ConversationStartedOnMap < Event class Events::ConversationStartedOnMap < Event
#after_create :notify_users! # after_create :notify_users!
def self.publish!(map, user) def self.publish!(map, user)
create!(kind: "conversation_started_on_map", create!(kind: 'conversation_started_on_map',
eventable: map, eventable: map,
map: map, map: map,
user: user) user: user)
end end
private
#def notify_users!
# unless comment_vote.user == comment_vote.comment_user
# notify!(comment_vote.comment_user)
# end
#end
end end

View file

@ -1,18 +1,10 @@
class Events::NewMapping < Event class Events::NewMapping < Event
#after_create :notify_users! # after_create :notify_users!
def self.publish!(mapping, user) def self.publish!(mapping, user)
create!(kind: mapping.mappable_type == "Topic" ? "topic_added_to_map" : "synapse_added_to_map", create!(kind: mapping.mappable_type == 'Topic' ? 'topic_added_to_map' : 'synapse_added_to_map',
eventable: mapping, eventable: mapping,
map: mapping.map, map: mapping.map,
user: user) user: user)
end end
private
#def notify_users!
# unless comment_vote.user == comment_vote.comment_user
# notify!(comment_vote.comment_user)
# end
#end
end end

View file

@ -1,18 +1,10 @@
class Events::UserPresentOnMap < Event class Events::UserPresentOnMap < Event
#after_create :notify_users! # after_create :notify_users!
def self.publish!(map, user) def self.publish!(map, user)
create!(kind: "user_present_on_map", create!(kind: 'user_present_on_map',
eventable: map, eventable: map,
map: map, map: map,
user: user) user: user)
end end
private
#def notify_users!
# unless comment_vote.user == comment_vote.comment_user
# notify!(comment_vote.comment_user)
# end
#end
end end

View file

@ -1,4 +1,4 @@
class InMetacodeSet < ActiveRecord::Base class InMetacodeSet < ActiveRecord::Base
belongs_to :metacode, :class_name => "Metacode", :foreign_key => "metacode_id" belongs_to :metacode, class_name: 'Metacode', foreign_key: 'metacode_id'
belongs_to :metacode_set, :class_name => "MetacodeSet", :foreign_key => "metacode_set_id" belongs_to :metacode_set, class_name: 'MetacodeSet', foreign_key: 'metacode_set_id'
end end

View file

@ -1,11 +1,10 @@
class Map < ActiveRecord::Base class Map < ActiveRecord::Base
belongs_to :user belongs_to :user
has_many :topicmappings, -> { Mapping.topicmapping }, class_name: :Mapping, dependent: :destroy has_many :topicmappings, -> { Mapping.topicmapping }, class_name: :Mapping, dependent: :destroy
has_many :synapsemappings, -> { Mapping.synapsemapping }, class_name: :Mapping, dependent: :destroy has_many :synapsemappings, -> { Mapping.synapsemapping }, class_name: :Mapping, dependent: :destroy
has_many :topics, through: :topicmappings, source: :mappable, source_type: "Topic" has_many :topics, through: :topicmappings, source: :mappable, source_type: 'Topic'
has_many :synapses, through: :synapsemappings, source: :mappable, source_type: "Synapse" has_many :synapses, through: :synapsemappings, source: :mappable, source_type: 'Synapse'
has_many :messages, as: :resource, dependent: :destroy has_many :messages, as: :resource, dependent: :destroy
has_many :user_maps, dependent: :destroy has_many :user_maps, dependent: :destroy
@ -15,11 +14,11 @@ class Map < ActiveRecord::Base
has_many :events, -> { includes :user }, as: :eventable, dependent: :destroy has_many :events, -> { includes :user }, as: :eventable, dependent: :destroy
# This method associates the attribute ":image" with a file attachment # This method associates the attribute ":image" with a file attachment
has_attached_file :screenshot, :styles => { has_attached_file :screenshot, styles: {
:thumb => ['188x126#', :png] thumb: ['188x126#', :png]
#:full => ['940x630#', :png] #:full => ['940x630#', :png]
}, },
:default_url => 'https://s3.amazonaws.com/metamaps-assets/site/missing-map.png' default_url: 'https://s3.amazonaws.com/metamaps-assets/site/missing-map.png'
validates :name, presence: true validates :name, presence: true
validates :arranged, inclusion: { in: [true, false] } validates :arranged, inclusion: { in: [true, false] }
@ -27,7 +26,7 @@ class Map < ActiveRecord::Base
validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) } validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) }
# Validate the attached image is image/jpg, image/png, etc # Validate the attached image is image/jpg, image/png, etc
validates_attachment_content_type :screenshot, :content_type => /\Aimage\/.*\Z/ validates_attachment_content_type :screenshot, content_type: /\Aimage\/.*\Z/
def mappings def mappings
topicmappings + synapsemappings topicmappings + synapsemappings
@ -37,19 +36,19 @@ class Map < ActiveRecord::Base
Perm.short(permission) Perm.short(permission)
end end
#return an array of the contributors to the map # return an array of the contributors to the map
def contributors def contributors
contributors = [] contributors = []
self.mappings.each do |m| mappings.each do |m|
contributors.push(m.user) if !contributors.include?(m.user) contributors.push(m.user) unless contributors.include?(m.user)
end end
return contributors contributors
end end
def editors def editors
collaborators + [self.user] collaborators + [user]
end end
def topic_count def topic_count
@ -60,9 +59,7 @@ class Map < ActiveRecord::Base
synapses.length synapses.length
end end
def user_name delegate :name, to: :user, prefix: true
user.name
end
def user_image def user_image
user.image.url user.image.url
@ -81,15 +78,15 @@ class Map < ActiveRecord::Base
end end
def created_at_str def created_at_str
created_at.strftime("%m/%d/%Y") created_at.strftime('%m/%d/%Y')
end end
def updated_at_str def updated_at_str
updated_at.strftime("%m/%d/%Y") updated_at.strftime('%m/%d/%Y')
end end
def as_json(options={}) def as_json(_options = {})
json = super(:methods =>[:user_name, :user_image, :topic_count, :synapse_count, :contributor_count, :collaborator_ids, :screenshot_url], :except => [:screenshot_content_type, :screenshot_file_size, :screenshot_file_name, :screenshot_updated_at]) json = super(methods: [:user_name, :user_image, :topic_count, :synapse_count, :contributor_count, :collaborator_ids, :screenshot_url], except: [:screenshot_content_type, :screenshot_file_size, :screenshot_file_name, :screenshot_updated_at])
json[:created_at_clean] = created_at_str json[:created_at_clean] = created_at_str
json[:updated_at_clean] = updated_at_str json[:updated_at_clean] = updated_at_str
json json
@ -103,11 +100,10 @@ class Map < ActiveRecord::Base
attr_accessor :content_type, :original_filename attr_accessor :content_type, :original_filename
end end
data.content_type = "image/png" data.content_type = 'image/png'
data.original_filename = File.basename('map-' + self.id.to_s + '-screenshot.png') data.original_filename = File.basename('map-' + id.to_s + '-screenshot.png')
self.screenshot = data self.screenshot = data
self.save save
end end
end end

View file

@ -1,29 +1,25 @@
class Mapping < ActiveRecord::Base class Mapping < ActiveRecord::Base
scope :topicmapping, -> { where(mappable_type: :Topic) } scope :topicmapping, -> { where(mappable_type: :Topic) }
scope :synapsemapping, -> { where(mappable_type: :Synapse) } scope :synapsemapping, -> { where(mappable_type: :Synapse) }
belongs_to :mappable, polymorphic: true belongs_to :mappable, polymorphic: true
belongs_to :map, :class_name => "Map", :foreign_key => "map_id", touch: true belongs_to :map, class_name: 'Map', foreign_key: 'map_id', touch: true
belongs_to :user belongs_to :user
validates :xloc, presence: true, validates :xloc, presence: true,
unless: Proc.new { |m| m.mappable_type == 'Synapse' } unless: proc { |m| m.mappable_type == 'Synapse' }
validates :yloc, presence: true, validates :yloc, presence: true,
unless: Proc.new { |m| m.mappable_type == 'Synapse' } unless: proc { |m| m.mappable_type == 'Synapse' }
validates :map, presence: true validates :map, presence: true
validates :mappable, presence: true validates :mappable, presence: true
def user_name delegate :name, to: :user, prefix: true
self.user.name
end
def user_image def user_image
self.user.image.url user.image.url
end end
def as_json(options={}) def as_json(_options = {})
super(:methods =>[:user_name, :user_image]) super(methods: [:user_name, :user_image])
end end
end end

View file

@ -1,19 +1,15 @@
class Message < ActiveRecord::Base class Message < ActiveRecord::Base
belongs_to :user belongs_to :user
belongs_to :resource, polymorphic: true belongs_to :resource, polymorphic: true
def user_name delegate :name, to: :user, prefix: true
self.user.name
end
def user_image def user_image
self.user.image.url user.image.url
end end
def as_json(options={}) def as_json(_options = {})
json = super(:methods =>[:user_name, :user_image]) json = super(methods: [:user_name, :user_image])
json json
end end
end end

View file

@ -1,21 +1,21 @@
class Metacode < ActiveRecord::Base class Metacode < ActiveRecord::Base
has_many :in_metacode_sets has_many :in_metacode_sets
has_many :metacode_sets, :through => :in_metacode_sets has_many :metacode_sets, through: :in_metacode_sets
has_many :topics has_many :topics
# This method associates the attribute ":aws_icon" with a file attachment # This method associates the attribute ":aws_icon" with a file attachment
has_attached_file :aws_icon, :styles => { has_attached_file :aws_icon, styles: {
:ninetysix => ['96x96#', :png], ninetysix: ['96x96#', :png]
}, },
:default_url => 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png' default_url: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png'
# Validate the attached icon is image/jpg, image/png, etc # Validate the attached icon is image/jpg, image/png, etc
validates_attachment_content_type :aws_icon, :content_type => /\Aimage\/.*\Z/ validates_attachment_content_type :aws_icon, content_type: /\Aimage\/.*\Z/
validate :aws_xor_manual_icon validate :aws_xor_manual_icon
validate :manual_icon_https validate :manual_icon_https
before_create do before_create do
self.manual_icon = nil if self.manual_icon == "" self.manual_icon = nil if manual_icon == ''
end end
def icon(*args) def icon(*args)
@ -26,37 +26,37 @@ class Metacode < ActiveRecord::Base
end end
end end
def as_json(options={}) def as_json(options = {})
default = super(options) default = super(options)
default[:icon] = icon default[:icon] = icon
default.except('aws_icon_file_name', 'aws_icon_content_type', 'aws_icon_file_size', 'aws_icon_updated_at', 'manual_icon') default.except('aws_icon_file_name', 'aws_icon_content_type', 'aws_icon_file_size', 'aws_icon_updated_at', 'manual_icon')
end end
def hasSelected(user) def hasSelected(user)
return true if user.settings.metacodes.include? self.id.to_s return true if user.settings.metacodes.include? id.to_s
return false false
end end
def inMetacodeSet(metacode_set) def inMetacodeSet(metacode_set)
return true if self.metacode_sets.include? metacode_set return true if metacode_sets.include? metacode_set
return false false
end end
private private
def aws_xor_manual_icon def aws_xor_manual_icon
if aws_icon.blank? && manual_icon.blank? if aws_icon.blank? && manual_icon.blank?
errors.add(:base, "Either aws_icon or manual_icon is required") errors.add(:base, 'Either aws_icon or manual_icon is required')
end end
if aws_icon.present? && manual_icon.present? if aws_icon.present? && manual_icon.present?
errors.add(:base, "Specify aws_icon or manual_icon, not both") errors.add(:base, 'Specify aws_icon or manual_icon, not both')
end end
end end
def manual_icon_https def manual_icon_https
if manual_icon.present? if manual_icon.present?
unless manual_icon.starts_with? 'https' unless manual_icon.starts_with? 'https'
errors.add(:base, "Manual icon must begin with https") errors.add(:base, 'Manual icon must begin with https')
end end
end end
end end

View file

@ -1,5 +1,5 @@
class MetacodeSet < ActiveRecord::Base class MetacodeSet < ActiveRecord::Base
belongs_to :user belongs_to :user
has_many :in_metacode_sets has_many :in_metacode_sets
has_many :metacodes, :through => :in_metacode_sets has_many :metacodes, through: :in_metacode_sets
end end

View file

@ -1,14 +1,13 @@
class PermittedParams < Struct.new(:params) class PermittedParams < Struct.new(:params)
%w(map synapse topic mapping token).each do |kind|
%w[map synapse topic mapping token].each do |kind|
define_method(kind) do define_method(kind) do
permitted_attributes = self.send("#{kind}_attributes") permitted_attributes = send("#{kind}_attributes")
params.require(kind).permit(*permitted_attributes) params.require(kind).permit(*permitted_attributes)
end end
alias_method :"api_#{kind}", kind.to_sym alias_method :"api_#{kind}", kind.to_sym
end end
alias :read_attribute_for_serialization :send alias read_attribute_for_serialization send
def token_attributes def token_attributes
[:description] [:description]
@ -29,5 +28,4 @@ class PermittedParams < Struct.new(:params)
def mapping_attributes def mapping_attributes
[:xloc, :yloc, :map_id, :mappable_type, :mappable_id] [:xloc, :yloc, :map_id, :mappable_type, :mappable_id]
end end
end end

View file

@ -1,12 +1,12 @@
class Synapse < ActiveRecord::Base class Synapse < ActiveRecord::Base
belongs_to :user belongs_to :user
belongs_to :defer_to_map, :class_name => 'Map', :foreign_key => 'defer_to_map_id' belongs_to :defer_to_map, class_name: 'Map', foreign_key: 'defer_to_map_id'
belongs_to :topic1, :class_name => "Topic", :foreign_key => "node1_id" belongs_to :topic1, class_name: 'Topic', foreign_key: 'node1_id'
belongs_to :topic2, :class_name => "Topic", :foreign_key => "node2_id" belongs_to :topic2, class_name: 'Topic', foreign_key: 'node2_id'
has_many :mappings, as: :mappable, dependent: :destroy has_many :mappings, as: :mappable, dependent: :destroy
has_many :maps, :through => :mappings has_many :maps, through: :mappings
validates :desc, length: { minimum: 0, allow_nil: false } validates :desc, length: { minimum: 0, allow_nil: false }
@ -18,13 +18,11 @@ class Synapse < ActiveRecord::Base
validates :category, inclusion: { in: ['from-to', 'both'], allow_nil: true } validates :category, inclusion: { in: ['from-to', 'both'], allow_nil: true }
scope :for_topic, ->(topic_id = nil) { scope :for_topic, ->(topic_id = nil) {
where("node1_id = ? OR node2_id = ?", topic_id, topic_id) where('node1_id = ? OR node2_id = ?', topic_id, topic_id)
} }
# :nocov: # :nocov:
def user_name delegate :name, to: :user, prefix: true
user.name
end
# :nocov: # :nocov:
# :nocov: # :nocov:
@ -36,7 +34,7 @@ class Synapse < ActiveRecord::Base
# :nocov: # :nocov:
def collaborator_ids def collaborator_ids
if defer_to_map if defer_to_map
defer_to_map.editors.select{|mapper| not mapper == self.user }.map(&:id) defer_to_map.editors.select { |mapper| mapper != user }.map(&:id)
else else
[] []
end end
@ -54,9 +52,8 @@ class Synapse < ActiveRecord::Base
# :nocov: # :nocov:
# :nocov: # :nocov:
def as_json(options={}) def as_json(_options = {})
super(:methods =>[:user_name, :user_image, :calculated_permission, :collaborator_ids]) super(methods: [:user_name, :user_image, :calculated_permission, :collaborator_ids])
end end
# :nocov: # :nocov:
end end

View file

@ -6,6 +6,7 @@ class Token < ActiveRecord::Base
CHARS = 32 CHARS = 32
private private
def assign_token def assign_token
self.token = generate_token self.token = generate_token
end end
@ -13,10 +14,7 @@ class Token < ActiveRecord::Base
def generate_token def generate_token
loop do loop do
candidate = SecureRandom.base64(CHARS).gsub(/\W/, '') candidate = SecureRandom.base64(CHARS).gsub(/\W/, '')
if candidate.size >= CHARS return candidate[0...CHARS] if candidate.size >= CHARS
return candidate[0...CHARS]
end end
end end
end
end end

View file

@ -2,15 +2,15 @@ class Topic < ActiveRecord::Base
include TopicsHelper include TopicsHelper
belongs_to :user belongs_to :user
belongs_to :defer_to_map, :class_name => 'Map', :foreign_key => 'defer_to_map_id' belongs_to :defer_to_map, class_name: 'Map', foreign_key: 'defer_to_map_id'
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', dependent: :destroy has_many :synapses1, class_name: 'Synapse', foreign_key: 'node1_id', dependent: :destroy
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', dependent: :destroy has_many :synapses2, class_name: 'Synapse', foreign_key: 'node2_id', dependent: :destroy
has_many :topics1, :through => :synapses2, source: :topic1 has_many :topics1, through: :synapses2, source: :topic1
has_many :topics2, :through => :synapses1, source: :topic2 has_many :topics2, through: :synapses1, source: :topic2
has_many :mappings, as: :mappable, dependent: :destroy has_many :mappings, as: :mappable, dependent: :destroy
has_many :maps, :through => :mappings has_many :maps, through: :mappings
belongs_to :metacode belongs_to :metacode
@ -20,19 +20,19 @@ class Topic < ActiveRecord::Base
# This method associates the attribute ":image" with a file attachment # This method associates the attribute ":image" with a file attachment
has_attached_file :image has_attached_file :image
#, styles: { # , styles: {
# thumb: '100x100>', # thumb: '100x100>',
# square: '200x200#', # square: '200x200#',
# medium: '300x300>' # medium: '300x300>'
#} # }
# Validate the attached image is image/jpg, image/png, etc # Validate the attached image is image/jpg, image/png, etc
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/ validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
# This method associates the attribute ":image" with a file attachment # This method associates the attribute ":image" with a file attachment
has_attached_file :audio has_attached_file :audio
# Validate the attached audio is audio/wav, audio/mp3, etc # Validate the attached audio is audio/wav, audio/mp3, etc
validates_attachment_content_type :audio, :content_type => /\Aaudio\/.*\Z/ validates_attachment_content_type :audio, content_type: /\Aaudio\/.*\Z/
def synapses def synapses
synapses1 + synapses2 synapses1 + synapses2
@ -54,9 +54,7 @@ class Topic < ActiveRecord::Base
.references(:synapses) .references(:synapses)
} }
def user_name delegate :name, to: :user, prefix: true
user.name
end
def user_image def user_image
user.image.url user.image.url
@ -86,19 +84,19 @@ class Topic < ActiveRecord::Base
end end
end end
def as_json(options={}) def as_json(_options = {})
super(:methods =>[:user_name, :user_image, :map_count, :synapse_count, :inmaps, :inmapsLinks, :calculated_permission, :collaborator_ids]) super(methods: [:user_name, :user_image, :map_count, :synapse_count, :inmaps, :inmapsLinks, :calculated_permission, :collaborator_ids])
end end
def collaborator_ids def collaborator_ids
if defer_to_map if defer_to_map
defer_to_map.editors.select{|mapper| not mapper == self.user }.map(&:id) defer_to_map.editors.select { |mapper| mapper != user }.map(&:id)
else else
[] []
end end
end end
# TODO move to a decorator? # TODO: move to a decorator?
def synapses_csv(output_format = 'array') def synapses_csv(output_format = 'array')
output = [] output = []
synapses.each do |synapse| synapses.each do |synapse|
@ -108,7 +106,7 @@ class Topic < ActiveRecord::Base
elsif synapse.node2_id == id elsif synapse.node2_id == id
output << synapse.node2_id.to_s + '<-' + synapse.node1_id.to_s output << synapse.node2_id.to_s + '<-' + synapse.node1_id.to_s
else else
fail 'invalid synapse on topic in synapse_csv' raise 'invalid synapse on topic in synapse_csv'
end end
elsif synapse.category == 'both' elsif synapse.category == 'both'
if synapse.node1_id == id if synapse.node1_id == id
@ -116,7 +114,7 @@ class Topic < ActiveRecord::Base
elsif synapse.node2_id == id elsif synapse.node2_id == id
output << synapse.node2_id.to_s + '<->' + synapse.node1_id.to_s output << synapse.node2_id.to_s + '<->' + synapse.node1_id.to_s
else else
fail 'invalid synapse on topic in synapse_csv' raise 'invalid synapse on topic in synapse_csv'
end end
end end
end end
@ -125,13 +123,13 @@ class Topic < ActiveRecord::Base
elsif output_format == 'text' elsif output_format == 'text'
return output.join('; ') return output.join('; ')
else else
fail 'invalid argument to synapses_csv' raise 'invalid argument to synapses_csv'
end end
output output
end end
def topic_autocomplete_method def topic_autocomplete_method
"Get: #{self.name}" "Get: #{name}"
end end
def mk_permission def mk_permission

View file

@ -1,7 +1,6 @@
require 'open-uri' require 'open-uri'
class User < ActiveRecord::Base class User < ActiveRecord::Base
has_many :topics has_many :topics
has_many :synapses has_many :synapses
has_many :maps has_many :maps
@ -16,40 +15,39 @@ class User < ActiveRecord::Base
serialize :settings, UserPreference serialize :settings, UserPreference
validates :password, :presence => true, validates :password, presence: true,
:length => { :within => 8..40 }, length: { within: 8..40 },
:on => :create on: :create
validates :password, :length => { :within => 8..40 }, validates :password, length: { within: 8..40 },
:allow_blank => true, allow_blank: true,
:on => :update on: :update
validates_confirmation_of :password validates :password, confirmation: true
validates_presence_of :name # done by devise validates :name, presence: true # done by devise
validates_presence_of :email # done by devise validates :email, presence: true # done by devise
validates_uniqueness_of :name # done by devise validates :name, uniqueness: true # done by devise
validates_uniqueness_of :email # done by devise validates :email, uniqueness: true # done by devise
validates :joinedwithcode, :presence => true, :inclusion => { :in => $codes, :message => "%{value} is not valid" }, :on => :create validates :joinedwithcode, presence: true, inclusion: { in: $codes, message: '%{value} is not valid' }, on: :create
# This method associates the attribute ":image" with a file attachment # This method associates the attribute ":image" with a file attachment
has_attached_file :image, :styles => { has_attached_file :image, styles: {
:thirtytwo => ['32x32#', :png], thirtytwo: ['32x32#', :png],
:sixtyfour => ['64x64#', :png], sixtyfour: ['64x64#', :png],
:ninetysix => ['96x96#', :png], ninetysix: ['96x96#', :png],
:onetwentyeight => ['128x128#', :png] onetwentyeight: ['128x128#', :png]
}, },
:default_url => 'https://s3.amazonaws.com/metamaps-assets/site/user.png' default_url: 'https://s3.amazonaws.com/metamaps-assets/site/user.png'
# Validate the attached image is image/jpg, image/png, etc # Validate the attached image is image/jpg, image/png, etc
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/ validates_attachment_content_type :image, content_type: %r(\Aimage/.*\Z)
# override default as_json # override default as_json
def as_json(options={}) def as_json(_options = {})
{ :id => self.id, { id: id,
:name => self.name, name: name,
:image => self.image.url(:sixtyfour), image: image.url(:sixtyfour),
:admin => self.admin admin: admin }
}
end end
def as_json_for_autocomplete def as_json_for_autocomplete
@ -60,12 +58,12 @@ class User < ActiveRecord::Base
json['profile'] = image.url(:sixtyfour) json['profile'] = image.url(:sixtyfour)
json['mapCount'] = maps.count json['mapCount'] = maps.count
json['generation'] = generation json['generation'] = generation
json['created_at'] = created_at.strftime("%m/%d/%Y") json['created_at'] = created_at.strftime('%m/%d/%Y')
json['rtype'] = "mapper" json['rtype'] = 'mapper'
json json
end end
#generate a random 8 letter/digit code that they can use to invite people # generate a random 8 letter/digit code that they can use to invite people
def generate_code def generate_code
self.code ||= rand(36**8).to_s(36) self.code ||= rand(36**8).to_s(36)
$codes.push(self.code) $codes.push(self.code)
@ -82,14 +80,11 @@ class User < ActiveRecord::Base
def settings def settings
# make sure we always return a UserPreference instance # make sure we always return a UserPreference instance
if read_attribute(:settings).nil? self[:settings] = UserPreference.new if self[:settings].nil?
write_attribute :settings, UserPreference.new self[:settings]
end
read_attribute :settings
end end
def settings=(val) def settings=(val)
write_attribute :settings, val self[:settings] = val
end end
end end

View file

@ -3,7 +3,7 @@ class UserPreference
def initialize def initialize
array = [] array = []
Metacode.all.each do |m| Metacode.all.find_each do |m|
array.push(m.id.to_s) array.push(m.id.to_s)
end end
@metacodes = array @metacodes = array

View file

@ -3,11 +3,10 @@ class Webhook < ActiveRecord::Base
validates :uri, presence: true validates :uri, presence: true
validates :hookable, presence: true validates :hookable, presence: true
validates_inclusion_of :kind, in: %w[slack] validates :kind, inclusion: { in: %w(slack) }
validates :event_types, length: { minimum: 1 } validates :event_types, length: { minimum: 1 }
def headers def headers
{} {}
end end
end end

View file

@ -2,15 +2,15 @@ Webhooks::Slack::Base = Struct.new(:event) do
include Routing include Routing
def username def username
"Metamaps Bot" 'Metamaps Bot'
end end
def icon_url def icon_url
"https://pbs.twimg.com/profile_images/539300245029392385/dJ1bwnw7.jpeg" 'https://pbs.twimg.com/profile_images/539300245029392385/dJ1bwnw7.jpeg'
end end
def text def text
"something" 'something'
end end
def attachments def attachments
@ -22,11 +22,11 @@ Webhooks::Slack::Base = Struct.new(:event) do
}] }]
end end
alias :read_attribute_for_serialization :send alias_method :read_attribute_for_serialization, :send
private private
#def motion_vote_field # def motion_vote_field
# { # {
# title: "Vote on this proposal", # title: "Vote on this proposal",
# value: "#{proposal_link(eventable, "yes")} · " + # value: "#{proposal_link(eventable, "yes")} · " +
@ -34,23 +34,23 @@ Webhooks::Slack::Base = Struct.new(:event) do
# "#{proposal_link(eventable, "no")} · " + # "#{proposal_link(eventable, "no")} · " +
# "#{proposal_link(eventable, "block")}" # "#{proposal_link(eventable, "block")}"
# } # }
#end # end
def view_map_on_metamaps(text = nil) def view_map_on_metamaps(text = nil)
"<#{map_url(event.map)}|#{text || event.map.name}>" "<#{map_url(event.map)}|#{text || event.map.name}>"
end end
#def view_discussion_on_loomio(params = {}) # def view_discussion_on_loomio(params = {})
# { value: discussion_link(I18n.t(:"webhooks.slack.view_it_on_loomio"), params) } # { value: discussion_link(I18n.t(:"webhooks.slack.view_it_on_loomio"), params) }
#end # end
#def proposal_link(proposal, position = nil) # def proposal_link(proposal, position = nil)
# discussion_link position || proposal.name, { proposal: proposal.key, position: position } # discussion_link position || proposal.name, { proposal: proposal.key, position: position }
#end # end
#def discussion_link(text = nil, params = {}) # def discussion_link(text = nil, params = {})
# "<#{discussion_url(eventable.map, params)}|#{text || eventable.discussion.title}>" # "<#{discussion_url(eventable.map, params)}|#{text || eventable.discussion.title}>"
#end # end
def eventable def eventable
@eventable ||= event.eventable @eventable ||= event.eventable
@ -59,10 +59,9 @@ Webhooks::Slack::Base = Struct.new(:event) do
def author def author
@author ||= eventable.author @author ||= eventable.author
end end
end end
#webhooks: # webhooks:
# slack: # slack:
# motion_closed: "*%{name}* has closed" # motion_closed: "*%{name}* has closed"
# motion_closing_soon: "*%{name}* has a proposal closing in 24 hours" # motion_closing_soon: "*%{name}* has a proposal closing in 24 hours"

View file

@ -1,27 +1,25 @@
class Webhooks::Slack::ConversationStartedOnMap < Webhooks::Slack::Base class Webhooks::Slack::ConversationStartedOnMap < Webhooks::Slack::Base
def text def text
"There is a live conversation starting on map *#{event.map.name}*. #{view_map_on_metamaps('Join in!')}" "There is a live conversation starting on map *#{event.map.name}*. #{view_map_on_metamaps('Join in!')}"
end end
# todo: it would be sweet if it sends it with the metacode as the icon_url # TODO: it would be sweet if it sends it with the metacode as the icon_url
def attachment_fallback def attachment_fallback
"" #{}"*#{eventable.name}*\n#{eventable.description}\n" '' # {}"*#{eventable.name}*\n#{eventable.description}\n"
end end
def attachment_title def attachment_title
"" #proposal_link(eventable) '' # proposal_link(eventable)
end end
def attachment_text def attachment_text
"" # "#{eventable.description}\n" '' # "#{eventable.description}\n"
end end
def attachment_fields def attachment_fields
[{ [{
title: "nothing", title: 'nothing',
value: "nothing" value: 'nothing'
}] #[motion_vote_field] }] # [motion_vote_field]
end end
end end

View file

@ -1,26 +1,24 @@
class Webhooks::Slack::SynapseAddedToMap < Webhooks::Slack::Base class Webhooks::Slack::SynapseAddedToMap < Webhooks::Slack::Base
def text def text
"\"*#{eventable.mappable.topic1.name}* #{eventable.mappable.desc || '->'} *#{eventable.mappable.topic2.name}*\" was added as a connection to the map *#{view_map_on_metamaps()}*" "\"*#{eventable.mappable.topic1.name}* #{eventable.mappable.desc || '->'} *#{eventable.mappable.topic2.name}*\" was added as a connection to the map *#{view_map_on_metamaps}*"
end end
def attachment_fallback def attachment_fallback
"" #{}"*#{eventable.name}*\n#{eventable.description}\n" '' # {}"*#{eventable.name}*\n#{eventable.description}\n"
end end
def attachment_title def attachment_title
"" #proposal_link(eventable) '' # proposal_link(eventable)
end end
def attachment_text def attachment_text
"" # "#{eventable.description}\n" '' # "#{eventable.description}\n"
end end
def attachment_fields def attachment_fields
[{ [{
title: "nothing", title: 'nothing',
value: "nothing" value: 'nothing'
}] #[motion_vote_field] }] # [motion_vote_field]
end end
end end

View file

@ -1,27 +1,25 @@
class Webhooks::Slack::TopicAddedToMap < Webhooks::Slack::Base class Webhooks::Slack::TopicAddedToMap < Webhooks::Slack::Base
def text def text
"New #{eventable.mappable.metacode.name} topic *#{eventable.mappable.name}* was added to the map *#{view_map_on_metamaps()}*" "New #{eventable.mappable.metacode.name} topic *#{eventable.mappable.name}* was added to the map *#{view_map_on_metamaps}*"
end end
# todo: it would be sweet if it sends it with the metacode as the icon_url # TODO: it would be sweet if it sends it with the metacode as the icon_url
def attachment_fallback def attachment_fallback
"" #{}"*#{eventable.name}*\n#{eventable.description}\n" '' # {}"*#{eventable.name}*\n#{eventable.description}\n"
end end
def attachment_title def attachment_title
"" #proposal_link(eventable) '' # proposal_link(eventable)
end end
def attachment_text def attachment_text
"" # "#{eventable.description}\n" '' # "#{eventable.description}\n"
end end
def attachment_fields def attachment_fields
[{ [{
title: "nothing", title: 'nothing',
value: "nothing" value: 'nothing'
}] #[motion_vote_field] }] # [motion_vote_field]
end end
end end

View file

@ -1,27 +1,25 @@
class Webhooks::Slack::UserPresentOnMap < Webhooks::Slack::Base class Webhooks::Slack::UserPresentOnMap < Webhooks::Slack::Base
def text def text
"Mapper *#{event.user.name}* has joined the map *#{event.map.name}*. #{view_map_on_metamaps('Map with them')}" "Mapper *#{event.user.name}* has joined the map *#{event.map.name}*. #{view_map_on_metamaps('Map with them')}"
end end
# todo: it would be sweet if it sends it with the metacode as the icon_url # TODO: it would be sweet if it sends it with the metacode as the icon_url
def attachment_fallback def attachment_fallback
"" #{}"*#{eventable.name}*\n#{eventable.description}\n" '' # {}"*#{eventable.name}*\n#{eventable.description}\n"
end end
def attachment_title def attachment_title
"" #proposal_link(eventable) '' # proposal_link(eventable)
end end
def attachment_text def attachment_text
"" # "#{eventable.description}\n" '' # "#{eventable.description}\n"
end end
def attachment_fields def attachment_fields
[{ [{
title: "nothing", title: 'nothing',
value: "nothing" value: 'nothing'
}] #[motion_vote_field] }] # [motion_vote_field]
end end
end end

View file

@ -11,7 +11,7 @@ class ApplicationPolicy
end end
def show? def show?
scope.where(:id => record.id).exists? scope.where(id: record.id).exists?
end end
def create? def create?
@ -34,7 +34,7 @@ class ApplicationPolicy
false false
end end
# TODO update this function to enable some flag in the interface # TODO: update this function to enable some flag in the interface
# so that admins usually can't do super admin stuff unless they # so that admins usually can't do super admin stuff unless they
# explicitly say they want to (E.g. seeing/editing/deleting private # explicitly say they want to (E.g. seeing/editing/deleting private
# maps - they should be able to, but not by accident) # maps - they should be able to, but not by accident)

View file

@ -1,5 +1,5 @@
class MainPolicy < ApplicationPolicy class MainPolicy < ApplicationPolicy
def initialize(user, record) def initialize(user, _record)
@user = user @user = user
@record = nil @record = nil
end end

View file

@ -1,7 +1,7 @@
class MapPolicy < ApplicationPolicy class MapPolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
visible = ['public', 'commons'] visible = %w(public commons)
permission = 'maps.permission IN (?)' permission = 'maps.permission IN (?)'
if user if user
shared_maps = user.shared_maps.map(&:id) shared_maps = user.shared_maps.map(&:id)

View file

@ -1,11 +1,11 @@
class MappingPolicy < ApplicationPolicy class MappingPolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
# TODO base this on the map policy # TODO: base this on the map policy
# it would be nice if we could also base this on the mappable, but that # it would be nice if we could also base this on the mappable, but that
# gets really complicated. Devin thinks it's OK to SHOW a mapping for # gets really complicated. Devin thinks it's OK to SHOW a mapping for
# a private topic, since you can't see the private topic anyways # a private topic, since you can't see the private topic anyways
visible = ['public', 'commons'] visible = %w(public commons)
permission = 'maps.permission IN (?)' permission = 'maps.permission IN (?)'
if user if user
scope.joins(:maps).where(permission + ' OR maps.user_id = ?', visible, user.id) scope.joins(:maps).where(permission + ' OR maps.user_id = ?', visible, user.id)

View file

@ -1,7 +1,7 @@
class MessagePolicy < ApplicationPolicy class MessagePolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
visible = ['public', 'commons'] visible = %w(public commons)
permission = 'maps.permission IN (?)' permission = 'maps.permission IN (?)'
if user if user
scope.joins(:maps).where(permission + ' OR maps.user_id = ?', visible, user.id) scope.joins(:maps).where(permission + ' OR maps.user_id = ?', visible, user.id)
@ -11,9 +11,7 @@ class MessagePolicy < ApplicationPolicy
end end
end end
def show? delegate :show?, to: :resource_policy
resource_policy.show?
end
def create? def create?
record.resource.present? && resource_policy.update? record.resource.present? && resource_policy.update?
@ -32,5 +30,4 @@ class MessagePolicy < ApplicationPolicy
def resource_policy def resource_policy
@resource_policy ||= Pundit.policy(user, record.resource) @resource_policy ||= Pundit.policy(user, record.resource)
end end
end end

View file

@ -1,7 +1,7 @@
class SynapsePolicy < ApplicationPolicy class SynapsePolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
visible = ['public', 'commons'] visible = %w(public commons)
permission = 'synapses.permission IN (?)' permission = 'synapses.permission IN (?)'
if user if user
scope.where(permission + ' OR synapses.defer_to_map_id IN (?) OR synapses.user_id = ?', visible, user.shared_maps.map(&:id), user.id) scope.where(permission + ' OR synapses.defer_to_map_id IN (?) OR synapses.user_id = ?', visible, user.shared_maps.map(&:id), user.id)
@ -13,7 +13,7 @@ class SynapsePolicy < ApplicationPolicy
def create? def create?
user.present? user.present?
# todo add validation against whether you can see both topics # TODO: add validation against whether you can see both topics
end end
def show? def show?
@ -25,7 +25,7 @@ class SynapsePolicy < ApplicationPolicy
end end
def update? def update?
if not user.present? if !user.present?
false false
elsif record.defer_to_map.present? elsif record.defer_to_map.present?
map_policy.update? map_policy.update?

View file

@ -4,7 +4,7 @@ class TokenPolicy < ApplicationPolicy
if user if user
scope.where('tokens.user_id = ?', user.id) scope.where('tokens.user_id = ?', user.id)
else else
scope.where(:id => nil).where("id IS NOT ?", nil) # to just return none scope.where(id: nil).where('id IS NOT ?', nil) # to just return none
end end
end end
end end
@ -20,5 +20,4 @@ class TokenPolicy < ApplicationPolicy
def destroy? def destroy?
user.present? && record.user == user user.present? && record.user == user
end end
end end

View file

@ -1,7 +1,7 @@
class TopicPolicy < ApplicationPolicy class TopicPolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
visible = ['public', 'commons'] visible = %w(public commons)
permission = 'topics.permission IN (?)' permission = 'topics.permission IN (?)'
if user if user
scope.where(permission + ' OR topics.defer_to_map_id IN (?) OR topics.user_id = ?', visible, user.shared_maps.map(&:id), user.id) scope.where(permission + ' OR topics.defer_to_map_id IN (?) OR topics.user_id = ?', visible, user.shared_maps.map(&:id), user.id)
@ -24,7 +24,7 @@ class TopicPolicy < ApplicationPolicy
end end
def update? def update?
if not user.present? if !user.present?
false false
elsif record.defer_to_map.present? elsif record.defer_to_map.present?
map_policy.update? map_policy.update?

View file

@ -13,5 +13,4 @@ class NewMapSerializer < ActiveModel::Serializer
has_many :mappings, serializer: NewMappingSerializer has_many :mappings, serializer: NewMappingSerializer
has_many :contributors, root: :users, serializer: NewUserSerializer has_many :contributors, root: :users, serializer: NewUserSerializer
has_many :collaborators, root: :users, serializer: NewUserSerializer has_many :collaborators, root: :users, serializer: NewUserSerializer
end end

View file

@ -12,8 +12,8 @@ class NewMappingSerializer < ActiveModel::Serializer
has_one :map, serializer: NewMapSerializer has_one :map, serializer: NewMapSerializer
def filter(keys) def filter(keys)
keys.delete(:xloc) unless object.mappable_type == "Topic" keys.delete(:xloc) unless object.mappable_type == 'Topic'
keys.delete(:yloc) unless object.mappable_type == "Topic" keys.delete(:yloc) unless object.mappable_type == 'Topic'
keys keys
end end
end end

View file

@ -11,5 +11,4 @@ class NewSynapseSerializer < ActiveModel::Serializer
has_one :topic1, root: :topics, serializer: NewTopicSerializer has_one :topic1, root: :topics, serializer: NewTopicSerializer
has_one :topic2, root: :topics, serializer: NewTopicSerializer has_one :topic2, root: :topics, serializer: NewTopicSerializer
has_one :user, serializer: NewUserSerializer has_one :user, serializer: NewUserSerializer
end end

View file

@ -10,5 +10,4 @@ class NewTopicSerializer < ActiveModel::Serializer
has_one :user, serializer: NewUserSerializer has_one :user, serializer: NewUserSerializer
has_one :metacode, serializer: NewMetacodeSerializer has_one :metacode, serializer: NewMetacodeSerializer
end end

View file

@ -4,5 +4,4 @@ class TokenSerializer < ActiveModel::Serializer
:description, :description,
:created_at, :created_at,
:updated_at :updated_at
end end

View file

@ -1,3 +1,3 @@
class WebhookSerializer < ActiveModel::Serializer class WebhookSerializer < ActiveModel::Serializer
attributes :text, :username, :icon_url #, :attachments attributes :text, :username, :icon_url # , :attachments
end end

View file

@ -24,6 +24,7 @@ class MapExportService < Struct.new(:user, :map)
def topic_headings def topic_headings
[:id, :name, :metacode, :x, :y, :description, :link, :user, :permission] [:id, :name, :metacode, :x, :y, :description, :link, :user, :permission]
end end
def synapse_headings def synapse_headings
[:topic1, :topic2, :category, :description, :user, :permission] [:topic1, :topic2, :category, :description, :user, :permission]
end end
@ -64,7 +65,7 @@ class MapExportService < Struct.new(:user, :map)
def to_spreadsheet def to_spreadsheet
spreadsheet = [] spreadsheet = []
spreadsheet << ["Topics"] spreadsheet << ['Topics']
spreadsheet << topic_headings.map(&:capitalize) spreadsheet << topic_headings.map(&:capitalize)
exportable_topics.each do |topics| exportable_topics.each do |topics|
# convert exportable_topics into an array of arrays # convert exportable_topics into an array of arrays
@ -72,7 +73,7 @@ class MapExportService < Struct.new(:user, :map)
end end
spreadsheet << [] spreadsheet << []
spreadsheet << ["Synapses"] spreadsheet << ['Synapses']
spreadsheet << synapse_headings.map(&:capitalize) spreadsheet << synapse_headings.map(&:capitalize)
exportable_synapses.each do |synapse| exportable_synapses.each do |synapse|
# convert exportable_synapses into an array of arrays # convert exportable_synapses into an array of arrays

View file

@ -1,32 +1,31 @@
class Perm class Perm
# e.g. Perm::ISSIONS # e.g. Perm::ISSIONS
ISSIONS = [:commons, :public, :private] ISSIONS = [:commons, :public, :private].freeze
class << self class << self
def short(permission) def short(permission)
case permission case permission
when :commons when :commons
"co" 'co'
when :public when :public
"pu" 'pu'
when :private when :private
"pr" 'pr'
else else
fail "Invalid permission" raise 'Invalid permission'
end end
end end
def long(perm) def long(perm)
case perm case perm
when "co" when 'co'
:commons :commons
when "pu" when 'pu'
:public :public
when "pr" when 'pr'
:private :private
else else
fail "Invalid short permission" raise 'Invalid short permission'
end end
end end

View file

@ -1,18 +1,16 @@
class WebhookService class WebhookService
def self.publish!(webhook:, event:) def self.publish!(webhook:, event:)
return false unless webhook.event_types.include? event.kind return false unless webhook.event_types.include? event.kind
HTTParty.post webhook.uri, body: payload_for(webhook, event), headers: webhook.headers HTTParty.post webhook.uri, body: payload_for(webhook, event), headers: webhook.headers
end end
private class << self
def payload_for(webhook, event)
def self.payload_for(webhook, event)
WebhookSerializer.new(webhook_object_for(webhook, event), root: false).to_json WebhookSerializer.new(webhook_object_for(webhook, event), root: false).to_json
end end
def self.webhook_object_for(webhook, event) def webhook_object_for(webhook, event)
"Webhooks::#{webhook.kind.classify}::#{event.kind.classify}".constantize.new(event) "Webhooks::#{webhook.kind.classify}::#{event.kind.classify}".constantize.new(event)
end end
end
end end

View file

@ -31,12 +31,12 @@ module Metamaps
# config.i18n.default_locale = :de # config.i18n.default_locale = :de
# Configure the default encoding used in templates for Ruby 1.9. # Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8" config.encoding = 'utf-8'
config.to_prepare do config.to_prepare do
Doorkeeper::ApplicationsController.layout "doorkeeper" Doorkeeper::ApplicationsController.layout 'doorkeeper'
Doorkeeper::AuthorizationsController.layout "doorkeeper" Doorkeeper::AuthorizationsController.layout 'doorkeeper'
Doorkeeper::AuthorizedApplicationsController.layout "doorkeeper" Doorkeeper::AuthorizedApplicationsController.layout 'doorkeeper'
Doorkeeper::ApplicationController.helper ApplicationHelper Doorkeeper::ApplicationController.helper ApplicationHelper
end end
@ -60,6 +60,6 @@ module Metamaps
config.active_record.raise_in_transactional_callbacks = true config.active_record.raise_in_transactional_callbacks = true
# pundit errors return 403 FORBIDDEN # pundit errors return 403 FORBIDDEN
config.action_dispatch.rescue_responses["Pundit::NotAuthorizedError"] = :forbidden config.action_dispatch.rescue_responses['Pundit::NotAuthorizedError'] = :forbidden
end end
end end

View file

@ -11,4 +11,4 @@ end
# Set up gems listed in the Gemfile. # Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])

View file

@ -33,8 +33,9 @@ Metamaps::Application.configure do
domain: ENV['SMTP_DOMAIN'], domain: ENV['SMTP_DOMAIN'],
authentication: 'plain', authentication: 'plain',
enable_starttls_auto: true, enable_starttls_auto: true,
openssl_verify_mode: 'none' } openssl_verify_mode: 'none'
config.action_mailer.default_url_options = { :host => 'localhost:3000' } }
config.action_mailer.default_url_options = { host: 'localhost:3000' }
# Don't care if the mailer can't send # Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = true config.action_mailer.raise_delivery_errors = true

View file

@ -20,10 +20,9 @@ Metamaps::Application.configure do
# Compress JavaScripts and CSS # Compress JavaScripts and CSS
config.assets.compress = true config.assets.compress = true
# S3 file storage # S3 file storage
config.paperclip_defaults = { config.paperclip_defaults = {
:storage => :s3, storage: :s3,
s3_credentials: { s3_credentials: {
bucket: ENV['S3_BUCKET_NAME'], bucket: ENV['S3_BUCKET_NAME'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'], access_key_id: ENV['AWS_ACCESS_KEY_ID'],
@ -38,11 +37,12 @@ Metamaps::Application.configure do
port: ENV['SMTP_PORT'], port: ENV['SMTP_PORT'],
user_name: ENV['SMTP_USERNAME'], user_name: ENV['SMTP_USERNAME'],
password: ENV['SMTP_PASSWORD'], password: ENV['SMTP_PASSWORD'],
#domain: ENV['SMTP_DOMAIN'] # domain: ENV['SMTP_DOMAIN']
authentication: 'plain', authentication: 'plain',
enable_starttls_auto: true, enable_starttls_auto: true,
openssl_verify_mode: 'none' } openssl_verify_mode: 'none'
config.action_mailer.default_url_options = { :host => ENV['MAILER_DEFAULT_URL'] } }
config.action_mailer.default_url_options = { host: ENV['MAILER_DEFAULT_URL'] }
# Don't care if the mailer can't send # Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = true config.action_mailer.raise_delivery_errors = true
@ -78,7 +78,7 @@ Metamaps::Application.configure do
# config.action_controller.asset_host = "http://assets.example.com" # config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
#config.assets.precompile += %w( ) # config.assets.precompile += %w( )
# Disable delivery errors, bad email addresses will be ignored # Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false # config.action_mailer.raise_delivery_errors = false

View file

@ -11,7 +11,7 @@ Metamaps::Application.configure do
# Configure static asset server for tests with Cache-Control for performance # Configure static asset server for tests with Cache-Control for performance
config.serve_static_files = true config.serve_static_files = true
config.static_cache_control = "public, max-age=3600" config.static_cache_control = 'public, max-age=3600'
# Show full error reports and disable caching # Show full error reports and disable caching
config.consider_all_requests_local = true config.consider_all_requests_local = true
@ -31,7 +31,7 @@ Metamaps::Application.configure do
# Print deprecation notices to the stderr # Print deprecation notices to the stderr
config.active_support.deprecation = :stderr config.active_support.deprecation = :stderr
#assets config # assets config
config.assets.compile = true config.assets.compile = true
config.assets.compress = false config.assets.compress = false
config.assets.debug = false config.assets.debug = false

View file

@ -1,4 +1,4 @@
$codes = [] $codes = []
if ActiveRecord::Base.connection.table_exists? 'users' if ActiveRecord::Base.connection.table_exists? 'users'
$codes = ActiveRecord::Base.connection.execute("SELECT code FROM users").map {|user| user["code"] } $codes = ActiveRecord::Base.connection.execute('SELECT code FROM users').map { |user| user['code'] }
end end

View file

@ -16,7 +16,6 @@ Devise.setup do |config|
# Configure the class responsible to send e-mails. # Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer" # config.mailer = "Devise::Mailer"
config.secret_key = ENV['DEVISE_SECRET_KEY'] config.secret_key = ENV['DEVISE_SECRET_KEY']
# ==> ORM configuration # ==> ORM configuration
@ -45,12 +44,12 @@ Devise.setup do |config|
# Configure which authentication keys should be case-insensitive. # Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used # These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email. # to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [ :email ] config.case_insensitive_keys = [:email]
# Configure which authentication keys should have whitespace stripped. # Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or # These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email. # modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [ :email ] config.strip_whitespace_keys = [:email]
# Tell if authentication through request.params is enabled. True by default. # Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the # It can be set to an array that will enable params authentication only for the

View file

@ -4,4 +4,4 @@
# Mime::Type.register "text/richtext", :rtf # Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone # Mime::Type.register_alias "text/html", :iphone
Mime::Type.register "application/xls", :xls Mime::Type.register 'application/xls', :xls

View file

@ -2,6 +2,6 @@ require 'uservoice-ruby'
def current_sso_token def current_sso_token
@current_sso_token ||= UserVoice.generate_sso_token('metamapscc', ENV['SSO_KEY'], { @current_sso_token ||= UserVoice.generate_sso_token('metamapscc', ENV['SSO_KEY'], {
:email => current_user.email email: current_user.email
}, 300) # Default expiry time is 5 minutes = 300 seconds }, 300) # Default expiry time is 5 minutes = 300 seconds
end end

View file

@ -1 +1 @@
METAMAPS_VERSION = '2.8.5' METAMAPS_VERSION = '2.8.5'.freeze

View file

@ -1,5 +1,4 @@
Metamaps::Application.routes.draw do Metamaps::Application.routes.draw do
use_doorkeeper use_doorkeeper
root to: 'main#home', via: :get root to: 'main#home', via: :get
@ -10,26 +9,26 @@ Metamaps::Application.routes.draw do
get 'search/mappers', to: 'main#searchmappers', as: :searchmappers get 'search/mappers', to: 'main#searchmappers', as: :searchmappers
get 'search/synapses', to: 'main#searchsynapses', as: :searchsynapses get 'search/synapses', to: 'main#searchsynapses', as: :searchsynapses
namespace :api, path: '/api/v1', defaults: {format: :json} do namespace :api, path: '/api/v1', defaults: { format: :json } do
resources :maps, only: [:create, :show, :update, :destroy] resources :maps, only: [:create, :show, :update, :destroy]
resources :synapses, only: [:create, :show, :update, :destroy] resources :synapses, only: [:create, :show, :update, :destroy]
resources :topics, only: [:create, :show, :update, :destroy] resources :topics, only: [:create, :show, :update, :destroy]
resources :mappings, only: [:create, :show, :update, :destroy] resources :mappings, only: [:create, :show, :update, :destroy]
resources :tokens, only: [ :create, :destroy] do resources :tokens, only: [:create, :destroy] do
get :my_tokens, on: :collection get :my_tokens, on: :collection
end end
end end
resources :messages, only: [:show, :create, :update, :destroy] resources :messages, only: [:show, :create, :update, :destroy]
resources :mappings, except: [:index, :new, :edit] resources :mappings, except: [:index, :new, :edit]
resources :metacode_sets, :except => [:show] resources :metacode_sets, except: [:show]
resources :metacodes, :except => [:destroy] resources :metacodes, except: [:destroy]
get 'metacodes/:name', to: 'metacodes#show' get 'metacodes/:name', to: 'metacodes#show'
resources :synapses, except: [:index, :new, :edit] resources :synapses, except: [:index, :new, :edit]
resources :topics, except: [:index, :new, :edit] do resources :topics, except: [:index, :new, :edit] do
get :autocomplete_topic, :on => :collection get :autocomplete_topic, on: :collection
end end
get 'topics/:id/network', to: 'topics#network', as: :network get 'topics/:id/network', to: 'topics#network', as: :network
get 'topics/:id/relative_numbers', to: 'topics#relative_numbers', as: :relative_numbers get 'topics/:id/relative_numbers', to: 'topics#relative_numbers', as: :relative_numbers
@ -40,7 +39,7 @@ Metamaps::Application.routes.draw do
post 'maps/:id/events/:event', to: 'maps#events' post 'maps/:id/events/:event', to: 'maps#events'
get 'maps/:id/contains', to: 'maps#contains', as: :contains get 'maps/:id/contains', to: 'maps#contains', as: :contains
post 'maps/:id/upload_screenshot', to: 'maps#screenshot', as: :screenshot post 'maps/:id/upload_screenshot', to: 'maps#screenshot', as: :screenshot
post 'maps/:id/access', to: 'maps#access', as: :access, defaults: {format: :json} post 'maps/:id/access', to: 'maps#access', as: :access, defaults: { format: :json }
get 'explore/active', to: 'maps#activemaps' get 'explore/active', to: 'maps#activemaps'
get 'explore/featured', to: 'maps#featuredmaps' get 'explore/featured', to: 'maps#featuredmaps'
@ -48,7 +47,7 @@ Metamaps::Application.routes.draw do
get 'explore/shared', to: 'maps#sharedmaps' get 'explore/shared', to: 'maps#sharedmaps'
get 'explore/mapper/:id', to: 'maps#usermaps' get 'explore/mapper/:id', to: 'maps#usermaps'
devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, :skip => :sessions devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, skip: :sessions
devise_scope :user do devise_scope :user do
get 'login' => 'devise/sessions#new', :as => :new_user_session get 'login' => 'devise/sessions#new', :as => :new_user_session

View file

@ -5,19 +5,19 @@ class MappingPolymorphism < ActiveRecord::Migration
add_index :mappings, [:mappable_id, :mappable_type] add_index :mappings, [:mappable_id, :mappable_type]
Mapping.find_each do |mapping| Mapping.find_each do |mapping|
if mapping.synapse_id.nil? and mapping.topic_id.nil? if mapping.synapse_id.nil? && mapping.topic_id.nil?
puts "Mapping id=#{mapping.id} has no valid id, skipping!" puts "Mapping id=#{mapping.id} has no valid id, skipping!"
next next
end end
if not mapping.synapse_id.nil? and not mapping.topic_id.nil? if !mapping.synapse_id.nil? && !mapping.topic_id.nil?
puts "Mapping id=#{mapping.id} has both topic and synapse ids, skipping!" puts "Mapping id=#{mapping.id} has both topic and synapse ids, skipping!"
next next
end end
unless mapping.synapse_id.nil? if mapping.synapse_id.nil?
mapping.mappable = Synapse.find_by(id: mapping.synapse_id)
else
mapping.mappable = Topic.find_by(id: mapping.topic_id) mapping.mappable = Topic.find_by(id: mapping.topic_id)
else
mapping.mappable = Synapse.find_by(id: mapping.synapse_id)
end end
if mapping.mappable.nil? if mapping.mappable.nil?

View file

@ -4,12 +4,11 @@ end
class MetacodeAssetPathUpdate < ActiveRecord::Migration class MetacodeAssetPathUpdate < ActiveRecord::Migration
def change def change
Metacode.first(50).each do |metacode| Metacode.first(50).each do |metacode|
if metacode.icon.start_with?("/assets/icons/") next unless metacode.icon.start_with?('/assets/icons/')
metacode.icon = metacode.icon.sub(/^\/assets\/icons/, "https://s3.amazonaws.com/metamaps-assets/metacodes") metacode.icon = metacode.icon.sub(/^\/assets\/icons/, 'https://s3.amazonaws.com/metamaps-assets/metacodes')
metacode.icon = metacode.icon.sub('blueprint_96px', 'blueprint/96px') metacode.icon = metacode.icon.sub('blueprint_96px', 'blueprint/96px')
metacode.icon = metacode.icon.sub('generics_96px', 'generics/96px') metacode.icon = metacode.icon.sub('generics_96px', 'generics/96px')
metacode.save metacode.save
end end
end end
end
end end

View file

@ -13,7 +13,7 @@ class CreateDelayedJobs < ActiveRecord::Migration
table.timestamps null: true table.timestamps null: true
end end
add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority" add_index :delayed_jobs, [:priority, :run_at], name: 'delayed_jobs_priority'
end end
def self.down def self.down

View file

@ -11,270 +11,269 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160401133937) do ActiveRecord::Schema.define(version: 20_160_401_133_937) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension 'plpgsql'
create_table "delayed_jobs", force: :cascade do |t| create_table 'delayed_jobs', force: :cascade do |t|
t.integer "priority", default: 0, null: false t.integer 'priority', default: 0, null: false
t.integer "attempts", default: 0, null: false t.integer 'attempts', default: 0, null: false
t.text "handler", null: false t.text 'handler', null: false
t.text "last_error" t.text 'last_error'
t.datetime "run_at" t.datetime 'run_at'
t.datetime "locked_at" t.datetime 'locked_at'
t.datetime "failed_at" t.datetime 'failed_at'
t.string "locked_by" t.string 'locked_by'
t.string "queue" t.string 'queue'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree add_index 'delayed_jobs', %w(priority run_at), name: 'delayed_jobs_priority', using: :btree
create_table "events", force: :cascade do |t| create_table 'events', force: :cascade do |t|
t.string "kind", limit: 255 t.string 'kind', limit: 255
t.integer "eventable_id" t.integer 'eventable_id'
t.string "eventable_type" t.string 'eventable_type'
t.integer "user_id" t.integer 'user_id'
t.integer "map_id" t.integer 'map_id'
t.integer "sequence_id" t.integer 'sequence_id'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "events", ["eventable_type", "eventable_id"], name: "index_events_on_eventable_type_and_eventable_id", using: :btree add_index 'events', %w(eventable_type eventable_id), name: 'index_events_on_eventable_type_and_eventable_id', using: :btree
add_index "events", ["map_id", "sequence_id"], name: "index_events_on_map_id_and_sequence_id", unique: true, using: :btree add_index 'events', %w(map_id sequence_id), name: 'index_events_on_map_id_and_sequence_id', unique: true, using: :btree
add_index "events", ["map_id"], name: "index_events_on_map_id", using: :btree add_index 'events', ['map_id'], name: 'index_events_on_map_id', using: :btree
add_index "events", ["sequence_id"], name: "index_events_on_sequence_id", using: :btree add_index 'events', ['sequence_id'], name: 'index_events_on_sequence_id', using: :btree
add_index "events", ["user_id"], name: "index_events_on_user_id", using: :btree add_index 'events', ['user_id'], name: 'index_events_on_user_id', using: :btree
create_table "in_metacode_sets", force: :cascade do |t| create_table 'in_metacode_sets', force: :cascade do |t|
t.integer "metacode_id" t.integer 'metacode_id'
t.integer "metacode_set_id" t.integer 'metacode_set_id'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
end end
add_index "in_metacode_sets", ["metacode_id"], name: "index_in_metacode_sets_on_metacode_id", using: :btree add_index 'in_metacode_sets', ['metacode_id'], name: 'index_in_metacode_sets_on_metacode_id', using: :btree
add_index "in_metacode_sets", ["metacode_set_id"], name: "index_in_metacode_sets_on_metacode_set_id", using: :btree add_index 'in_metacode_sets', ['metacode_set_id'], name: 'index_in_metacode_sets_on_metacode_set_id', using: :btree
create_table "mappings", force: :cascade do |t| create_table 'mappings', force: :cascade do |t|
t.text "category" t.text 'category'
t.integer "xloc" t.integer 'xloc'
t.integer "yloc" t.integer 'yloc'
t.integer "topic_id" t.integer 'topic_id'
t.integer "synapse_id" t.integer 'synapse_id'
t.integer "map_id" t.integer 'map_id'
t.integer "user_id" t.integer 'user_id'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
t.integer "mappable_id" t.integer 'mappable_id'
t.string "mappable_type" t.string 'mappable_type'
end end
add_index "mappings", ["map_id", "synapse_id"], name: "index_mappings_on_map_id_and_synapse_id", using: :btree add_index 'mappings', %w(map_id synapse_id), name: 'index_mappings_on_map_id_and_synapse_id', using: :btree
add_index "mappings", ["map_id", "topic_id"], name: "index_mappings_on_map_id_and_topic_id", using: :btree add_index 'mappings', %w(map_id topic_id), name: 'index_mappings_on_map_id_and_topic_id', using: :btree
add_index "mappings", ["map_id"], name: "index_mappings_on_map_id", using: :btree add_index 'mappings', ['map_id'], name: 'index_mappings_on_map_id', using: :btree
add_index "mappings", ["mappable_id", "mappable_type"], name: "index_mappings_on_mappable_id_and_mappable_type", using: :btree add_index 'mappings', %w(mappable_id mappable_type), name: 'index_mappings_on_mappable_id_and_mappable_type', using: :btree
add_index "mappings", ["user_id"], name: "index_mappings_on_user_id", using: :btree add_index 'mappings', ['user_id'], name: 'index_mappings_on_user_id', using: :btree
create_table "maps", force: :cascade do |t| create_table 'maps', force: :cascade do |t|
t.text "name" t.text 'name'
t.boolean "arranged" t.boolean 'arranged'
t.text "desc" t.text 'desc'
t.text "permission" t.text 'permission'
t.integer "user_id" t.integer 'user_id'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
t.boolean "featured" t.boolean 'featured'
t.string "screenshot_file_name" t.string 'screenshot_file_name'
t.string "screenshot_content_type" t.string 'screenshot_content_type'
t.integer "screenshot_file_size" t.integer 'screenshot_file_size'
t.datetime "screenshot_updated_at" t.datetime 'screenshot_updated_at'
end end
add_index "maps", ["user_id"], name: "index_maps_on_user_id", using: :btree add_index 'maps', ['user_id'], name: 'index_maps_on_user_id', using: :btree
create_table "messages", force: :cascade do |t| create_table 'messages', force: :cascade do |t|
t.text "message" t.text 'message'
t.integer "user_id" t.integer 'user_id'
t.integer "resource_id" t.integer 'resource_id'
t.string "resource_type" t.string 'resource_type'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "messages", ["resource_id"], name: "index_messages_on_resource_id", using: :btree add_index 'messages', ['resource_id'], name: 'index_messages_on_resource_id', using: :btree
add_index "messages", ["resource_type"], name: "index_messages_on_resource_type", using: :btree add_index 'messages', ['resource_type'], name: 'index_messages_on_resource_type', using: :btree
add_index "messages", ["user_id"], name: "index_messages_on_user_id", using: :btree add_index 'messages', ['user_id'], name: 'index_messages_on_user_id', using: :btree
create_table "metacode_sets", force: :cascade do |t| create_table 'metacode_sets', force: :cascade do |t|
t.string "name" t.string 'name'
t.text "desc" t.text 'desc'
t.integer "user_id" t.integer 'user_id'
t.boolean "mapperContributed" t.boolean 'mapperContributed'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
end end
add_index "metacode_sets", ["user_id"], name: "index_metacode_sets_on_user_id", using: :btree add_index 'metacode_sets', ['user_id'], name: 'index_metacode_sets_on_user_id', using: :btree
create_table "metacodes", force: :cascade do |t| create_table 'metacodes', force: :cascade do |t|
t.text "name" t.text 'name'
t.string "manual_icon" t.string 'manual_icon'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
t.string "color" t.string 'color'
t.string "aws_icon_file_name" t.string 'aws_icon_file_name'
t.string "aws_icon_content_type" t.string 'aws_icon_content_type'
t.integer "aws_icon_file_size" t.integer 'aws_icon_file_size'
t.datetime "aws_icon_updated_at" t.datetime 'aws_icon_updated_at'
end end
create_table "oauth_access_grants", force: :cascade do |t| create_table 'oauth_access_grants', force: :cascade do |t|
t.integer "resource_owner_id", null: false t.integer 'resource_owner_id', null: false
t.integer "application_id", null: false t.integer 'application_id', null: false
t.string "token", null: false t.string 'token', null: false
t.integer "expires_in", null: false t.integer 'expires_in', null: false
t.text "redirect_uri", null: false t.text 'redirect_uri', null: false
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "revoked_at" t.datetime 'revoked_at'
t.string "scopes" t.string 'scopes'
end end
add_index "oauth_access_grants", ["token"], name: "index_oauth_access_grants_on_token", unique: true, using: :btree add_index 'oauth_access_grants', ['token'], name: 'index_oauth_access_grants_on_token', unique: true, using: :btree
create_table "oauth_access_tokens", force: :cascade do |t| create_table 'oauth_access_tokens', force: :cascade do |t|
t.integer "resource_owner_id" t.integer 'resource_owner_id'
t.integer "application_id" t.integer 'application_id'
t.string "token", null: false t.string 'token', null: false
t.string "refresh_token" t.string 'refresh_token'
t.integer "expires_in" t.integer 'expires_in'
t.datetime "revoked_at" t.datetime 'revoked_at'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.string "scopes" t.string 'scopes'
end end
add_index "oauth_access_tokens", ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true, using: :btree add_index 'oauth_access_tokens', ['refresh_token'], name: 'index_oauth_access_tokens_on_refresh_token', unique: true, using: :btree
add_index "oauth_access_tokens", ["resource_owner_id"], name: "index_oauth_access_tokens_on_resource_owner_id", using: :btree add_index 'oauth_access_tokens', ['resource_owner_id'], name: 'index_oauth_access_tokens_on_resource_owner_id', using: :btree
add_index "oauth_access_tokens", ["token"], name: "index_oauth_access_tokens_on_token", unique: true, using: :btree add_index 'oauth_access_tokens', ['token'], name: 'index_oauth_access_tokens_on_token', unique: true, using: :btree
create_table "oauth_applications", force: :cascade do |t| create_table 'oauth_applications', force: :cascade do |t|
t.string "name", null: false t.string 'name', null: false
t.string "uid", null: false t.string 'uid', null: false
t.string "secret", null: false t.string 'secret', null: false
t.text "redirect_uri", null: false t.text 'redirect_uri', null: false
t.string "scopes", default: "", null: false t.string 'scopes', default: '', null: false
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "oauth_applications", ["uid"], name: "index_oauth_applications_on_uid", unique: true, using: :btree add_index 'oauth_applications', ['uid'], name: 'index_oauth_applications_on_uid', unique: true, using: :btree
create_table "synapses", force: :cascade do |t| create_table 'synapses', force: :cascade do |t|
t.text "desc" t.text 'desc'
t.text "category" t.text 'category'
t.text "weight" t.text 'weight'
t.text "permission" t.text 'permission'
t.integer "node1_id" t.integer 'node1_id'
t.integer "node2_id" t.integer 'node2_id'
t.integer "user_id" t.integer 'user_id'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
t.integer "defer_to_map_id" t.integer 'defer_to_map_id'
end end
add_index "synapses", ["node1_id", "node1_id"], name: "index_synapses_on_node1_id_and_node1_id", using: :btree add_index 'synapses', %w(node1_id node1_id), name: 'index_synapses_on_node1_id_and_node1_id', using: :btree
add_index "synapses", ["node1_id"], name: "index_synapses_on_node1_id", using: :btree add_index 'synapses', ['node1_id'], name: 'index_synapses_on_node1_id', using: :btree
add_index "synapses", ["node2_id", "node2_id"], name: "index_synapses_on_node2_id_and_node2_id", using: :btree add_index 'synapses', %w(node2_id node2_id), name: 'index_synapses_on_node2_id_and_node2_id', using: :btree
add_index "synapses", ["node2_id"], name: "index_synapses_on_node2_id", using: :btree add_index 'synapses', ['node2_id'], name: 'index_synapses_on_node2_id', using: :btree
add_index "synapses", ["user_id"], name: "index_synapses_on_user_id", using: :btree add_index 'synapses', ['user_id'], name: 'index_synapses_on_user_id', using: :btree
create_table "tokens", force: :cascade do |t| create_table 'tokens', force: :cascade do |t|
t.string "token" t.string 'token'
t.string "description" t.string 'description'
t.integer "user_id" t.integer 'user_id'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
end end
add_index "tokens", ["user_id"], name: "index_tokens_on_user_id", using: :btree add_index 'tokens', ['user_id'], name: 'index_tokens_on_user_id', using: :btree
create_table "topics", force: :cascade do |t| create_table 'topics', force: :cascade do |t|
t.text "name" t.text 'name'
t.text "desc" t.text 'desc'
t.text "link" t.text 'link'
t.text "permission" t.text 'permission'
t.integer "user_id" t.integer 'user_id'
t.integer "metacode_id" t.integer 'metacode_id'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
t.string "image_file_name" t.string 'image_file_name'
t.string "image_content_type" t.string 'image_content_type'
t.integer "image_file_size" t.integer 'image_file_size'
t.datetime "image_updated_at" t.datetime 'image_updated_at'
t.string "audio_file_name" t.string 'audio_file_name'
t.string "audio_content_type" t.string 'audio_content_type'
t.integer "audio_file_size" t.integer 'audio_file_size'
t.datetime "audio_updated_at" t.datetime 'audio_updated_at'
t.integer "defer_to_map_id" t.integer 'defer_to_map_id'
end end
add_index "topics", ["metacode_id"], name: "index_topics_on_metacode_id", using: :btree add_index 'topics', ['metacode_id'], name: 'index_topics_on_metacode_id', using: :btree
add_index "topics", ["user_id"], name: "index_topics_on_user_id", using: :btree add_index 'topics', ['user_id'], name: 'index_topics_on_user_id', using: :btree
create_table "user_maps", force: :cascade do |t| create_table 'user_maps', force: :cascade do |t|
t.integer "user_id" t.integer 'user_id'
t.integer "map_id" t.integer 'map_id'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "user_maps", ["map_id"], name: "index_user_maps_on_map_id", using: :btree add_index 'user_maps', ['map_id'], name: 'index_user_maps_on_map_id', using: :btree
add_index "user_maps", ["user_id"], name: "index_user_maps_on_user_id", using: :btree add_index 'user_maps', ['user_id'], name: 'index_user_maps_on_user_id', using: :btree
create_table "users", force: :cascade do |t| create_table 'users', force: :cascade do |t|
t.string "name" t.string 'name'
t.string "email" t.string 'email'
t.text "settings" t.text 'settings'
t.string "code", limit: 8 t.string 'code', limit: 8
t.string "joinedwithcode", limit: 8 t.string 'joinedwithcode', limit: 8
t.string "crypted_password" t.string 'crypted_password'
t.string "password_salt" t.string 'password_salt'
t.string "persistence_token" t.string 'persistence_token'
t.string "perishable_token" t.string 'perishable_token'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
t.string "encrypted_password", limit: 128, default: "" t.string 'encrypted_password', limit: 128, default: ''
t.string "remember_token" t.string 'remember_token'
t.datetime "remember_created_at" t.datetime 'remember_created_at'
t.string "reset_password_token" t.string 'reset_password_token'
t.datetime "last_sign_in_at" t.datetime 'last_sign_in_at'
t.string "last_sign_in_ip" t.string 'last_sign_in_ip'
t.integer "sign_in_count", default: 0 t.integer 'sign_in_count', default: 0
t.datetime "current_sign_in_at" t.datetime 'current_sign_in_at'
t.string "current_sign_in_ip" t.string 'current_sign_in_ip'
t.datetime "reset_password_sent_at" t.datetime 'reset_password_sent_at'
t.boolean "admin" t.boolean 'admin'
t.string "image_file_name" t.string 'image_file_name'
t.string "image_content_type" t.string 'image_content_type'
t.integer "image_file_size" t.integer 'image_file_size'
t.datetime "image_updated_at" t.datetime 'image_updated_at'
t.integer "generation" t.integer 'generation'
end end
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree add_index 'users', ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true, using: :btree
create_table "webhooks", force: :cascade do |t| create_table 'webhooks', force: :cascade do |t|
t.integer "hookable_id" t.integer 'hookable_id'
t.string "hookable_type" t.string 'hookable_type'
t.string "kind", null: false t.string 'kind', null: false
t.string "uri", null: false t.string 'uri', null: false
t.text "event_types", default: [], array: true t.text 'event_types', default: [], array: true
end end
add_index "webhooks", ["hookable_type", "hookable_id"], name: "index_webhooks_on_hookable_type_and_hookable_id", using: :btree add_index 'webhooks', %w(hookable_type hookable_id), name: 'index_webhooks_on_hookable_type_and_hookable_id', using: :btree
add_foreign_key "tokens", "users" add_foreign_key 'tokens', 'users'
end end

View file

@ -2,305 +2,207 @@
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
## USERS ## USERS
User.new({ User.new(name: 'user',
name: 'user',
email: 'user@user.com', email: 'user@user.com',
password: 'toolsplusconsciousness', password: 'toolsplusconsciousness',
code: 'qwertyui', code: 'qwertyui',
joinedwithcode: 'qwertyui', joinedwithcode: 'qwertyui',
admin: 'false' admin: 'false').save(validate: false)
}).save(validate: false)
User.new({ User.new(name: 'admin',
name: 'admin',
email: 'admin@admin.com', email: 'admin@admin.com',
password: 'toolsplusconsciousness', password: 'toolsplusconsciousness',
code: 'iuytrewq', code: 'iuytrewq',
joinedwithcode: 'iuytrewq', joinedwithcode: 'iuytrewq',
admin: 'true' admin: 'true').save(validate: false)
}).save(validate: false)
## END USERS ## END USERS
## METACODES ## METACODES
Metacode.create({ Metacode.create(name: 'Action',
name: 'Action',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_action.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_action.png',
color: '#BD6C85' color: '#BD6C85')
})
Metacode.create({ Metacode.create(name: 'Activity',
name: 'Activity',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_activity.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_activity.png',
color: '#6EBF65' color: '#6EBF65')
})
Metacode.create({ Metacode.create(name: 'Catalyst',
name: 'Catalyst',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_catalyst.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_catalyst.png',
color: '#EF8964', color: '#EF8964')
})
Metacode.create({ Metacode.create(name: 'Closed',
name: 'Closed',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_closedissue.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_closedissue.png',
color: '#ABB49F', color: '#ABB49F')
})
Metacode.create({ Metacode.create(name: 'Process',
name: 'Process',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_process.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_process.png',
color: '#BDB25E', color: '#BDB25E')
})
Metacode.create({ Metacode.create(name: 'Future',
name: 'Future',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_futuredev.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_futuredev.png',
color: '#25A17F', color: '#25A17F')
})
Metacode.create({ Metacode.create(name: 'Group',
name: 'Group',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_group.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_group.png',
color: '#7076BC', color: '#7076BC')
})
Metacode.create({ Metacode.create(name: 'Implication',
name: 'Implication',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_implication.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_implication.png',
color: '#83DECA', color: '#83DECA')
})
Metacode.create({ Metacode.create(name: 'Insight',
name: 'Insight',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_insight.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_insight.png',
color: '#B074AD', color: '#B074AD')
})
Metacode.create({ Metacode.create(name: 'Intention',
name: 'Intention',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_intention.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_intention.png',
color: '#BAEAFF', color: '#BAEAFF')
})
Metacode.create({ Metacode.create(name: 'Knowledge',
name: 'Knowledge',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_knowledge.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_knowledge.png',
color: '#60ACF7', color: '#60ACF7')
})
Metacode.create({ Metacode.create(name: 'Location',
name: 'Location',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_location.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_location.png',
color: '#ABD9A7', color: '#ABD9A7')
})
Metacode.create({ Metacode.create(name: 'Need',
name: 'Need',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_need.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_need.png',
color: '#D2A7D4', color: '#D2A7D4')
})
Metacode.create({ Metacode.create(name: 'Open',
name: 'Open',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_openissue.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_openissue.png',
color: '#9BBF71', color: '#9BBF71')
})
Metacode.create({ Metacode.create(name: 'Opportunity',
name: 'Opportunity',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_opportunity.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_opportunity.png',
color: '#889F64', color: '#889F64')
})
Metacode.create({ Metacode.create(name: 'Person',
name: 'Person',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_person.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_person.png',
color: '#DE925F', color: '#DE925F')
})
Metacode.create({ Metacode.create(name: 'Platform',
name: 'Platform',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_platform.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_platform.png',
color: '#21C8FE', color: '#21C8FE')
})
Metacode.create({ Metacode.create(name: 'Problem',
name: 'Problem',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_problem.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_problem.png',
color: '#99CFC4', color: '#99CFC4')
})
Metacode.create({ Metacode.create(name: 'Resource',
name: 'Resource',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_resource.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_resource.png',
color: '#C98C63', color: '#C98C63')
})
Metacode.create({ Metacode.create(name: 'Role',
name: 'Role',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_role.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_role.png',
color: '#A8595D', color: '#A8595D')
})
Metacode.create({ Metacode.create(name: 'Task',
name: 'Task',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_task.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_task.png',
color: '#3397C4', color: '#3397C4')
})
Metacode.create({ Metacode.create(name: 'Trajectory',
name: 'Trajectory',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_trajectory.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_trajectory.png',
color: '#D3AA4C', color: '#D3AA4C')
})
Metacode.create({ Metacode.create(name: 'Argument',
name: 'Argument',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_argument.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_argument.png',
color: '#7FAEFD', color: '#7FAEFD')
})
Metacode.create({ Metacode.create(name: 'Con',
name: 'Con',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_con.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_con.png',
color: '#CF7C74', color: '#CF7C74')
})
Metacode.create({ Metacode.create(name: 'Subject',
name: 'Subject',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_subject.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_subject.png',
color: '#8293D8', color: '#8293D8')
})
Metacode.create({ Metacode.create(name: 'Decision',
name: 'Decision',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_decision.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_decision.png',
color: '#CCA866', color: '#CCA866')
})
Metacode.create({ Metacode.create(name: 'Event',
name: 'Event',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_event.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_event.png',
color: '#F5854B', color: '#F5854B')
})
Metacode.create({ Metacode.create(name: 'Example',
name: 'Example',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_example.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_example.png',
color: '#618C61', color: '#618C61')
})
Metacode.create({ Metacode.create(name: 'Experience',
name: 'Experience',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_experience.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_experience.png',
color: '#BE995F', color: '#BE995F')
})
Metacode.create({ Metacode.create(name: 'Feedback',
name: 'Feedback',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_feedback.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_feedback.png',
color: '#54A19D', color: '#54A19D')
})
Metacode.create({ Metacode.create(name: 'Aim',
name: 'Aim',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_aim.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_aim.png',
color: '#B0B0B0', color: '#B0B0B0')
})
Metacode.create({ Metacode.create(name: 'Good',
name: 'Good',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_goodpractice.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_goodpractice.png',
color: '#BD9E86', color: '#BD9E86')
})
Metacode.create({ Metacode.create(name: 'Idea',
name: 'Idea',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_idea.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_idea.png',
color: '#C4BC5E', color: '#C4BC5E')
})
Metacode.create({ Metacode.create(name: 'List',
name: 'List',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_list.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_list.png',
color: '#B7A499', color: '#B7A499')
})
Metacode.create({ Metacode.create(name: 'Media',
name: 'Media',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_media.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_media.png',
color: '#6D94CC', color: '#6D94CC')
})
Metacode.create({ Metacode.create(name: 'Metamap',
name: 'Metamap',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_metamap.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_metamap.png',
color: '#AEA9FD', color: '#AEA9FD')
})
Metacode.create({ Metacode.create(name: 'Model',
name: 'Model',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_model.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_model.png',
color: '#B385BA', color: '#B385BA')
})
Metacode.create({ Metacode.create(name: 'Note',
name: 'Note',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_note.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_note.png',
color: '#A389A1', color: '#A389A1')
})
Metacode.create({ Metacode.create(name: 'Perspective',
name: 'Perspective',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_perspective.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_perspective.png',
color: '#2EB6CC', color: '#2EB6CC')
})
Metacode.create({ Metacode.create(name: 'Pro',
name: 'Pro',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_pro.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_pro.png',
color: '#89B879', color: '#89B879')
})
Metacode.create({ Metacode.create(name: 'Project',
name: 'Project',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_project.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_project.png',
color: '#85A050', color: '#85A050')
})
Metacode.create({ Metacode.create(name: 'Question',
name: 'Question',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_question.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_question.png',
color: '#5CB3B3', color: '#5CB3B3')
})
Metacode.create({ Metacode.create(name: 'Reference',
name: 'Reference',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_reference.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_reference.png',
color: '#A7A7A7', color: '#A7A7A7')
})
Metacode.create({ Metacode.create(name: 'Research',
name: 'Research',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_research.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_research.png',
color: '#CD8E89', color: '#CD8E89')
})
Metacode.create({ Metacode.create(name: 'Status',
name: 'Status',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_status.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_status.png',
color: '#EFA7C0', color: '#EFA7C0')
})
Metacode.create({ Metacode.create(name: 'Tool',
name: 'Tool',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_tool.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_tool.png',
color: '#828282', color: '#828282')
})
Metacode.create({ Metacode.create(name: 'Wildcard',
name: 'Wildcard',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png',
color: '#73C7DE', color: '#73C7DE')
})
## END METACODES ## END METACODES

View file

@ -1,13 +1,13 @@
require 'dotenv/tasks' require 'dotenv/tasks'
namespace :heroku do namespace :heroku do
desc "Generate the Heroku gems manifest from gem dependencies" desc 'Generate the Heroku gems manifest from gem dependencies'
task :gems => :dotenv do task gems: :dotenv do
RAILS_ENV='production' RAILS_ENV = 'production'.freeze
Rake::Task[:environment].invoke Rake::Task[:environment].invoke
list = Rails.configuration.gems.collect do |g| list = Rails.configuration.gems.collect do |g|
command, *options = g.send(:install_command) _command, *options = g.send(:install_command)
options.join(" ") + "\n" options.join(' ') + "\n"
end end
File.open(File.join(RAILS_ROOT, '.gems'), 'w') do |f| File.open(File.join(RAILS_ROOT, '.gems'), 'w') do |f|

View file

@ -1,8 +1,8 @@
require 'dotenv/tasks' require 'dotenv/tasks'
namespace :perms do namespace :perms do
desc "Update the Unix permissions on the public directory" desc 'Update the Unix permissions on the public directory'
task :fix => :environment do task fix: :environment do
# e.g. rake perms:fix user=mmstaging group=mmstaging # e.g. rake perms:fix user=mmstaging group=mmstaging
# e.g. rake perms:fix group=www-data #probably don't need this one # e.g. rake perms:fix group=www-data #probably don't need this one
# e.g. rake perms:fix # e.g. rake perms:fix

View file

@ -10,7 +10,7 @@ RSpec.describe MappingsController, type: :controller do
describe 'GET #show' do describe 'GET #show' do
it 'assigns the requested mapping as @mapping' do it 'assigns the requested mapping as @mapping' do
get :show, { id: mapping.to_param } get :show, id: mapping.to_param
expect(assigns(:mapping)).to eq(mapping) expect(assigns(:mapping)).to eq(mapping)
end end
end end
@ -19,12 +19,12 @@ RSpec.describe MappingsController, type: :controller do
context 'with valid params' do context 'with valid params' do
it 'creates a new Mapping' do it 'creates a new Mapping' do
expect do expect do
post :create, { mapping: valid_attributes } post :create, mapping: valid_attributes
end.to change(Mapping, :count).by(1) end.to change(Mapping, :count).by(1)
end end
it 'assigns a newly created mapping as @mapping' do it 'assigns a newly created mapping as @mapping' do
post :create, { mapping: valid_attributes } post :create, mapping: valid_attributes
expect(assigns(:mapping)).to be_a(Mapping) expect(assigns(:mapping)).to be_a(Mapping)
expect(assigns(:mapping)).to be_persisted expect(assigns(:mapping)).to be_persisted
end end
@ -32,7 +32,7 @@ RSpec.describe MappingsController, type: :controller do
context 'with invalid params' do context 'with invalid params' do
it 'assigns a newly created but unsaved mapping as @mapping' do it 'assigns a newly created but unsaved mapping as @mapping' do
post :create, { mapping: invalid_attributes } post :create, mapping: invalid_attributes
expect(assigns(:mapping)).to be_a_new(Mapping) expect(assigns(:mapping)).to be_a_new(Mapping)
end end
end end
@ -44,13 +44,13 @@ RSpec.describe MappingsController, type: :controller do
it 'updates the requested mapping' do it 'updates the requested mapping' do
put :update, put :update,
{ id: mapping.to_param, mapping: new_attributes } id: mapping.to_param, mapping: new_attributes
mapping.reload mapping.reload
end end
it 'assigns the requested mapping as @mapping' do it 'assigns the requested mapping as @mapping' do
put :update, put :update,
{ id: mapping.to_param, mapping: valid_attributes } id: mapping.to_param, mapping: valid_attributes
expect(assigns(:mapping)).to eq(mapping) expect(assigns(:mapping)).to eq(mapping)
end end
end end
@ -58,7 +58,7 @@ RSpec.describe MappingsController, type: :controller do
context 'with invalid params' do context 'with invalid params' do
it 'assigns the mapping as @mapping' do it 'assigns the mapping as @mapping' do
put :update, put :update,
{ id: mapping.to_param, mapping: invalid_attributes } id: mapping.to_param, mapping: invalid_attributes
expect(assigns(:mapping)).to eq(mapping) expect(assigns(:mapping)).to eq(mapping)
end end
end end
@ -67,7 +67,7 @@ RSpec.describe MappingsController, type: :controller do
describe 'DELETE #destroy' do describe 'DELETE #destroy' do
it 'destroys the requested mapping' do it 'destroys the requested mapping' do
expect do expect do
delete :destroy, { id: mapping.to_param } delete :destroy, id: mapping.to_param
end.to change(Mapping, :count).by(-1) end.to change(Mapping, :count).by(-1)
end end
end end

View file

@ -17,14 +17,14 @@ RSpec.describe MapsController, type: :controller do
describe 'GET #contains' do describe 'GET #contains' do
it 'returns json matching schema' do it 'returns json matching schema' do
get :contains, { id: map.to_param, format: :json } get :contains, id: map.to_param, format: :json
expect(response.body).to match_json_schema(:map_contains) expect(response.body).to match_json_schema(:map_contains)
end end
end end
describe 'GET #show' do describe 'GET #show' do
it 'assigns the requested map as @map' do it 'assigns the requested map as @map' do
get :show, { id: map.to_param } get :show, id: map.to_param
expect(assigns(:map)).to eq(map) expect(assigns(:map)).to eq(map)
end end
end end
@ -55,18 +55,18 @@ RSpec.describe MapsController, type: :controller do
describe 'PUT #update' do describe 'PUT #update' do
context 'with valid params' do context 'with valid params' do
let(:new_attributes) { { name: "Uncool map", permission: :private } } let(:new_attributes) { { name: 'Uncool map', permission: :private } }
it 'updates the requested map' do it 'updates the requested map' do
put :update, put :update,
{ id: map.to_param, map: new_attributes, format: :json } id: map.to_param, map: new_attributes, format: :json
expect(assigns(:map).name).to eq "Uncool map" expect(assigns(:map).name).to eq 'Uncool map'
expect(assigns(:map).permission).to eq 'private' expect(assigns(:map).permission).to eq 'private'
end end
it 'assigns the requested map as @map' do it 'assigns the requested map as @map' do
put :update, put :update,
{ id: map.to_param, map: valid_attributes, format: :json } id: map.to_param, map: valid_attributes, format: :json
expect(assigns(:map)).to eq(map) expect(assigns(:map)).to eq(map)
end end
end end
@ -74,7 +74,7 @@ RSpec.describe MapsController, type: :controller do
context 'with invalid params' do context 'with invalid params' do
it 'assigns the map as @map' do it 'assigns the map as @map' do
put :update, put :update,
{ id: map.to_param, map: invalid_attributes, format: :json } id: map.to_param, map: invalid_attributes, format: :json
expect(assigns(:map)).to eq(map) expect(assigns(:map)).to eq(map)
end end
end end
@ -87,7 +87,7 @@ RSpec.describe MapsController, type: :controller do
it 'prevents deletion by non-owners' do it 'prevents deletion by non-owners' do
unowned_map.reload unowned_map.reload
expect do expect do
delete :destroy, { id: unowned_map.to_param, format: :json } delete :destroy, id: unowned_map.to_param, format: :json
end.to change(Map, :count).by(0) end.to change(Map, :count).by(0)
expect(response.body).to eq '' expect(response.body).to eq ''
expect(response.status).to eq 403 expect(response.status).to eq 403
@ -96,7 +96,7 @@ RSpec.describe MapsController, type: :controller do
it 'deletes owned map' do it 'deletes owned map' do
owned_map.reload # ensure it's in the database owned_map.reload # ensure it's in the database
expect do expect do
delete :destroy, { id: owned_map.to_param, format: :json } delete :destroy, id: owned_map.to_param, format: :json
end.to change(Map, :count).by(-1) end.to change(Map, :count).by(-1)
expect(response.body).to eq '' expect(response.body).to eq ''
expect(response.status).to eq 204 expect(response.status).to eq 204

View file

@ -17,14 +17,14 @@ RSpec.describe MetacodesController, type: :controller do
describe 'GET #new' do describe 'GET #new' do
it 'assigns a new metacode as @metacode' do it 'assigns a new metacode as @metacode' do
get :new, { format: :json } get :new, format: :json
expect(assigns(:metacode)).to be_a_new(Metacode) expect(assigns(:metacode)).to be_a_new(Metacode)
end end
end end
describe 'GET #edit' do describe 'GET #edit' do
it 'assigns the requested metacode as @metacode' do it 'assigns the requested metacode as @metacode' do
get :edit, { id: metacode.to_param } get :edit, id: metacode.to_param
expect(assigns(:metacode)).to eq(metacode) expect(assigns(:metacode)).to eq(metacode)
end end
end end
@ -34,19 +34,19 @@ RSpec.describe MetacodesController, type: :controller do
it 'creates a new Metacode' do it 'creates a new Metacode' do
metacode.reload # ensure it's present to start metacode.reload # ensure it's present to start
expect do expect do
post :create, { metacode: valid_attributes } post :create, metacode: valid_attributes
end.to change(Metacode, :count).by(1) end.to change(Metacode, :count).by(1)
end end
it 'has the correct attributes' do it 'has the correct attributes' do
post :create, { metacode: valid_attributes } post :create, metacode: valid_attributes
# expect(Metacode.last.attributes.expect(:id)).to eq(metacode.attributes.except(:id)) # expect(Metacode.last.attributes.expect(:id)).to eq(metacode.attributes.except(:id))
expect(assigns(:metacode)).to be_a(Metacode) expect(assigns(:metacode)).to be_a(Metacode)
expect(assigns(:metacode)).to be_persisted expect(assigns(:metacode)).to be_persisted
end end
it 'redirects to the metacode index' do it 'redirects to the metacode index' do
post :create, { metacode: valid_attributes } post :create, metacode: valid_attributes
expect(response).to redirect_to(metacodes_url) expect(response).to redirect_to(metacodes_url)
end end
end end
@ -63,7 +63,7 @@ RSpec.describe MetacodesController, type: :controller do
it 'updates the requested metacode' do it 'updates the requested metacode' do
put :update, put :update,
{ id: metacode.to_param, metacode: new_attributes } id: metacode.to_param, metacode: new_attributes
metacode.reload metacode.reload
expect(metacode.icon).to eq 'https://newimages.ca/cool-image.jpg' expect(metacode.icon).to eq 'https://newimages.ca/cool-image.jpg'
expect(metacode.color).to eq '#ffffff' expect(metacode.color).to eq '#ffffff'
@ -75,13 +75,13 @@ RSpec.describe MetacodesController, type: :controller do
context 'not admin' do context 'not admin' do
it 'denies access to create' do it 'denies access to create' do
sign_in create(:user, admin: false) sign_in create(:user, admin: false)
post :create, { metacode: valid_attributes } post :create, metacode: valid_attributes
expect(response).to redirect_to root_url expect(response).to redirect_to root_url
end end
it 'denies access to update' do it 'denies access to update' do
sign_in create(:user, admin: false) sign_in create(:user, admin: false)
post :update, { id: metacode.to_param, metacode: valid_attributes } post :update, id: metacode.to_param, metacode: valid_attributes
expect(response).to redirect_to root_url expect(response).to redirect_to root_url
end end
end end

View file

@ -10,7 +10,7 @@ RSpec.describe SynapsesController, type: :controller do
describe 'GET #show' do describe 'GET #show' do
it 'assigns the requested synapse as @synapse' do it 'assigns the requested synapse as @synapse' do
get :show, { id: synapse.to_param, format: :json } get :show, id: synapse.to_param, format: :json
expect(assigns(:synapse)).to eq(synapse) expect(assigns(:synapse)).to eq(synapse)
end end
end end
@ -20,25 +20,25 @@ RSpec.describe SynapsesController, type: :controller do
it 'creates a new Synapse' do it 'creates a new Synapse' do
synapse.reload # ensure it's present synapse.reload # ensure it's present
expect do expect do
post :create, { synapse: valid_attributes, format: :json } post :create, synapse: valid_attributes, format: :json
end.to change(Synapse, :count).by(1) end.to change(Synapse, :count).by(1)
end end
it 'assigns a newly created synapse as @synapse' do it 'assigns a newly created synapse as @synapse' do
post :create, { synapse: valid_attributes, format: :json } post :create, synapse: valid_attributes, format: :json
expect(assigns(:synapse)).to be_a(Synapse) expect(assigns(:synapse)).to be_a(Synapse)
expect(assigns(:synapse)).to be_persisted expect(assigns(:synapse)).to be_persisted
end end
it 'returns 201 CREATED' do it 'returns 201 CREATED' do
post :create, { synapse: valid_attributes, format: :json } post :create, synapse: valid_attributes, format: :json
expect(response.status).to eq 201 expect(response.status).to eq 201
end end
end end
context 'with invalid params' do context 'with invalid params' do
it 'returns 422 UNPROCESSABLE ENTITY' do it 'returns 422 UNPROCESSABLE ENTITY' do
post :create, { synapse: invalid_attributes, format: :json } post :create, synapse: invalid_attributes, format: :json
expect(response.status).to eq 422 expect(response.status).to eq 422
end end
end end
@ -54,7 +54,7 @@ RSpec.describe SynapsesController, type: :controller do
it 'updates the requested synapse' do it 'updates the requested synapse' do
put :update, put :update,
{ id: synapse.to_param, synapse: new_attributes, format: :json } id: synapse.to_param, synapse: new_attributes, format: :json
synapse.reload synapse.reload
expect(synapse.desc).to eq 'My new description' expect(synapse.desc).to eq 'My new description'
expect(synapse.category).to eq 'both' expect(synapse.category).to eq 'both'
@ -63,7 +63,7 @@ RSpec.describe SynapsesController, type: :controller do
it 'returns 204 NO CONTENT' do it 'returns 204 NO CONTENT' do
put :update, put :update,
{ id: synapse.to_param, synapse: valid_attributes, format: :json } id: synapse.to_param, synapse: valid_attributes, format: :json
expect(response.status).to eq 204 expect(response.status).to eq 204
end end
end end
@ -71,7 +71,7 @@ RSpec.describe SynapsesController, type: :controller do
context 'with invalid params' do context 'with invalid params' do
it 'assigns the synapse as @synapse' do it 'assigns the synapse as @synapse' do
put :update, put :update,
{ id: synapse.to_param, synapse: invalid_attributes, format: :json } id: synapse.to_param, synapse: invalid_attributes, format: :json
expect(assigns(:synapse)).to eq(synapse) expect(assigns(:synapse)).to eq(synapse)
end end
end end
@ -83,12 +83,12 @@ RSpec.describe SynapsesController, type: :controller do
it 'destroys the requested synapse' do it 'destroys the requested synapse' do
synapse.reload # ensure it's present synapse.reload # ensure it's present
expect do expect do
delete :destroy, { id: synapse.to_param, format: :json } delete :destroy, id: synapse.to_param, format: :json
end.to change(Synapse, :count).by(-1) end.to change(Synapse, :count).by(-1)
end end
it 'returns 204 NO CONTENT' do it 'returns 204 NO CONTENT' do
delete :destroy, { id: synapse.to_param, format: :json } delete :destroy, id: synapse.to_param, format: :json
expect(response.status).to eq 204 expect(response.status).to eq 204
end end
end end

View file

@ -10,7 +10,7 @@ RSpec.describe TopicsController, type: :controller do
describe 'GET #show' do describe 'GET #show' do
it 'assigns the requested topic as @topic' do it 'assigns the requested topic as @topic' do
get :show, { id: topic.to_param, format: :json } get :show, id: topic.to_param, format: :json
expect(assigns(:topic)).to eq(topic) expect(assigns(:topic)).to eq(topic)
end end
end end
@ -20,25 +20,25 @@ RSpec.describe TopicsController, type: :controller do
it 'creates a new Topic' do it 'creates a new Topic' do
topic.reload # ensure it's created topic.reload # ensure it's created
expect do expect do
post :create, { topic: valid_attributes, format: :json } post :create, topic: valid_attributes, format: :json
end.to change(Topic, :count).by(1) end.to change(Topic, :count).by(1)
end end
it 'assigns a newly created topic as @topic' do it 'assigns a newly created topic as @topic' do
post :create, { topic: valid_attributes, format: :json } post :create, topic: valid_attributes, format: :json
expect(assigns(:topic)).to be_a(Topic) expect(assigns(:topic)).to be_a(Topic)
expect(assigns(:topic)).to be_persisted expect(assigns(:topic)).to be_persisted
end end
it 'returns 201 CREATED' do it 'returns 201 CREATED' do
post :create, { topic: valid_attributes, format: :json } post :create, topic: valid_attributes, format: :json
expect(response.status).to eq 201 expect(response.status).to eq 201
end end
end end
context 'with invalid params' do context 'with invalid params' do
it 'assigns a newly created but unsaved topic as @topic' do it 'assigns a newly created but unsaved topic as @topic' do
post :create, { topic: invalid_attributes, format: :json } post :create, topic: invalid_attributes, format: :json
expect(assigns(:topic)).to be_a_new(Topic) expect(assigns(:topic)).to be_a_new(Topic)
end end
end end
@ -55,7 +55,7 @@ RSpec.describe TopicsController, type: :controller do
it 'updates the requested topic' do it 'updates the requested topic' do
put :update, put :update,
{ id: topic.to_param, topic: new_attributes, format: :json } id: topic.to_param, topic: new_attributes, format: :json
topic.reload topic.reload
expect(topic.name).to eq 'Cool Topic with no number' expect(topic.name).to eq 'Cool Topic with no number'
expect(topic.desc).to eq 'This is a cool topic.' expect(topic.desc).to eq 'This is a cool topic.'
@ -65,13 +65,13 @@ RSpec.describe TopicsController, type: :controller do
it 'assigns the requested topic as @topic' do it 'assigns the requested topic as @topic' do
put :update, put :update,
{ id: topic.to_param, topic: valid_attributes, format: :json } id: topic.to_param, topic: valid_attributes, format: :json
expect(assigns(:topic)).to eq(topic) expect(assigns(:topic)).to eq(topic)
end end
it 'returns status of no content' do it 'returns status of no content' do
put :update, put :update,
{ id: topic.to_param, topic: valid_attributes, format: :json } id: topic.to_param, topic: valid_attributes, format: :json
expect(response.status).to eq 204 expect(response.status).to eq 204
end end
end end
@ -79,7 +79,7 @@ RSpec.describe TopicsController, type: :controller do
context 'with invalid params' do context 'with invalid params' do
it 'assigns the topic as @topic' do it 'assigns the topic as @topic' do
put :update, put :update,
{ id: topic.to_param, topic: invalid_attributes, format: :json } id: topic.to_param, topic: invalid_attributes, format: :json
expect(assigns(:topic)).to eq(topic) expect(assigns(:topic)).to eq(topic)
end end
end end
@ -90,7 +90,7 @@ RSpec.describe TopicsController, type: :controller do
it 'destroys the requested topic' do it 'destroys the requested topic' do
owned_topic.reload # ensure it's there owned_topic.reload # ensure it's there
expect do expect do
delete :destroy, { id: owned_topic.to_param, format: :json } delete :destroy, id: owned_topic.to_param, format: :json
end.to change(Topic, :count).by(-1) end.to change(Topic, :count).by(-1)
expect(response.body).to eq '' expect(response.body).to eq ''
expect(response.status).to eq 204 expect(response.status).to eq 204

View file

@ -15,8 +15,8 @@ FactoryGirl.define do
password 'omgwtfbbq' password 'omgwtfbbq'
factory :simple_user, aliases: [:user] do factory :simple_user, aliases: [:user] do
joinedwithcode { "qwertyui" } joinedwithcode { 'qwertyui' }
code { "qwertyui" } code { 'qwertyui' }
transient do transient do
validate false validate false

View file

@ -1,4 +1,4 @@
require "rails_helper" require 'rails_helper'
RSpec.describe MapMailer, type: :mailer do RSpec.describe MapMailer, type: :mailer do
pending "add some examples to (or delete) #{__FILE__}" pending "add some examples to (or delete) #{__FILE__}"

View file

@ -6,4 +6,3 @@ RSpec.describe Map, type: :model do
it { is_expected.to validate_presence_of :permission } it { is_expected.to validate_presence_of :permission }
it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) } it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) }
end end

View file

@ -5,10 +5,14 @@ RSpec.describe Metacode, type: :model do
it { is_expected.to have_many :metacode_sets } it { is_expected.to have_many :metacode_sets }
context 'BOTH aws_icon and manual_icon' do context 'BOTH aws_icon and manual_icon' do
let(:icon) { File.open(Rails.root.join('app', 'assets', 'images', let(:icon) do
'user.png')) } File.open(Rails.root.join('app', 'assets', 'images',
let(:metacode) { build(:metacode, aws_icon: icon, 'user.png'))
manual_icon: 'https://metamaps.cc/assets/user.png') } end
let(:metacode) do
build(:metacode, aws_icon: icon,
manual_icon: 'https://metamaps.cc/assets/user.png')
end
it 'raises a validation error' do it 'raises a validation error' do
expect { metacode.save! }.to raise_error ActiveRecord::RecordInvalid expect { metacode.save! }.to raise_error ActiveRecord::RecordInvalid
end end

View file

@ -9,5 +9,5 @@ RSpec.describe Synapse, type: :model do
it { is_expected.to validate_presence_of :permission } it { is_expected.to validate_presence_of :permission }
it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) } it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) }
it { is_expected.to validate_inclusion_of(:category).in_array ['from-to', 'both'] } it { is_expected.to validate_inclusion_of(:category).in_array ['from-to', 'both'] }
it { is_expected.to validate_length_of(:desc).is_at_least(0) } # TODO don't allow nil it { is_expected.to validate_length_of(:desc).is_at_least(0) } # TODO: don't allow nil
end end

View file

@ -1,10 +1,10 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe Token, type: :model do RSpec.describe Token, type: :model do
context "#generate_token" do context '#generate_token' do
subject (:token) { Token.new } subject(:token) { Token.new }
it "should generate an alphanumeric token of 32 characters" do it 'should generate an alphanumeric token of 32 characters' do
expect(token.send(:generate_token)).to match /^[a-zA-Z0-9]{32}$/ expect(token.send(:generate_token)).to match(/^[a-zA-Z0-9]{32}$/)
end end
end end
end end

View file

@ -21,6 +21,6 @@ module ControllerHelpers
end end
RSpec.configure do |config| RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller config.include Devise::TestHelpers, type: :controller
config.include ControllerHelpers, :type => :controller config.include ControllerHelpers, type: :controller
end end