diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..9fb58aba --- /dev/null +++ b/.rubocop.yml @@ -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 diff --git a/.ruby-version b/.ruby-version index 378bc559..ac2cdeba 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-2.1.3 +2.1.3 diff --git a/Gemfile b/Gemfile index 5840a752..7dc8035b 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ gem 'rails' gem 'active_model_serializers', '~> 0.8.1' 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_active_record', '~> 4.0.1' gem 'devise' @@ -40,7 +40,7 @@ group :assets do end group :production do - gem 'rails_12factor' + gem 'rails_12factor' end group :test do @@ -59,4 +59,5 @@ group :development, :test do gem 'pry-rails' gem 'quiet_assets' gem 'tunemygc' + gem 'rubocop' end diff --git a/Gemfile.lock b/Gemfile.lock index f62a561a..c385bd81 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,6 +40,7 @@ GEM tzinfo (~> 1.1) addressable (2.3.8) arel (6.0.3) + ast (2.3.0) aws-sdk (1.66.0) aws-sdk-v1 (= 1.66.0) aws-sdk-v1 (1.66.0) @@ -151,8 +152,11 @@ GEM cocaine (~> 0.5.5) mime-types mimemagic (= 0.3.0) + parser (2.3.1.2) + ast (~> 2.2) pg (0.18.4) pkg-config (1.1.7) + powerpack (0.1.1) pry (0.10.3) coderay (~> 1.1.0) method_source (~> 0.8.1) @@ -202,6 +206,7 @@ GEM activesupport (= 4.2.6) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + rainbow (2.1.0) rake (11.2.2) redis (3.3.0) responders (2.2.0) @@ -223,6 +228,13 @@ GEM rspec-mocks (~> 3.4.0) rspec-support (~> 3.4.0) 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-rails (5.0.4) railties (>= 4.0.0, < 5.0) @@ -256,6 +268,7 @@ GEM thread_safe (~> 0.1) uglifier (3.0.0) execjs (>= 0.3.0, < 3) + unicode-display_width (1.1.0) uservoice-ruby (0.0.11) ezcrypto (>= 0.7.2) json (>= 1.7.5) @@ -303,6 +316,7 @@ DEPENDENCIES rails_12factor redis rspec-rails + rubocop sass-rails shoulda-matchers simplecov diff --git a/Vagrantfile b/Vagrantfile index c9ea9363..23f1e8f4 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -31,15 +31,15 @@ sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '3112';" SCRIPT -VAGRANTFILE_API_VERSION = "2" +VAGRANTFILE_API_VERSION = '2'.freeze Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - 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 = 'trusty64' + 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: 5001, host: 5001 - config.vm.network "private_network", ip: "10.0.1.11" - config.vm.synced_folder ".", "/vagrant", :nfs => true + config.vm.network 'private_network', ip: '10.0.1.11' + config.vm.synced_folder '.', '/vagrant', nfs: true - config.vm.provision "shell", inline: $script + config.vm.provision 'shell', inline: $script end diff --git a/app/controllers/api/mappings_controller.rb b/app/controllers/api/mappings_controller.rb index 426c9dbe..15fde6bc 100644 --- a/app/controllers/api/mappings_controller.rb +++ b/app/controllers/api/mappings_controller.rb @@ -1,3 +1,2 @@ class Api::MappingsController < API::RestfulController - end diff --git a/app/controllers/api/maps_controller.rb b/app/controllers/api/maps_controller.rb index 7b805280..bb2d553d 100644 --- a/app/controllers/api/maps_controller.rb +++ b/app/controllers/api/maps_controller.rb @@ -1,3 +1,2 @@ class Api::MapsController < API::RestfulController - end diff --git a/app/controllers/api/restful_controller.rb b/app/controllers/api/restful_controller.rb index 2dd00d4d..5b6c41da 100644 --- a/app/controllers/api/restful_controller.rb +++ b/app/controllers/api/restful_controller.rb @@ -35,9 +35,7 @@ class API::RestfulController < ActionController::Base def token_user token = params[:access_token] access_token = Token.find_by_token(token) - if access_token - @token_user ||= access_token.user - end + @token_user ||= access_token.user if access_token end def doorkeeper_user @@ -49,5 +47,4 @@ class API::RestfulController < ActionController::Base def permitted_params @permitted_params ||= PermittedParams.new(params) end - end diff --git a/app/controllers/api/synapses_controller.rb b/app/controllers/api/synapses_controller.rb index f133ffd0..47cb6056 100644 --- a/app/controllers/api/synapses_controller.rb +++ b/app/controllers/api/synapses_controller.rb @@ -1,3 +1,2 @@ class Api::SynapsesController < API::RestfulController - end diff --git a/app/controllers/api/tokens_controller.rb b/app/controllers/api/tokens_controller.rb index 3fcca370..cea6ac5f 100644 --- a/app/controllers/api/tokens_controller.rb +++ b/app/controllers/api/tokens_controller.rb @@ -1,7 +1,6 @@ class Api::TokensController < API::RestfulController - def my_tokens - raise Pundit::NotAuthorizedError.new unless current_user + raise Pundit::NotAuthorizedError unless current_user instantiate_collection page_collection: false, timeframe_collection: false respond_with_collection end @@ -15,5 +14,4 @@ class Api::TokensController < API::RestfulController def visible_records current_user.tokens end - end diff --git a/app/controllers/api/topics_controller.rb b/app/controllers/api/topics_controller.rb index f3633544..4ccc619c 100644 --- a/app/controllers/api/topics_controller.rb +++ b/app/controllers/api/topics_controller.rb @@ -1,3 +1,2 @@ class Api::TopicsController < API::RestfulController - end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7b2a48b2..f46b4e4c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -20,12 +20,12 @@ class ApplicationController < ActionController::Base helper_method :admin? 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 super - elsif params[:uv_login] == "1" - "http://support.metamaps.cc/login_success?sso=" + current_sso_token + elsif params[:uv_login] == '1' + 'http://support.metamaps.cc/login_success?sso=' + current_sso_token else stored_location_for(resource) || request.referer || root_path end @@ -33,35 +33,35 @@ class ApplicationController < ActionController::Base def handle_unauthorized if authenticated? - head :forbidden # TODO make this better + head :forbidden # TODO: make this better 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 -private + private 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 def require_no_user 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 end end def require_user 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 end end def require_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 end end @@ -79,7 +79,7 @@ private end def allow_embedding - #allow all + # allow all response.headers.except! 'X-Frame-Options' # or allow a whitelist # response.headers['X-Frame-Options'] = 'ALLOW-FROM http://blog.metamaps.cc' diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 87264c4c..03f928ce 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -5,66 +5,66 @@ class MainController < ApplicationController include SynapsesHelper after_action :verify_policy_scoped, except: [:requestinvite, :searchmappers] - + respond_to :html, :json - + # home page 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| - format.html { - if not authenticated? - render 'main/home' - else - render 'maps/activemaps' - end - } + format.html do + if !authenticated? + render 'main/home' + else + render 'maps/activemaps' + end + end end end - + ### SEARCHING ### - + # get /search/topics?term=SOMETERM def searchtopics term = params[:term] user = params[:user] ? params[:user] : false - - if term && !term.empty? && term.downcase[0..3] != "map:" && term.downcase[0..6] != "mapper:" && term.downcase != "topic:" - - #remove "topic:" if appended at beginning - term = term[6..-1] if term.downcase[0..5] == "topic:" - - #if desc: search desc instead + + if term && !term.empty? && term.downcase[0..3] != 'map:' && term.downcase[0..6] != 'mapper:' && !term.casecmp('topic:').zero? + + # remove "topic:" if appended at beginning + term = term[6..-1] if term.downcase[0..5] == 'topic:' + + # if desc: search desc instead desc = false - if term.downcase[0..4] == "desc:" - term = term[5..-1] + if term.downcase[0..4] == 'desc:' + term = term[5..-1] desc = true end - - #if link: search link instead + + # if link: search link instead link = false - if term.downcase[0..4] == "link:" - term = term[5..-1] + if term.downcase[0..4] == 'link:' + term = term[5..-1] link = true 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 Metacode.all.each do |m| - lOne = m.name.length+1 + lOne = m.name.length + 1 lTwo = m.name.length - - if term.downcase[0..lTwo] == m.name.downcase + ":" - term = term[lOne..-1] + + if term.downcase[0..lTwo] == m.name.downcase + ':' + term = term[lOne..-1] filterByMetacode = m end end search = '%' + term.downcase + '%' builder = policy_scope(Topic) - + if filterByMetacode - if term == "" + if term == '' builder = builder.none else builder = builder.where('LOWER("name") like ? OR @@ -76,7 +76,7 @@ class MainController < ApplicationController builder = builder.where('LOWER("desc") like ?', search) elsif link 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 LOWER("desc") like ? OR LOWER("link") like ?', search, search, search) @@ -90,59 +90,59 @@ class MainController < ApplicationController render json: autocomplete_array_json(@topics) end - + # get /search/maps?term=SOMETERM def searchmaps term = params[:term] user = params[:user] ? params[:user] : nil - - if term && !term.empty? && term.downcase[0..5] != "topic:" && term.downcase[0..6] != "mapper:" && term.downcase != "map:" - - #remove "map:" if appended at beginning - term = term[4..-1] if term.downcase[0..3] == "map:" - - #if desc: search desc instead + + if term && !term.empty? && term.downcase[0..5] != 'topic:' && term.downcase[0..6] != 'mapper:' && !term.casecmp('map:').zero? + + # remove "map:" if appended at beginning + term = term[4..-1] if term.downcase[0..3] == 'map:' + + # if desc: search desc instead desc = false - if term.downcase[0..4] == "desc:" - term = term[5..-1] + if term.downcase[0..4] == 'desc:' + term = term[5..-1] desc = true end search = '%' + term.downcase + '%' builder = policy_scope(Map) - if desc - builder = builder.where('LOWER("desc") like ?', search) - else - builder = builder.where('LOWER("name") like ?', search) - end + builder = if desc + builder.where('LOWER("desc") like ?', search) + else + builder.where('LOWER("name") like ?', search) + end builder = builder.where(user: user) if user @maps = builder.order(:name) else @maps = [] end - + render json: autocomplete_map_array_json(@maps) end - + # get /search/mappers?term=SOMETERM def searchmappers term = params[:term] - if term && !term.empty? && term.downcase[0..3] != "map:" && term.downcase[0..5] != "topic:" && term.downcase != "mapper:" - - #remove "mapper:" if appended at beginning - term = term[7..-1] if term.downcase[0..6] == "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 + term = term[7..-1] if term.downcase[0..6] == 'mapper:' 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) @mappers = builder.order(:name) else @mappers = [] end render json: autocomplete_user_array_json(@mappers) - end - + end + # get /search/synapses?term=SOMETERM OR # get /search/synapses?topic1id=SOMEID&topic2id=SOMEID def searchsynapses @@ -153,30 +153,30 @@ class MainController < ApplicationController if term && !term.empty? @synapses = policy_scope(Synapse).where('LOWER("desc") like ?', '%' + term.downcase + '%').order('"desc"') - # remove any duplicate synapse types that just differ by + # remove any duplicate synapse types that just differ by # leading or trailing whitespaces collectedDesc = [] - @synapses.to_a.uniq(&:desc).delete_if {|s| - desc = s.desc == nil || s.desc == "" ? "" : s.desc.strip - if collectedDesc.index(desc) == nil + @synapses.to_a.uniq(&:desc).delete_if do |s| + desc = s.desc.nil? || s.desc == '' ? '' : s.desc.strip + if collectedDesc.index(desc).nil? collectedDesc.push(desc) - boolean = false + false # return this value else - boolean = true + true # return this value end - } + end elsif topic1id && !topic1id.empty? @one = policy_scope(Synapse).where('node1_id = ? AND node2_id = ?', topic1id, topic2id) @two = policy_scope(Synapse).where('node2_id = ? AND node1_id = ?', topic1id, topic2id) @synapses = @one + @two - @synapses.sort! {|s1,s2| s1.desc <=> s2.desc }.to_a + @synapses.sort! { |s1, s2| s1.desc <=> s2.desc }.to_a else @synapses = [] end - #limit to 5 results - @synapses = @synapses.slice(0,5) + # limit to 5 results + @synapses = @synapses.slice(0, 5) render json: autocomplete_synapse_array_json(@synapses) - end + end end diff --git a/app/controllers/mappings_controller.rb b/app/controllers/mappings_controller.rb index 9a5f1f1f..3d162c0f 100644 --- a/app/controllers/mappings_controller.rb +++ b/app/controllers/mappings_controller.rb @@ -1,11 +1,10 @@ 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_policy_scoped, only: :index - + respond_to :json - + # GET /mappings/1.json def show @mapping = Mapping.find(params[:id]) @@ -54,12 +53,13 @@ class MappingsController < ApplicationController @mapping.destroy - head :no_content + head :no_content end private - # Never trust parameters from the scary internet, only allow the white list through. - def mapping_params - params.require(:mapping).permit(:id, :xloc, :yloc, :mappable_id, :mappable_type, :map_id) - end + + # Never trust parameters from the scary internet, only allow the white list through. + def mapping_params + params.require(:mapping).permit(:id, :xloc, :yloc, :mappable_id, :mappable_type, :map_id) + end end diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 0e59f72d..90d2c320 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -1,309 +1,308 @@ class MapsController < ApplicationController - before_action :require_user, only: [:create, :update, :access, :screenshot, :events, :destroy] - after_action :verify_authorized, except: [:activemaps, :featuredmaps, :mymaps, :sharedmaps, :usermaps, :events] - after_action :verify_policy_scoped, only: [:activemaps, :featuredmaps, :mymaps, :sharedmaps, :usermaps] + before_action :require_user, only: [:create, :update, :access, :screenshot, :events, :destroy] + after_action :verify_authorized, except: [:activemaps, :featuredmaps, :mymaps, :sharedmaps, :usermaps, :events] + after_action :verify_policy_scoped, only: [:activemaps, :featuredmaps, :mymaps, :sharedmaps, :usermaps] - 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 - def activemaps - page = params[:page].present? ? params[:page] : 1 - @maps = policy_scope(Map).order("updated_at DESC") - .page(page).per(20) + # GET /explore/active + def activemaps + page = params[:page].present? ? params[:page] : 1 + @maps = policy_scope(Map).order('updated_at DESC') + .page(page).per(20) - respond_to do |format| - format.html { - # root url => main/home. main/home renders maps/activemaps view. - redirect_to root_url and return if authenticated? - respond_with(@maps, @user) - } - format.json { render json: @maps } - end - end - - # GET /explore/featured - def featuredmaps - page = params[:page].present? ? params[:page] : 1 - @maps = policy_scope( - Map.where("maps.featured = ? AND maps.permission != ?", - true, "private") - ).order("updated_at DESC").page(page).per(20) - - respond_to do |format| - format.html { respond_with(@maps, @user) } - format.json { render json: @maps } - end - end - - # GET /explore/mine - def mymaps - if !authenticated? - skip_policy_scope - return redirect_to explore_active_path + respond_to do |format| + format.html do + # root url => main/home. main/home renders maps/activemaps view. + redirect_to(root_url) && return if authenticated? + respond_with(@maps, @user) end + format.json { render json: @maps } + end + end - page = params[:page].present? ? params[:page] : 1 - @maps = policy_scope( - Map.where("maps.user_id = ?", current_user.id) - ).order("updated_at DESC").page(page).per(20) + # GET /explore/featured + def featuredmaps + page = params[:page].present? ? params[:page] : 1 + @maps = policy_scope( + Map.where('maps.featured = ? AND maps.permission != ?', + true, 'private') + ).order('updated_at DESC').page(page).per(20) - respond_to do |format| - format.html { respond_with(@maps, @user) } - format.json { render json: @maps } - end + respond_to do |format| + format.html { respond_with(@maps, @user) } + format.json { render json: @maps } + end + end + + # GET /explore/mine + def mymaps + unless authenticated? + skip_policy_scope + return redirect_to explore_active_path end - # GET /explore/shared - def sharedmaps - if !authenticated? - skip_policy_scope - return redirect_to explore_active_path - end + page = params[:page].present? ? params[:page] : 1 + @maps = policy_scope( + Map.where('maps.user_id = ?', current_user.id) + ).order('updated_at DESC').page(page).per(20) - page = params[:page].present? ? params[:page] : 1 - @maps = policy_scope( - Map.where("maps.id IN (?)", current_user.shared_maps.map(&:id)) - ).order("updated_at DESC").page(page).per(20) + respond_to do |format| + format.html { respond_with(@maps, @user) } + format.json { render json: @maps } + end + end - respond_to do |format| - format.html { respond_with(@maps, @user) } - format.json { render json: @maps } - end + # GET /explore/shared + def sharedmaps + unless authenticated? + skip_policy_scope + return redirect_to explore_active_path end - # GET /explore/mapper/:id - def usermaps - page = params[:page].present? ? params[:page] : 1 - @user = User.find(params[:id]) - @maps = policy_scope(Map.where(user: @user)) - .order("updated_at DESC").page(page).per(20) + page = params[:page].present? ? params[:page] : 1 + @maps = policy_scope( + Map.where('maps.id IN (?)', current_user.shared_maps.map(&:id)) + ).order('updated_at DESC').page(page).per(20) - respond_to do |format| - format.html { respond_with(@maps, @user) } - format.json { render json: @maps } - end + respond_to do |format| + format.html { respond_with(@maps, @user) } + format.json { render json: @maps } end + end - # GET maps/:id - def show - @map = Map.find(params[:id]) - authorize @map + # GET /explore/mapper/:id + def usermaps + page = params[:page].present? ? params[:page] : 1 + @user = User.find(params[:id]) + @maps = policy_scope(Map.where(user: @user)) + .order('updated_at DESC').page(page).per(20) - respond_to do |format| - format.html { - @allmappers = @map.contributors - @allcollaborators = @map.editors - @alltopics = @map.topics.to_a.delete_if {|t| not policy(t).show? } - @allsynapses = @map.synapses.to_a.delete_if {|s| not policy(s).show? } - @allmappings = @map.mappings.to_a.delete_if {|m| not policy(m).show? } - @allmessages = @map.messages.sort_by(&:created_at) - - respond_with(@allmappers, @allcollaborators, @allmappings, @allsynapses, @alltopics, @allmessages, @map) - } - format.json { render json: @map } - format.csv { redirect_to action: :export, format: :csv } - format.xls { redirect_to action: :export, format: :xls } - end + respond_to do |format| + format.html { respond_with(@maps, @user) } + format.json { render json: @maps } end + end - # GET maps/:id/export - def export - map = Map.find(params[:id]) - authorize map - exporter = MapExportService.new(current_user, map) - respond_to do |format| - format.json { render json: exporter.json } - format.csv { send_data exporter.csv } - format.xls { @spreadsheet = exporter.xls } - end - end - - # POST maps/:id/events/:event - def events - map = Map.find(params[:id]) - authorize map - - valid_event = false - if params[:event] == 'conversation' - Events::ConversationStartedOnMap.publish!(map, current_user) - valid_event = true - elsif params[:event] == 'user_presence' - Events::UserPresentOnMap.publish!(map, current_user) - valid_event = true - end - - respond_to do |format| - format.json { - head :ok if valid_event - head :bad_request if not valid_event - } - end - end - - # GET maps/:id/contains - def contains - @map = Map.find(params[:id]) - authorize @map + # GET maps/:id + def show + @map = Map.find(params[:id]) + authorize @map + respond_to do |format| + format.html do @allmappers = @map.contributors @allcollaborators = @map.editors - @alltopics = @map.topics.to_a.delete_if {|t| not policy(t).show? } - @allsynapses = @map.synapses.to_a.delete_if {|s| not policy(s).show? } - @allmappings = @map.mappings.to_a.delete_if {|m| not policy(m).show? } + @alltopics = @map.topics.to_a.delete_if { |t| !policy(t).show? } + @allsynapses = @map.synapses.to_a.delete_if { |s| !policy(s).show? } + @allmappings = @map.mappings.to_a.delete_if { |m| !policy(m).show? } + @allmessages = @map.messages.sort_by(&:created_at) + respond_with(@allmappers, @allcollaborators, @allmappings, @allsynapses, @alltopics, @allmessages, @map) + end + format.json { render json: @map } + format.csv { redirect_to action: :export, format: :csv } + format.xls { redirect_to action: :export, format: :xls } + end + end - @json = Hash.new() - @json['map'] = @map - @json['topics'] = @alltopics - @json['synapses'] = @allsynapses - @json['mappings'] = @allmappings - @json['mappers'] = @allmappers - @json['collaborators'] = @allcollaborators - @json['messages'] = @map.messages.sort_by(&:created_at) + # GET maps/:id/export + def export + map = Map.find(params[:id]) + authorize map + exporter = MapExportService.new(current_user, map) + respond_to do |format| + format.json { render json: exporter.json } + format.csv { send_data exporter.csv } + format.xls { @spreadsheet = exporter.xls } + end + end - respond_to do |format| - format.json { render json: @json } - end + # POST maps/:id/events/:event + def events + map = Map.find(params[:id]) + authorize map + + valid_event = false + if params[:event] == 'conversation' + Events::ConversationStartedOnMap.publish!(map, current_user) + valid_event = true + elsif params[:event] == 'user_presence' + Events::UserPresentOnMap.publish!(map, current_user) + valid_event = true end - # POST maps - def create - @user = current_user - @map = Map.new() - @map.name = params[:name] - @map.desc = params[:desc] - @map.permission = params[:permission] - @map.user = @user - @map.arranged = false + respond_to do |format| + format.json do + head :ok if valid_event + head :bad_request unless valid_event + end + end + end - if params[:topicsToMap] - @all = params[:topicsToMap] - @all = @all.split(',') - @all.each do |topic| - topic = topic.split('/') - mapping = Mapping.new - mapping.map = @map - mapping.user = @user - mapping.mappable = Topic.find(topic[0]) - mapping.xloc = topic[1] - mapping.yloc = topic[2] - authorize mapping, :create? - mapping.save - end + # GET maps/:id/contains + def contains + @map = Map.find(params[:id]) + authorize @map - if params[:synapsesToMap] - @synAll = params[:synapsesToMap] - @synAll = @synAll.split(',') - @synAll.each do |synapse_id| - mapping = Mapping.new - mapping.map = @map - mapping.user = @user - mapping.mappable = Synapse.find(synapse_id) - authorize mapping, :create? - mapping.save - end - end + @allmappers = @map.contributors + @allcollaborators = @map.editors + @alltopics = @map.topics.to_a.delete_if { |t| !policy(t).show? } + @allsynapses = @map.synapses.to_a.delete_if { |s| !policy(s).show? } + @allmappings = @map.mappings.to_a.delete_if { |m| !policy(m).show? } - @map.arranged = true + @json = {} + @json['map'] = @map + @json['topics'] = @alltopics + @json['synapses'] = @allsynapses + @json['mappings'] = @allmappings + @json['mappers'] = @allmappers + @json['collaborators'] = @allcollaborators + @json['messages'] = @map.messages.sort_by(&:created_at) + + respond_to do |format| + format.json { render json: @json } + end + end + + # POST maps + def create + @user = current_user + @map = Map.new + @map.name = params[:name] + @map.desc = params[:desc] + @map.permission = params[:permission] + @map.user = @user + @map.arranged = false + + if params[:topicsToMap] + @all = params[:topicsToMap] + @all = @all.split(',') + @all.each do |topic| + topic = topic.split('/') + mapping = Mapping.new + mapping.map = @map + mapping.user = @user + mapping.mappable = Topic.find(topic[0]) + mapping.xloc = topic[1] + mapping.yloc = topic[2] + authorize mapping, :create? + mapping.save + end + + if params[:synapsesToMap] + @synAll = params[:synapsesToMap] + @synAll = @synAll.split(',') + @synAll.each do |synapse_id| + mapping = Mapping.new + mapping.map = @map + mapping.user = @user + mapping.mappable = Synapse.find(synapse_id) + authorize mapping, :create? + mapping.save end + end - authorize @map - - if @map.save - respond_to do |format| - format.json { render :json => @map } - end - else - respond_to do |format| - format.json { render :json => "invalid params" } - end - end + @map.arranged = true end - # PUT maps/:id - def update - @map = Map.find(params[:id]) - authorize @map - - respond_to do |format| - if @map.update_attributes(map_params) - format.json { head :no_content } - else - format.json { render json: @map.errors, status: :unprocessable_entity } - end - end - end - - # POST maps/:id/access - def access - @map = Map.find(params[:id]) - authorize @map - userIds = params[:access] || [] - added = userIds.select { |uid| - user = User.find(uid) - if user.nil? || (current_user && user == current_user) - false - else - not @map.collaborators.include?(user) - end - } - removed = @map.collaborators.select { |user| not userIds.include?(user.id.to_s) }.map(&:id) - added.each { |uid| - um = UserMap.create({ user_id: uid.to_i, map_id: @map.id }) - user = User.find(uid.to_i) - MapMailer.invite_to_edit_email(@map, current_user, user).deliver_later - } - removed.each { |uid| - @map.user_maps.select{ |um| um.user_id == uid }.each{ |um| um.destroy } - } + authorize @map + if @map.save respond_to do |format| - format.json do - render :json => { :message => "Successfully altered edit permissions" } - end + format.json { render json: @map } + end + else + respond_to do |format| + format.json { render json: 'invalid params' } end end - - # POST maps/:id/upload_screenshot - def screenshot - @map = Map.find(params[:id]) - authorize @map + end - png = Base64.decode64(params[:encoded_image]['data:image/png;base64,'.length .. -1]) - StringIO.open(png) do |data| - data.class.class_eval { attr_accessor :original_filename, :content_type } - data.original_filename = "map-" + @map.id.to_s + "-screenshot.png" - data.content_type = "image/png" - @map.screenshot = data - end - - if @map.save - render :json => {:message => "Successfully uploaded the map screenshot."} + # PUT maps/:id + def update + @map = Map.find(params[:id]) + authorize @map + + respond_to do |format| + if @map.update_attributes(map_params) + format.json { head :no_content } else - render :json => {:message => "Failed to upload image."} + format.json { render json: @map.errors, status: :unprocessable_entity } end end + end - # DELETE maps/:id - def destroy - @map = Map.find(params[:id]) - authorize @map - - @map.delete - - respond_to do |format| - format.json do - head :no_content - end + # POST maps/:id/access + def access + @map = Map.find(params[:id]) + authorize @map + userIds = params[:access] || [] + added = userIds.select do |uid| + user = User.find(uid) + if user.nil? || (current_user && user == current_user) + false + else + !@map.collaborators.include?(user) end end - - private - - # Never trust parameters from the scary internet, only allow the white list through. - def map_params - params.require(:map).permit(:id, :name, :arranged, :desc, :permission) + removed = @map.collaborators.select { |user| !userIds.include?(user.id.to_s) }.map(&:id) + added.each do |uid| + UserMap.create(user_id: uid.to_i, map_id: @map.id) + user = User.find(uid.to_i) + MapMailer.invite_to_edit_email(@map, current_user, user).deliver_later end + removed.each do |uid| + @map.user_maps.select { |um| um.user_id == uid }.each(&:destroy) + end + + respond_to do |format| + format.json do + render json: { message: 'Successfully altered edit permissions' } + end + end + end + + # POST maps/:id/upload_screenshot + def screenshot + @map = Map.find(params[:id]) + authorize @map + + png = Base64.decode64(params[:encoded_image]['data:image/png;base64,'.length..-1]) + StringIO.open(png) do |data| + data.class.class_eval { attr_accessor :original_filename, :content_type } + data.original_filename = 'map-' + @map.id.to_s + '-screenshot.png' + data.content_type = 'image/png' + @map.screenshot = data + end + + if @map.save + render json: { message: 'Successfully uploaded the map screenshot.' } + else + render json: { message: 'Failed to upload image.' } + end + end + + # DELETE maps/:id + def destroy + @map = Map.find(params[:id]) + authorize @map + + @map.delete + + respond_to do |format| + format.json do + head :no_content + end + end + end + + private + + # Never trust parameters from the scary internet, only allow the white list through. + def map_params + params.require(:map).permit(:id, :name, :arranged, :desc, :permission) + end end diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 386919f3..ec59a2a4 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -1,5 +1,4 @@ class MessagesController < ApplicationController - before_action :require_user, except: [:show] after_action :verify_authorized @@ -59,9 +58,9 @@ class MessagesController < ApplicationController private - # Never trust parameters from the scary internet, only allow the white list through. - def message_params - #params.require(:message).permit(:id, :resource_id, :message) - params.permit(:id, :resource_id, :resource_type, :message) - end + # Never trust parameters from the scary internet, only allow the white list through. + def message_params + # params.require(:message).permit(:id, :resource_id, :message) + params.permit(:id, :resource_id, :resource_type, :message) + end end diff --git a/app/controllers/metacode_sets_controller.rb b/app/controllers/metacode_sets_controller.rb index e76f4c9a..a57c557f 100644 --- a/app/controllers/metacode_sets_controller.rb +++ b/app/controllers/metacode_sets_controller.rb @@ -1,11 +1,10 @@ class MetacodeSetsController < ApplicationController - before_action :require_admin # GET /metacode_sets # GET /metacode_sets.json def index - @metacode_sets = MetacodeSet.order("name").all + @metacode_sets = MetacodeSet.order('name').all respond_to do |format| format.html # index.html.erb @@ -16,14 +15,14 @@ class MetacodeSetsController < ApplicationController ### SHOW IS NOT CURRENTLY IN USE # GET /metacode_sets/1 # GET /metacode_sets/1.json -# def show -# @metacode_set = MetacodeSet.find(params[:id]) -# -# respond_to do |format| -# format.html # show.html.erb -# format.json { render json: @metacode_set } -# end -# end + # def show + # @metacode_set = MetacodeSet.find(params[:id]) + # + # respond_to do |format| + # format.html # show.html.erb + # format.json { render json: @metacode_set } + # end + # end # GET /metacode_sets/new # GET /metacode_sets/new.json @@ -53,12 +52,12 @@ class MetacodeSetsController < ApplicationController # create the InMetacodeSet for all the metacodes that were selected for the set @metacodes = params[:metacodes][:value].split(',') @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 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 } else - format.html { render action: "new" } + format.html { render action: 'new' } format.json { render json: @metacode_set.errors, status: :unprocessable_entity } end end @@ -71,29 +70,29 @@ class MetacodeSetsController < ApplicationController respond_to do |format| if @metacode_set.update_attributes(metacode_set_params) - + # 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 @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.each do |m| @inmetacodeset = InMetacodeSet.find_by_metacode_id_and_metacode_set_id(m, @metacode_set.id) @inmetacodeset.destroy end - + # add the new metacodes @addedMetacodes = @newMetacodes - @currentMetacodes @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 - + format.html { redirect_to metacode_sets_url, notice: 'Metacode set was successfully updated.' } format.json { head :no_content } else - format.html { render action: "edit" } + format.html { render action: 'edit' } format.json { render json: @metacode_set.errors, status: :unprocessable_entity } end end @@ -103,12 +102,10 @@ class MetacodeSetsController < ApplicationController # DELETE /metacode_sets/1.json def destroy @metacode_set = MetacodeSet.find(params[:id]) - - #delete everything that tracks what's in the set - @metacode_set.in_metacode_sets.each do |m| - m.destroy - end - + + # delete everything that tracks what's in the set + @metacode_set.in_metacode_sets.each(&:destroy) + @metacode_set.destroy respond_to do |format| @@ -122,5 +119,4 @@ class MetacodeSetsController < ApplicationController def metacode_set_params params.require(:metacode_set).permit(:desc, :mapperContributed, :name) end - end diff --git a/app/controllers/metacodes_controller.rb b/app/controllers/metacodes_controller.rb index 3480c4cd..313d9764 100644 --- a/app/controllers/metacodes_controller.rb +++ b/app/controllers/metacodes_controller.rb @@ -1,19 +1,19 @@ class MetacodesController < ApplicationController before_action :require_admin, except: [:index, :show] - + # GET /metacodes # GET /metacodes.json def index - @metacodes = Metacode.order("name").all + @metacodes = Metacode.order('name').all respond_to do |format| - format.html { + format.html do 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 end render :index - } + end format.json { render json: @metacodes } end end diff --git a/app/controllers/synapses_controller.rb b/app/controllers/synapses_controller.rb index b8ccfc5f..310e48cd 100644 --- a/app/controllers/synapses_controller.rb +++ b/app/controllers/synapses_controller.rb @@ -4,9 +4,9 @@ class SynapsesController < ApplicationController before_action :require_user, only: [:create, :update, :destroy] after_action :verify_authorized, except: :index after_action :verify_policy_scoped, only: :index - + respond_to :json - + # GET /synapses/1.json def show @synapse = Synapse.find(params[:id]) @@ -14,12 +14,12 @@ class SynapsesController < ApplicationController render json: @synapse end - + # POST /synapses # POST /synapses.json def create @synapse = Synapse.new(synapse_params) - @synapse.desc = "" if @synapse.desc.nil? + @synapse.desc = '' if @synapse.desc.nil? authorize @synapse respond_to do |format| @@ -30,12 +30,12 @@ class SynapsesController < ApplicationController end end end - + # PUT /synapses/1 # PUT /synapses/1.json def update @synapse = Synapse.find(params[:id]) - @synapse.desc = "" if @synapse.desc.nil? + @synapse.desc = '' if @synapse.desc.nil? authorize @synapse respond_to do |format| @@ -46,13 +46,13 @@ class SynapsesController < ApplicationController end end end - + # DELETE synapses/:id def destroy @synapse = Synapse.find(params[:id]) authorize @synapse @synapse.destroy - + respond_to do |format| format.json { head :no_content } end diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 88e9cef4..253f1ec1 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -1,119 +1,119 @@ class TopicsController < ApplicationController - include TopicsHelper + include TopicsHelper - before_action :require_user, only: [:create, :update, :destroy] - after_action :verify_authorized, except: :autocomplete_topic - - respond_to :html, :js, :json + before_action :require_user, only: [:create, :update, :destroy] + after_action :verify_authorized, except: :autocomplete_topic - # GET /topics/autocomplete_topic - def autocomplete_topic - term = params[:term] - if term && !term.empty? - @topics = policy_scope(Topic.where('LOWER("name") like ?', term.downcase + '%')).order('"name"') - else - @topics = [] - end - render json: autocomplete_array_json(@topics) - end + respond_to :html, :js, :json - # GET topics/:id - def show - @topic = Topic.find(params[:id]) - authorize @topic + # GET /topics/autocomplete_topic + def autocomplete_topic + term = params[:term] + @topics = if term && !term.empty? + policy_scope(Topic.where('LOWER("name") like ?', term.downcase + '%')).order('"name"') + else + [] + end + render json: autocomplete_array_json(@topics) + end - respond_to do |format| - format.html { - @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 -puts @alltopics.length -puts @allsynapses.length - @allcreators = @alltopics.map(&:user).uniq - @allcreators += @allsynapses.map(&:user).uniq - - respond_with(@allsynapses, @alltopics, @allcreators, @topic) - } - format.json { render json: @topic } - end - end - - # GET topics/:id/network - def network - @topic = Topic.find(params[:id]) - authorize @topic + # GET topics/:id + def show + @topic = Topic.find(params[:id]) + authorize @topic + respond_to do |format| + format.html do @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)) - + @allsynapses = policy_scope(Synapse.for_topic(@topic.id)).to_a + puts @alltopics.length + puts @allsynapses.length @allcreators = @alltopics.map(&:user).uniq @allcreators += @allsynapses.map(&:user).uniq - @json = Hash.new() - @json['topic'] = @topic - @json['creators'] = @allcreators - @json['relatives'] = @alltopics - @json['synapses'] = @allsynapses + respond_with(@allsynapses, @alltopics, @allcreators, @topic) + end + format.json { render json: @topic } + end + end - respond_to do |format| - format.json { render json: @json } - end + # GET topics/:id/network + def network + @topic = Topic.find(params[:id]) + authorize @topic + + @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)) + + @allcreators = @alltopics.map(&:user).uniq + @allcreators += @allsynapses.map(&:user).uniq + + @json = {} + @json['topic'] = @topic + @json['creators'] = @allcreators + @json['relatives'] = @alltopics + @json['synapses'] = @allsynapses + + respond_to do |format| + format.json { render json: @json } + end + end + + # GET topics/:id/relative_numbers + def relative_numbers + @topic = Topic.find(params[:id]) + authorize @topic + + topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : [] + + @alltopics = policy_scope(Topic.relatives1(@topic.id)).to_a.concat(policy_scope(Topic.relatives2(@topic.id)).to_a).uniq + @alltopics.delete_if do |topic| + !topicsAlreadyHas.index(topic.id).nil? end - # GET topics/:id/relative_numbers - def relative_numbers - @topic = Topic.find(params[:id]) - authorize @topic - - topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : [] - - @alltopics = policy_scope(Topic.relatives1(@topic.id)).to_a.concat(policy_scope(Topic.relatives2(@topic.id)).to_a).uniq - @alltopics.delete_if do |topic| - topicsAlreadyHas.index(topic.id) != nil - end - - @json = Hash.new(0) - @alltopics.each do |t| - @json[t.metacode.id] += 1 - end - - respond_to do |format| - format.json { render json: @json } - end + @json = Hash.new(0) + @alltopics.each do |t| + @json[t.metacode.id] += 1 end - # GET topics/:id/relatives - def relatives - @topic = Topic.find(params[:id]) - authorize @topic - - topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : [] - - alltopics = policy_scope(Topic.relatives1(@topic.id)).to_a.concat(policy_scope(Topic.relatives2(@topic.id)).to_a).uniq - alltopics.delete_if do |topic| - topicsAlreadyHas.index(topic.id.to_s) != nil - end - - #find synapses between topics in alltopics array - allsynapses = policy_scope(Synapse.for_topic(@topic.id)).to_a - synapse_ids = (allsynapses.map(&:node1_id) + allsynapses.map(&:node2_id)).uniq - allsynapses.delete_if do |synapse| - synapse_ids.index(synapse.id) != nil - end - - creatorsAlreadyHas = params[:creators] ? params[:creators].split(',').map(&:to_i) : [] - allcreators = (alltopics.map(&:user) + allsynapses.map(&:user)).uniq.delete_if do |user| - creatorsAlreadyHas.index(user.id) != nil - end - - @json = Hash.new() - @json['topics'] = alltopics - @json['synapses'] = allsynapses - @json['creators'] = allcreators - - respond_to do |format| - format.json { render json: @json } - end + respond_to do |format| + format.json { render json: @json } end + end + + # GET topics/:id/relatives + def relatives + @topic = Topic.find(params[:id]) + authorize @topic + + topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : [] + + alltopics = policy_scope(Topic.relatives1(@topic.id)).to_a.concat(policy_scope(Topic.relatives2(@topic.id)).to_a).uniq + alltopics.delete_if do |topic| + !topicsAlreadyHas.index(topic.id.to_s).nil? + end + + # find synapses between topics in alltopics array + allsynapses = policy_scope(Synapse.for_topic(@topic.id)).to_a + synapse_ids = (allsynapses.map(&:node1_id) + allsynapses.map(&:node2_id)).uniq + allsynapses.delete_if do |synapse| + !synapse_ids.index(synapse.id).nil? + end + + creatorsAlreadyHas = params[:creators] ? params[:creators].split(',').map(&:to_i) : [] + allcreators = (alltopics.map(&:user) + allsynapses.map(&:user)).uniq.delete_if do |user| + !creatorsAlreadyHas.index(user.id).nil? + end + + @json = {} + @json['topics'] = alltopics + @json['synapses'] = allsynapses + @json['creators'] = allcreators + + respond_to do |format| + format.json { render json: @json } + end + end # POST /topics # POST /topics.json diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb index ae5517e8..b6fa2acb 100644 --- a/app/controllers/users/passwords_controller.rb +++ b/app/controllers/users/passwords_controller.rb @@ -1,5 +1,6 @@ class Users::PasswordsController < Devise::PasswordsController protected + def after_resetting_password_path_for(resource) signed_in_root_path(resource) end diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 88474e21..efd6b42d 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -3,21 +3,23 @@ class Users::RegistrationsController < Devise::RegistrationsController before_action :configure_account_update_params, only: [:update] protected - def after_sign_up_path_for(resource) - signed_in_root_path(resource) - end - def after_update_path_for(resource) - signed_in_root_path(resource) - end + def after_sign_up_path_for(resource) + signed_in_root_path(resource) + end + + def after_update_path_for(resource) + signed_in_root_path(resource) + end private - def configure_sign_up_params - devise_parameter_sanitizer.for(:sign_up) << [:name, :joinedwithcode] - end - def configure_account_update_params - puts devise_parameter_sanitizer_for(:account_update) - devise_parameter_sanitizer.for(:account_update) << [:image] - end + def configure_sign_up_params + devise_parameter_sanitizer.for(:sign_up) << [:name, :joinedwithcode] + end + + def configure_account_update_params + puts devise_parameter_sanitizer_for(:account_update) + devise_parameter_sanitizer.for(:account_update) << [:image] + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f5b0aab9..0ea95211 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,38 +1,36 @@ class UsersController < ApplicationController before_action :require_user, only: [:edit, :update, :updatemetacodes] - - respond_to :html, :json + + respond_to :html, :json # GET /users/1.json def show @user = User.find(params[:id]) render json: @user - end - + end + # GET /users/:id/edit def edit @user = current_user - respond_with(@user) + respond_with(@user) end - + # PUT /users/:id def update @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 if @user.update_attributes(user_params.except(:password, :password_confirmation)) - if params[:remove_image] == "1" - @user.image = nil - end + @user.image = nil if params[:remove_image] == '1' @user.save - sign_in(@user, :bypass => true) + sign_in(@user, bypass: true) respond_to do |format| - format.html { redirect_to root_url, notice: "Account updated!" } + format.html { redirect_to root_url, notice: 'Account updated!' } end else - sign_in(@user, :bypass => true) + sign_in(@user, bypass: true) respond_to do |format| format.html { redirect_to edit_user_path(@user), notice: @user.errors.to_a[0] } end @@ -42,53 +40,51 @@ class UsersController < ApplicationController correct_pass = @user.valid_password?(params[:current_password]) if correct_pass && @user.update_attributes(user_params) - if params[:remove_image] == "1" - @user.image = nil - end + @user.image = nil if params[:remove_image] == '1' @user.save - sign_in(@user, :bypass => true) + sign_in(@user, bypass: true) respond_to do |format| - format.html { redirect_to root_url, notice: "Account updated!" } + format.html { redirect_to root_url, notice: 'Account updated!' } end else respond_to do |format| if correct_pass 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] } else - sign_in(@user, :bypass => true) - format.html { redirect_to edit_user_path(@user), notice: "Incorrect current password" } + sign_in(@user, bypass: true) + format.html { redirect_to edit_user_path(@user), notice: 'Incorrect current password' } end end end end end - + # GET /users/:id/details [.json] def details @user = User.find(params[:id]) - - @details = Hash.new + + @details = {} @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['generation'] = @user.generation @details['numSynapses'] = @user.synapses.count @details['numTopics'] = @user.topics.count @details['numMaps'] = @user.maps.count - render json: @details + render json: @details end # PUT /user/updatemetacodes def updatemetacodes @user = current_user - + @m = params[:metacodes][:value] - @user.settings.metacodes=@m.split(',') - + @user.settings.metacodes = @m.split(',') + @user.save respond_to do |format| diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 38e82922..555a32d2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,22 +1,22 @@ module ApplicationHelper def get_metacodeset @m = current_user.settings.metacodes - set = @m[0].include?("metacodeset") ? MetacodeSet.find(@m[0].sub("metacodeset-","").to_i) : false - return set + set = @m[0].include?('metacodeset') ? MetacodeSet.find(@m[0].sub('metacodeset-', '').to_i) : false + set end def user_metacodes @m = current_user.settings.metacodes set = get_metacodeset - if set - @metacodes = set.metacodes.to_a - else - @metacodes = Metacode.where(id: @m).to_a - end - @metacodes.sort! {|m1,m2| m2.name.downcase <=> m1.name.downcase }.rotate!(-1) + @metacodes = if set + set.metacodes.to_a + else + Metacode.where(id: @m).to_a + end + @metacodes.sort! { |m1, m2| m2.name.downcase <=> m1.name.downcase }.rotate!(-1) end 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 diff --git a/app/helpers/devise_helper.rb b/app/helpers/devise_helper.rb index 8679a258..5081cba0 100644 --- a/app/helpers/devise_helper.rb +++ b/app/helpers/devise_helper.rb @@ -1,26 +1,9 @@ module DeviseHelper def devise_error_messages! - - 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 - #
- #

#{sentence}

- # - #
- #HTML - - #html.html_safe + resource.errors.to_a[0] end def devise_error_messages? resource.errors.empty? ? false : true end - -end \ No newline at end of file +end diff --git a/app/helpers/maps_helper.rb b/app/helpers/maps_helper.rb index 8a48ab33..3f60fe4d 100644 --- a/app/helpers/maps_helper.rb +++ b/app/helpers/maps_helper.rb @@ -1,5 +1,4 @@ module MapsHelper - ## this one is for building our custom JSON autocomplete format for typeahead def autocomplete_map_array_json(maps) temp = [] @@ -13,16 +12,16 @@ module MapsHelper map['topicCount'] = m.topics.count map['synapseCount'] = m.synapses.count map['contributorCount'] = m.contributors.count - map['rtype'] = "map" - + map['rtype'] = 'map' + contributorTip = '' 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) - m.contributors.each_with_index do |c, index| + m.contributors.each_with_index do |c, _index| userImage = c.image.url(:thirtytwo) name = c.name - contributorTip += '
  • ' + '' + name + '
  • ' + contributorTip += '
  • ' + '' + name + '
  • ' end end map['contributorTip'] = contributorTip @@ -30,7 +29,6 @@ module MapsHelper temp.push map end - return temp + temp end - end diff --git a/app/helpers/synapses_helper.rb b/app/helpers/synapses_helper.rb index 19286bcd..470292e5 100644 --- a/app/helpers/synapses_helper.rb +++ b/app/helpers/synapses_helper.rb @@ -1,6 +1,4 @@ module SynapsesHelper - - ## this one is for building our custom JSON autocomplete format for typeahead def autocomplete_synapse_generic_json(unique) temp = [] @@ -8,29 +6,28 @@ module SynapsesHelper synapse = {} synapse['label'] = s.desc synapse['value'] = s.desc - + temp.push synapse end - return temp + temp end - + ## this one is for building our custom JSON autocomplete format for typeahead def autocomplete_synapse_array_json(synapses) temp = [] synapses.each do |s| synapse = {} 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['permission'] = s.permission synapse['mapCount'] = s.maps.count synapse['originator'] = s.user.name synapse['originatorImage'] = s.user.image.url(:thirtytwo) - synapse['rtype'] = "synapse" - + synapse['rtype'] = 'synapse' + temp.push synapse end - return temp + temp end - end diff --git a/app/helpers/topics_helper.rb b/app/helpers/topics_helper.rb index 9e7d82dc..bb589e9a 100644 --- a/app/helpers/topics_helper.rb +++ b/app/helpers/topics_helper.rb @@ -1,5 +1,4 @@ module TopicsHelper - ## this one is for building our custom JSON autocomplete format for typeahead def autocomplete_array_json(topics) temp = [] @@ -16,46 +15,42 @@ module TopicsHelper topic['synapseCount'] = t.synapses.count topic['originator'] = t.user.name topic['originatorImage'] = t.user.image.url(:thirtytwo) - topic['rtype'] = "topic" + topic['rtype'] = 'topic' topic['inmaps'] = t.inmaps topic['inmapsLinks'] = t.inmapsLinks - + temp.push topic end - return temp + temp end - #find all nodes in any given nodes network + # find all nodes in any given nodes network 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 array.nil? - array = Array.new - end + # if the array of nodes is empty initialize it + array = [] if array.nil? - # add the node to the array - array.push(node) + # add the node to the array + array.push(node) - if count == 0 - return array - end + return array if count == 0 - count = count - 1 + count -= 1 - # 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-array).empty? - return array - else - (node.relatives-array).each do |relative| - array = (array | network(relative, array, count)) - end - return array - end + # check if each relative is already in the array and if not, call the network function again + if !node.relatives.empty? + if (node.relatives - array).empty? + return array + else + (node.relatives - array).each do |relative| + array = (array | network(relative, array, count)) + end + return array + end - elsif node.relatives.empty? - return array - end + elsif node.relatives.empty? + return array + end end end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 69335da1..8144dfd8 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -3,7 +3,7 @@ module UsersHelper def autocomplete_user_array_json(users) json_users = [] users.each do |user| - json_users.push user.as_json_for_autocomplete + json_users.push user.as_json_for_autocomplete end json_users end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 0d9431a3..d934e218 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,4 @@ class ApplicationMailer < ActionMailer::Base - default from: "team@metamaps.cc" + default from: 'team@metamaps.cc' layout 'mailer' end diff --git a/app/mailers/map_mailer.rb b/app/mailers/map_mailer.rb index dd164cf3..94e8ebd5 100644 --- a/app/mailers/map_mailer.rb +++ b/app/mailers/map_mailer.rb @@ -1,5 +1,5 @@ class MapMailer < ApplicationMailer - default from: "team@metamaps.cc" + default from: 'team@metamaps.cc' def invite_to_edit_email(map, inviter, invitee) @inviter = inviter diff --git a/app/models/event.rb b/app/models/event.rb index 66431b61..67606aa2 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,7 +1,7 @@ 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 :map belongs_to :user @@ -10,22 +10,21 @@ class Event < ActiveRecord::Base after_create :notify_webhooks!, if: :map - validates_inclusion_of :kind, :in => KINDS - validates_presence_of :eventable + validates :kind, inclusion: { in: KINDS } + validates :eventable, presence: true - #def notify!(user) + # def notify!(user) # notifications.create!(user: user) - #end + # end def belongs_to?(this_user) - self.user_id == this_user.id + user_id == this_user.id end def notify_webhooks! - #group = self.discussion.group - self.map.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self } - #group.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self } + # group = self.discussion.group + map.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self } + # group.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self } end handle_asynchronously :notify_webhooks! - end diff --git a/app/models/events/conversation_started_on_map.rb b/app/models/events/conversation_started_on_map.rb index f8a0ca2c..4ca922be 100644 --- a/app/models/events/conversation_started_on_map.rb +++ b/app/models/events/conversation_started_on_map.rb @@ -1,18 +1,10 @@ class Events::ConversationStartedOnMap < Event - #after_create :notify_users! + # after_create :notify_users! def self.publish!(map, user) - create!(kind: "conversation_started_on_map", + create!(kind: 'conversation_started_on_map', eventable: map, map: map, user: user) end - - private - - #def notify_users! - # unless comment_vote.user == comment_vote.comment_user - # notify!(comment_vote.comment_user) - # end - #end end diff --git a/app/models/events/new_mapping.rb b/app/models/events/new_mapping.rb index 7d6e0696..d7b91576 100644 --- a/app/models/events/new_mapping.rb +++ b/app/models/events/new_mapping.rb @@ -1,18 +1,10 @@ class Events::NewMapping < Event - #after_create :notify_users! + # after_create :notify_users! 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, map: mapping.map, user: user) end - - private - - #def notify_users! - # unless comment_vote.user == comment_vote.comment_user - # notify!(comment_vote.comment_user) - # end - #end end diff --git a/app/models/events/user_present_on_map.rb b/app/models/events/user_present_on_map.rb index e40df243..45726002 100644 --- a/app/models/events/user_present_on_map.rb +++ b/app/models/events/user_present_on_map.rb @@ -1,18 +1,10 @@ class Events::UserPresentOnMap < Event - #after_create :notify_users! + # after_create :notify_users! def self.publish!(map, user) - create!(kind: "user_present_on_map", + create!(kind: 'user_present_on_map', eventable: map, map: map, user: user) end - - private - - #def notify_users! - # unless comment_vote.user == comment_vote.comment_user - # notify!(comment_vote.comment_user) - # end - #end end diff --git a/app/models/in_metacode_set.rb b/app/models/in_metacode_set.rb index 117033d6..c1b1ca33 100644 --- a/app/models/in_metacode_set.rb +++ b/app/models/in_metacode_set.rb @@ -1,4 +1,4 @@ class InMetacodeSet < ActiveRecord::Base - 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, class_name: 'Metacode', foreign_key: 'metacode_id' + belongs_to :metacode_set, class_name: 'MetacodeSet', foreign_key: 'metacode_set_id' end diff --git a/app/models/map.rb b/app/models/map.rb index 8ffe14d6..3f7a265a 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -1,11 +1,10 @@ class Map < ActiveRecord::Base - belongs_to :user has_many :topicmappings, -> { Mapping.topicmapping }, 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 :synapses, through: :synapsemappings, source: :mappable, source_type: "Synapse" + has_many :topics, through: :topicmappings, source: :mappable, source_type: 'Topic' + has_many :synapses, through: :synapsemappings, source: :mappable, source_type: 'Synapse' has_many :messages, as: :resource, 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 # This method associates the attribute ":image" with a file attachment - has_attached_file :screenshot, :styles => { - :thumb => ['188x126#', :png] - #:full => ['940x630#', :png] + has_attached_file :screenshot, styles: { + thumb: ['188x126#', :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 :arranged, inclusion: { in: [true, false] } @@ -27,29 +26,29 @@ class Map < ActiveRecord::Base validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) } # 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 - topicmappings + synapsemappings + topicmappings + synapsemappings end def mk_permission Perm.short(permission) end - #return an array of the contributors to the map + # return an array of the contributors to the map def contributors contributors = [] - self.mappings.each do |m| - contributors.push(m.user) if !contributors.include?(m.user) + mappings.each do |m| + contributors.push(m.user) unless contributors.include?(m.user) end - return contributors + contributors end def editors - collaborators + [self.user] + collaborators + [user] end def topic_count @@ -60,15 +59,13 @@ class Map < ActiveRecord::Base synapses.length end - def user_name - user.name - end + delegate :name, to: :user, prefix: true def user_image user.image.url end - def contributor_count + def contributor_count contributors.length end @@ -81,15 +78,15 @@ class Map < ActiveRecord::Base end def created_at_str - created_at.strftime("%m/%d/%Y") + created_at.strftime('%m/%d/%Y') end def updated_at_str - updated_at.strftime("%m/%d/%Y") + updated_at.strftime('%m/%d/%Y') end - 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]) + 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[:created_at_clean] = created_at_str json[:updated_at_clean] = updated_at_str json @@ -103,11 +100,10 @@ class Map < ActiveRecord::Base attr_accessor :content_type, :original_filename end - data.content_type = "image/png" - data.original_filename = File.basename('map-' + self.id.to_s + '-screenshot.png') + data.content_type = 'image/png' + data.original_filename = File.basename('map-' + id.to_s + '-screenshot.png') self.screenshot = data - self.save + save end - end diff --git a/app/models/mapping.rb b/app/models/mapping.rb index 1a37f490..ceb15538 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -1,29 +1,25 @@ class Mapping < ActiveRecord::Base - scope :topicmapping, -> { where(mappable_type: :Topic) } scope :synapsemapping, -> { where(mappable_type: :Synapse) } 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 - validates :xloc, presence: true, - unless: Proc.new { |m| m.mappable_type == 'Synapse' } + validates :xloc, presence: true, + unless: proc { |m| m.mappable_type == 'Synapse' } validates :yloc, presence: true, - unless: Proc.new { |m| m.mappable_type == 'Synapse' } + unless: proc { |m| m.mappable_type == 'Synapse' } validates :map, presence: true validates :mappable, presence: true - - def user_name - self.user.name - end + + delegate :name, to: :user, prefix: true def user_image - self.user.image.url + user.image.url end - def as_json(options={}) - super(:methods =>[:user_name, :user_image]) + def as_json(_options = {}) + super(methods: [:user_name, :user_image]) end - end diff --git a/app/models/message.rb b/app/models/message.rb index 0481192f..597caeb7 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -1,19 +1,15 @@ class Message < ActiveRecord::Base - belongs_to :user belongs_to :resource, polymorphic: true - def user_name - self.user.name - end + delegate :name, to: :user, prefix: true def user_image - self.user.image.url + user.image.url end - def as_json(options={}) - json = super(:methods =>[:user_name, :user_image]) + def as_json(_options = {}) + json = super(methods: [:user_name, :user_image]) json end - end diff --git a/app/models/metacode.rb b/app/models/metacode.rb index d3a8160b..bc0bef7b 100644 --- a/app/models/metacode.rb +++ b/app/models/metacode.rb @@ -1,21 +1,21 @@ class Metacode < ActiveRecord::Base has_many :in_metacode_sets - has_many :metacode_sets, :through => :in_metacode_sets + has_many :metacode_sets, through: :in_metacode_sets has_many :topics # This method associates the attribute ":aws_icon" with a file attachment - has_attached_file :aws_icon, :styles => { - :ninetysix => ['96x96#', :png], + has_attached_file :aws_icon, styles: { + 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 - 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 :manual_icon_https before_create do - self.manual_icon = nil if self.manual_icon == "" + self.manual_icon = nil if manual_icon == '' end def icon(*args) @@ -26,37 +26,37 @@ class Metacode < ActiveRecord::Base end end - def as_json(options={}) + def as_json(options = {}) default = super(options) default[:icon] = icon default.except('aws_icon_file_name', 'aws_icon_content_type', 'aws_icon_file_size', 'aws_icon_updated_at', 'manual_icon') end def hasSelected(user) - return true if user.settings.metacodes.include? self.id.to_s - return false + return true if user.settings.metacodes.include? id.to_s + false end def inMetacodeSet(metacode_set) - return true if self.metacode_sets.include? metacode_set - return false + return true if metacode_sets.include? metacode_set + false end private def aws_xor_manual_icon 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 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 def manual_icon_https if manual_icon.present? 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 diff --git a/app/models/metacode_set.rb b/app/models/metacode_set.rb index d06de1e4..cc672784 100644 --- a/app/models/metacode_set.rb +++ b/app/models/metacode_set.rb @@ -1,5 +1,5 @@ class MetacodeSet < ActiveRecord::Base belongs_to :user has_many :in_metacode_sets - has_many :metacodes, :through => :in_metacode_sets + has_many :metacodes, through: :in_metacode_sets end diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb index a49ed648..0ccea1c8 100644 --- a/app/models/permitted_params.rb +++ b/app/models/permitted_params.rb @@ -1,23 +1,22 @@ 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 - permitted_attributes = self.send("#{kind}_attributes") + permitted_attributes = send("#{kind}_attributes") params.require(kind).permit(*permitted_attributes) end alias_method :"api_#{kind}", kind.to_sym end - alias :read_attribute_for_serialization :send + alias read_attribute_for_serialization send def token_attributes [:description] end - + def map_attributes [:name, :desc, :permission, :arranged] end - + def synapse_attributes [:desc, :category, :weight, :permission, :node1_id, :node2_id] end @@ -29,5 +28,4 @@ class PermittedParams < Struct.new(:params) def mapping_attributes [:xloc, :yloc, :map_id, :mappable_type, :mappable_id] end - end diff --git a/app/models/synapse.rb b/app/models/synapse.rb index 7e361af3..710cb029 100644 --- a/app/models/synapse.rb +++ b/app/models/synapse.rb @@ -1,12 +1,12 @@ class Synapse < ActiveRecord::Base 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 :topic2, :class_name => "Topic", :foreign_key => "node2_id" + belongs_to :topic1, class_name: 'Topic', foreign_key: 'node1_id' + belongs_to :topic2, class_name: 'Topic', foreign_key: 'node2_id' 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 } @@ -17,14 +17,12 @@ class Synapse < ActiveRecord::Base validates :category, inclusion: { in: ['from-to', 'both'], allow_nil: true } - scope :for_topic, ->(topic_id = nil) { - where("node1_id = ? OR node2_id = ?", topic_id, topic_id) - } + scope :for_topic, ->(topic_id = nil) { + where('node1_id = ? OR node2_id = ?', topic_id, topic_id) + } # :nocov: - def user_name - user.name - end + delegate :name, to: :user, prefix: true # :nocov: # :nocov: @@ -36,14 +34,14 @@ class Synapse < ActiveRecord::Base # :nocov: def collaborator_ids 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 [] end end # :nocov: - - # :nocov: + + # :nocov: def calculated_permission if defer_to_map defer_to_map.permission @@ -52,11 +50,10 @@ class Synapse < ActiveRecord::Base end end # :nocov: - + # :nocov: - def as_json(options={}) - super(:methods =>[:user_name, :user_image, :calculated_permission, :collaborator_ids]) + def as_json(_options = {}) + super(methods: [:user_name, :user_image, :calculated_permission, :collaborator_ids]) end # :nocov: - end diff --git a/app/models/token.rb b/app/models/token.rb index 714730fc..1dac3fde 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -6,6 +6,7 @@ class Token < ActiveRecord::Base CHARS = 32 private + def assign_token self.token = generate_token end @@ -13,10 +14,7 @@ class Token < ActiveRecord::Base def generate_token loop do candidate = SecureRandom.base64(CHARS).gsub(/\W/, '') - if candidate.size >= CHARS - return candidate[0...CHARS] - end + return candidate[0...CHARS] if candidate.size >= CHARS end end - end diff --git a/app/models/topic.rb b/app/models/topic.rb index 61f405de..4ff6ac50 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -2,61 +2,59 @@ class Topic < ActiveRecord::Base include TopicsHelper 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 :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', dependent: :destroy - has_many :topics1, :through => :synapses2, source: :topic1 - has_many :topics2, :through => :synapses1, source: :topic2 + 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 :topics1, through: :synapses2, source: :topic1 + has_many :topics2, through: :synapses1, source: :topic2 has_many :mappings, as: :mappable, dependent: :destroy - has_many :maps, :through => :mappings + has_many :maps, through: :mappings belongs_to :metacode validates :permission, presence: true validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) } - + # This method associates the attribute ":image" with a file attachment has_attached_file :image - - #, styles: { + + # , styles: { # thumb: '100x100>', # square: '200x200#', # medium: '300x300>' - #} + # } # 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 has_attached_file :audio # 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 - synapses1 + synapses2 - end - - def relatives - topics1 + topics2 + synapses1 + synapses2 end - scope :relatives1, ->(topic_id = nil) { + def relatives + topics1 + topics2 + end + + scope :relatives1, ->(topic_id = nil) { includes(:topics1) - .where('synapses.node1_id = ?', topic_id) - .references(:synapses) + .where('synapses.node1_id = ?', topic_id) + .references(:synapses) } scope :relatives2, ->(topic_id = nil) { includes(:topics2) - .where('synapses.node2_id = ?', topic_id) - .references(:synapses) + .where('synapses.node2_id = ?', topic_id) + .references(:synapses) } - def user_name - user.name - end + delegate :name, to: :user, prefix: true def user_image user.image.url @@ -86,19 +84,19 @@ class Topic < ActiveRecord::Base end end - def as_json(options={}) - super(:methods =>[:user_name, :user_image, :map_count, :synapse_count, :inmaps, :inmapsLinks, :calculated_permission, :collaborator_ids]) + def as_json(_options = {}) + super(methods: [:user_name, :user_image, :map_count, :synapse_count, :inmaps, :inmapsLinks, :calculated_permission, :collaborator_ids]) end def collaborator_ids 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 [] end end - # TODO move to a decorator? + # TODO: move to a decorator? def synapses_csv(output_format = 'array') output = [] synapses.each do |synapse| @@ -108,7 +106,7 @@ class Topic < ActiveRecord::Base elsif synapse.node2_id == id output << synapse.node2_id.to_s + '<-' + synapse.node1_id.to_s else - fail 'invalid synapse on topic in synapse_csv' + raise 'invalid synapse on topic in synapse_csv' end elsif synapse.category == 'both' if synapse.node1_id == id @@ -116,7 +114,7 @@ class Topic < ActiveRecord::Base elsif synapse.node2_id == id output << synapse.node2_id.to_s + '<->' + synapse.node1_id.to_s else - fail 'invalid synapse on topic in synapse_csv' + raise 'invalid synapse on topic in synapse_csv' end end end @@ -125,15 +123,15 @@ class Topic < ActiveRecord::Base elsif output_format == 'text' return output.join('; ') else - fail 'invalid argument to synapses_csv' + raise 'invalid argument to synapses_csv' end output end def topic_autocomplete_method - "Get: #{self.name}" + "Get: #{name}" end - + def mk_permission Perm.short(permission) end diff --git a/app/models/user.rb b/app/models/user.rb index a38d7177..236bf4e1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,7 +1,6 @@ require 'open-uri' class User < ActiveRecord::Base - has_many :topics has_many :synapses has_many :maps @@ -9,47 +8,46 @@ class User < ActiveRecord::Base has_many :tokens has_many :user_maps, dependent: :destroy has_many :shared_maps, through: :user_maps, source: :map - + after_create :generate_code devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable serialize :settings, UserPreference - validates :password, :presence => true, - :length => { :within => 8..40 }, - :on => :create - validates :password, :length => { :within => 8..40 }, - :allow_blank => true, - :on => :update - validates_confirmation_of :password + validates :password, presence: true, + length: { within: 8..40 }, + on: :create + validates :password, length: { within: 8..40 }, + allow_blank: true, + on: :update + validates :password, confirmation: true - validates_presence_of :name # done by devise - validates_presence_of :email # done by devise - validates_uniqueness_of :name # done by devise - validates_uniqueness_of :email # done by devise + validates :name, presence: true # done by devise + validates :email, presence: true # done by devise + validates :name, uniqueness: true # 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 - has_attached_file :image, :styles => { - :thirtytwo => ['32x32#', :png], - :sixtyfour => ['64x64#', :png], - :ninetysix => ['96x96#', :png], - :onetwentyeight => ['128x128#', :png] + has_attached_file :image, styles: { + thirtytwo: ['32x32#', :png], + sixtyfour: ['64x64#', :png], + ninetysix: ['96x96#', :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 - validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/ + validates_attachment_content_type :image, content_type: %r(\Aimage/.*\Z) # override default as_json - def as_json(options={}) - { :id => self.id, - :name => self.name, - :image => self.image.url(:sixtyfour), - :admin => self.admin - } + def as_json(_options = {}) + { id: id, + name: name, + image: image.url(:sixtyfour), + admin: admin } end def as_json_for_autocomplete @@ -60,14 +58,14 @@ class User < ActiveRecord::Base json['profile'] = image.url(:sixtyfour) json['mapCount'] = maps.count json['generation'] = generation - json['created_at'] = created_at.strftime("%m/%d/%Y") - json['rtype'] = "mapper" + json['created_at'] = created_at.strftime('%m/%d/%Y') + json['rtype'] = 'mapper' json 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 - self.code ||= rand(36**8).to_s(36) + self.code ||= rand(36**8).to_s(36) $codes.push(self.code) self.generation = get_generation! end @@ -82,14 +80,11 @@ class User < ActiveRecord::Base def settings # make sure we always return a UserPreference instance - if read_attribute(:settings).nil? - write_attribute :settings, UserPreference.new - end - read_attribute :settings + self[:settings] = UserPreference.new if self[:settings].nil? + self[:settings] end def settings=(val) - write_attribute :settings, val + self[:settings] = val end - end diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index aaced385..175e9f91 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -1,11 +1,11 @@ class UserPreference attr_accessor :metacodes - + def initialize array = [] - Metacode.all.each do |m| + Metacode.all.find_each do |m| array.push(m.id.to_s) end @metacodes = array end -end \ No newline at end of file +end diff --git a/app/models/webhook.rb b/app/models/webhook.rb index 4e20272c..86d2333d 100644 --- a/app/models/webhook.rb +++ b/app/models/webhook.rb @@ -3,11 +3,10 @@ class Webhook < ActiveRecord::Base validates :uri, 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 } def headers {} end - end diff --git a/app/models/webhooks/slack/base.rb b/app/models/webhooks/slack/base.rb index 3337e320..97cf1f04 100644 --- a/app/models/webhooks/slack/base.rb +++ b/app/models/webhooks/slack/base.rb @@ -2,15 +2,15 @@ Webhooks::Slack::Base = Struct.new(:event) do include Routing def username - "Metamaps Bot" + 'Metamaps Bot' end def icon_url - "https://pbs.twimg.com/profile_images/539300245029392385/dJ1bwnw7.jpeg" + 'https://pbs.twimg.com/profile_images/539300245029392385/dJ1bwnw7.jpeg' end def text - "something" + 'something' end def attachments @@ -22,11 +22,11 @@ Webhooks::Slack::Base = Struct.new(:event) do }] end - alias :read_attribute_for_serialization :send + alias_method :read_attribute_for_serialization, :send private - #def motion_vote_field + # def motion_vote_field # { # title: "Vote on this proposal", # value: "#{proposal_link(eventable, "yes")} · " + @@ -34,23 +34,23 @@ Webhooks::Slack::Base = Struct.new(:event) do # "#{proposal_link(eventable, "no")} · " + # "#{proposal_link(eventable, "block")}" # } - #end + # end def view_map_on_metamaps(text = nil) "<#{map_url(event.map)}|#{text || event.map.name}>" 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) } - #end + # end - #def proposal_link(proposal, position = nil) + # def proposal_link(proposal, position = nil) # 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}>" - #end + # end def eventable @eventable ||= event.eventable @@ -59,10 +59,9 @@ Webhooks::Slack::Base = Struct.new(:event) do def author @author ||= eventable.author end - end -#webhooks: +# webhooks: # slack: # motion_closed: "*%{name}* has closed" # motion_closing_soon: "*%{name}* has a proposal closing in 24 hours" diff --git a/app/models/webhooks/slack/conversation_started_on_map.rb b/app/models/webhooks/slack/conversation_started_on_map.rb index 489559c7..5fa325d0 100644 --- a/app/models/webhooks/slack/conversation_started_on_map.rb +++ b/app/models/webhooks/slack/conversation_started_on_map.rb @@ -1,27 +1,25 @@ class Webhooks::Slack::ConversationStartedOnMap < Webhooks::Slack::Base - def text "There is a live conversation starting on map *#{event.map.name}*. #{view_map_on_metamaps('Join in!')}" 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 - "" #{}"*#{eventable.name}*\n#{eventable.description}\n" + '' # {}"*#{eventable.name}*\n#{eventable.description}\n" end def attachment_title - "" #proposal_link(eventable) + '' # proposal_link(eventable) end def attachment_text - "" # "#{eventable.description}\n" + '' # "#{eventable.description}\n" end def attachment_fields [{ - title: "nothing", - value: "nothing" - }] #[motion_vote_field] + title: 'nothing', + value: 'nothing' + }] # [motion_vote_field] end - end diff --git a/app/models/webhooks/slack/synapse_added_to_map.rb b/app/models/webhooks/slack/synapse_added_to_map.rb index 3d70450b..5dc636e1 100644 --- a/app/models/webhooks/slack/synapse_added_to_map.rb +++ b/app/models/webhooks/slack/synapse_added_to_map.rb @@ -1,26 +1,24 @@ class Webhooks::Slack::SynapseAddedToMap < Webhooks::Slack::Base - 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 def attachment_fallback - "" #{}"*#{eventable.name}*\n#{eventable.description}\n" + '' # {}"*#{eventable.name}*\n#{eventable.description}\n" end def attachment_title - "" #proposal_link(eventable) + '' # proposal_link(eventable) end def attachment_text - "" # "#{eventable.description}\n" + '' # "#{eventable.description}\n" end def attachment_fields [{ - title: "nothing", - value: "nothing" - }] #[motion_vote_field] + title: 'nothing', + value: 'nothing' + }] # [motion_vote_field] end - end diff --git a/app/models/webhooks/slack/topic_added_to_map.rb b/app/models/webhooks/slack/topic_added_to_map.rb index 3574a464..07a20759 100644 --- a/app/models/webhooks/slack/topic_added_to_map.rb +++ b/app/models/webhooks/slack/topic_added_to_map.rb @@ -1,27 +1,25 @@ class Webhooks::Slack::TopicAddedToMap < Webhooks::Slack::Base - 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 - # 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 - "" #{}"*#{eventable.name}*\n#{eventable.description}\n" + '' # {}"*#{eventable.name}*\n#{eventable.description}\n" end def attachment_title - "" #proposal_link(eventable) + '' # proposal_link(eventable) end def attachment_text - "" # "#{eventable.description}\n" + '' # "#{eventable.description}\n" end def attachment_fields [{ - title: "nothing", - value: "nothing" - }] #[motion_vote_field] + title: 'nothing', + value: 'nothing' + }] # [motion_vote_field] end - end diff --git a/app/models/webhooks/slack/user_present_on_map.rb b/app/models/webhooks/slack/user_present_on_map.rb index b8d0fac5..666d5121 100644 --- a/app/models/webhooks/slack/user_present_on_map.rb +++ b/app/models/webhooks/slack/user_present_on_map.rb @@ -1,27 +1,25 @@ class Webhooks::Slack::UserPresentOnMap < Webhooks::Slack::Base - def text "Mapper *#{event.user.name}* has joined the map *#{event.map.name}*. #{view_map_on_metamaps('Map with them')}" 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 - "" #{}"*#{eventable.name}*\n#{eventable.description}\n" + '' # {}"*#{eventable.name}*\n#{eventable.description}\n" end def attachment_title - "" #proposal_link(eventable) + '' # proposal_link(eventable) end def attachment_text - "" # "#{eventable.description}\n" + '' # "#{eventable.description}\n" end def attachment_fields [{ - title: "nothing", - value: "nothing" - }] #[motion_vote_field] + title: 'nothing', + value: 'nothing' + }] # [motion_vote_field] end - end diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index e0352be2..a9835c98 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -11,7 +11,7 @@ class ApplicationPolicy end def show? - scope.where(:id => record.id).exists? + scope.where(id: record.id).exists? end def create? @@ -34,7 +34,7 @@ class ApplicationPolicy false 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 # explicitly say they want to (E.g. seeing/editing/deleting private # maps - they should be able to, but not by accident) diff --git a/app/policies/main_policy.rb b/app/policies/main_policy.rb index ee7f9fc9..77ab373c 100644 --- a/app/policies/main_policy.rb +++ b/app/policies/main_policy.rb @@ -1,5 +1,5 @@ class MainPolicy < ApplicationPolicy - def initialize(user, record) + def initialize(user, _record) @user = user @record = nil end diff --git a/app/policies/map_policy.rb b/app/policies/map_policy.rb index 17943086..5255319c 100644 --- a/app/policies/map_policy.rb +++ b/app/policies/map_policy.rb @@ -1,7 +1,7 @@ class MapPolicy < ApplicationPolicy class Scope < Scope def resolve - visible = ['public', 'commons'] + visible = %w(public commons) permission = 'maps.permission IN (?)' if user shared_maps = user.shared_maps.map(&:id) diff --git a/app/policies/mapping_policy.rb b/app/policies/mapping_policy.rb index ce8522df..07b6d0c5 100644 --- a/app/policies/mapping_policy.rb +++ b/app/policies/mapping_policy.rb @@ -1,17 +1,17 @@ class MappingPolicy < ApplicationPolicy class Scope < Scope 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 # 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 - visible = ['public', 'commons'] + visible = %w(public commons) permission = 'maps.permission IN (?)' if user scope.joins(:maps).where(permission + ' OR maps.user_id = ?', visible, user.id) else scope.where(permission, visible) - end + end end end diff --git a/app/policies/message_policy.rb b/app/policies/message_policy.rb index af2efb0c..8df6e916 100644 --- a/app/policies/message_policy.rb +++ b/app/policies/message_policy.rb @@ -1,19 +1,17 @@ class MessagePolicy < ApplicationPolicy class Scope < Scope def resolve - visible = ['public', 'commons'] + visible = %w(public commons) permission = 'maps.permission IN (?)' if user scope.joins(:maps).where(permission + ' OR maps.user_id = ?', visible, user.id) else scope.where(permission, visible) - end + end end end - def show? - resource_policy.show? - end + delegate :show?, to: :resource_policy def create? record.resource.present? && resource_policy.update? @@ -32,5 +30,4 @@ class MessagePolicy < ApplicationPolicy def resource_policy @resource_policy ||= Pundit.policy(user, record.resource) end - end diff --git a/app/policies/synapse_policy.rb b/app/policies/synapse_policy.rb index 9b1a8524..97d993f5 100644 --- a/app/policies/synapse_policy.rb +++ b/app/policies/synapse_policy.rb @@ -1,7 +1,7 @@ class SynapsePolicy < ApplicationPolicy class Scope < Scope def resolve - visible = ['public', 'commons'] + visible = %w(public commons) permission = 'synapses.permission IN (?)' if user 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? user.present? - # todo add validation against whether you can see both topics + # TODO: add validation against whether you can see both topics end def show? @@ -25,11 +25,11 @@ class SynapsePolicy < ApplicationPolicy end def update? - if not user.present? + if !user.present? false elsif record.defer_to_map.present? - map_policy.update? - else + map_policy.update? + else record.permission == 'commons' || record.user == user end end diff --git a/app/policies/token_policy.rb b/app/policies/token_policy.rb index 79ab17ae..e150fec9 100644 --- a/app/policies/token_policy.rb +++ b/app/policies/token_policy.rb @@ -4,13 +4,13 @@ class TokenPolicy < ApplicationPolicy if user scope.where('tokens.user_id = ?', user.id) 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 def create? - user.present? + user.present? end def my_tokens? @@ -20,5 +20,4 @@ class TokenPolicy < ApplicationPolicy def destroy? user.present? && record.user == user end - end diff --git a/app/policies/topic_policy.rb b/app/policies/topic_policy.rb index 2eb2abb6..a8d5df2a 100644 --- a/app/policies/topic_policy.rb +++ b/app/policies/topic_policy.rb @@ -1,7 +1,7 @@ class TopicPolicy < ApplicationPolicy class Scope < Scope def resolve - visible = ['public', 'commons'] + visible = %w(public commons) permission = 'topics.permission IN (?)' if user scope.where(permission + ' OR topics.defer_to_map_id IN (?) OR topics.user_id = ?', visible, user.shared_maps.map(&:id), user.id) @@ -24,11 +24,11 @@ class TopicPolicy < ApplicationPolicy end def update? - if not user.present? + if !user.present? false elsif record.defer_to_map.present? - map_policy.update? - else + map_policy.update? + else record.permission == 'commons' || record.user == user end end diff --git a/app/serializers/new_map_serializer.rb b/app/serializers/new_map_serializer.rb index 3c56f82f..c323b09d 100644 --- a/app/serializers/new_map_serializer.rb +++ b/app/serializers/new_map_serializer.rb @@ -13,5 +13,4 @@ class NewMapSerializer < ActiveModel::Serializer has_many :mappings, serializer: NewMappingSerializer has_many :contributors, root: :users, serializer: NewUserSerializer has_many :collaborators, root: :users, serializer: NewUserSerializer - end diff --git a/app/serializers/new_mapping_serializer.rb b/app/serializers/new_mapping_serializer.rb index 4e65e161..3ef9a8b6 100644 --- a/app/serializers/new_mapping_serializer.rb +++ b/app/serializers/new_mapping_serializer.rb @@ -12,8 +12,8 @@ class NewMappingSerializer < ActiveModel::Serializer has_one :map, serializer: NewMapSerializer def filter(keys) - keys.delete(:xloc) unless object.mappable_type == "Topic" - keys.delete(:yloc) unless object.mappable_type == "Topic" + keys.delete(:xloc) unless object.mappable_type == 'Topic' + keys.delete(:yloc) unless object.mappable_type == 'Topic' keys end end diff --git a/app/serializers/new_metacode_serializer.rb b/app/serializers/new_metacode_serializer.rb index e664e7ea..b20f25b6 100644 --- a/app/serializers/new_metacode_serializer.rb +++ b/app/serializers/new_metacode_serializer.rb @@ -4,4 +4,4 @@ class NewMetacodeSerializer < ActiveModel::Serializer :manual_icon, :color, :aws_icon -end +end diff --git a/app/serializers/new_synapse_serializer.rb b/app/serializers/new_synapse_serializer.rb index b145d605..5cdf644d 100644 --- a/app/serializers/new_synapse_serializer.rb +++ b/app/serializers/new_synapse_serializer.rb @@ -11,5 +11,4 @@ class NewSynapseSerializer < ActiveModel::Serializer has_one :topic1, root: :topics, serializer: NewTopicSerializer has_one :topic2, root: :topics, serializer: NewTopicSerializer has_one :user, serializer: NewUserSerializer - end diff --git a/app/serializers/new_topic_serializer.rb b/app/serializers/new_topic_serializer.rb index cdbbedf9..2eb718df 100644 --- a/app/serializers/new_topic_serializer.rb +++ b/app/serializers/new_topic_serializer.rb @@ -10,5 +10,4 @@ class NewTopicSerializer < ActiveModel::Serializer has_one :user, serializer: NewUserSerializer has_one :metacode, serializer: NewMetacodeSerializer - end diff --git a/app/serializers/new_user_serializer.rb b/app/serializers/new_user_serializer.rb index 45be36b0..62796f31 100644 --- a/app/serializers/new_user_serializer.rb +++ b/app/serializers/new_user_serializer.rb @@ -12,4 +12,4 @@ class NewUserSerializer < ActiveModel::Serializer def is_admin object.admin end -end +end diff --git a/app/serializers/token_serializer.rb b/app/serializers/token_serializer.rb index 7abcc3df..4d593c0e 100644 --- a/app/serializers/token_serializer.rb +++ b/app/serializers/token_serializer.rb @@ -4,5 +4,4 @@ class TokenSerializer < ActiveModel::Serializer :description, :created_at, :updated_at - end diff --git a/app/serializers/webhook_serializer.rb b/app/serializers/webhook_serializer.rb index ed013cae..8108c86c 100644 --- a/app/serializers/webhook_serializer.rb +++ b/app/serializers/webhook_serializer.rb @@ -1,3 +1,3 @@ class WebhookSerializer < ActiveModel::Serializer - attributes :text, :username, :icon_url #, :attachments + attributes :text, :username, :icon_url # , :attachments end diff --git a/app/services/map_export_service.rb b/app/services/map_export_service.rb index 94a0cf17..7c66c0e6 100644 --- a/app/services/map_export_service.rb +++ b/app/services/map_export_service.rb @@ -24,6 +24,7 @@ class MapExportService < Struct.new(:user, :map) def topic_headings [:id, :name, :metacode, :x, :y, :description, :link, :user, :permission] end + def synapse_headings [:topic1, :topic2, :category, :description, :user, :permission] end @@ -64,7 +65,7 @@ class MapExportService < Struct.new(:user, :map) def to_spreadsheet spreadsheet = [] - spreadsheet << ["Topics"] + spreadsheet << ['Topics'] spreadsheet << topic_headings.map(&:capitalize) exportable_topics.each do |topics| # convert exportable_topics into an array of arrays @@ -72,7 +73,7 @@ class MapExportService < Struct.new(:user, :map) end spreadsheet << [] - spreadsheet << ["Synapses"] + spreadsheet << ['Synapses'] spreadsheet << synapse_headings.map(&:capitalize) exportable_synapses.each do |synapse| # convert exportable_synapses into an array of arrays diff --git a/app/services/perm.rb b/app/services/perm.rb index c18c26b7..99897028 100644 --- a/app/services/perm.rb +++ b/app/services/perm.rb @@ -1,35 +1,34 @@ class Perm # e.g. Perm::ISSIONS - ISSIONS = [:commons, :public, :private] + ISSIONS = [:commons, :public, :private].freeze class << self - def short(permission) case permission when :commons - "co" + 'co' when :public - "pu" + 'pu' when :private - "pr" + 'pr' else - fail "Invalid permission" + raise 'Invalid permission' end end def long(perm) case perm - when "co" + when 'co' :commons - when "pu" + when 'pu' :public - when "pr" + when 'pr' :private else - fail "Invalid short permission" + raise 'Invalid short permission' end end - + def valid?(permission) ISSIONS.include? permission end diff --git a/app/services/webhook_service.rb b/app/services/webhook_service.rb index 7a4361b4..965f2c91 100644 --- a/app/services/webhook_service.rb +++ b/app/services/webhook_service.rb @@ -1,18 +1,16 @@ class WebhookService - def self.publish!(webhook:, event:) return false unless webhook.event_types.include? event.kind HTTParty.post webhook.uri, body: payload_for(webhook, event), headers: webhook.headers end - private + class << self + def payload_for(webhook, event) + WebhookSerializer.new(webhook_object_for(webhook, event), root: false).to_json + end - def self.payload_for(webhook, event) - WebhookSerializer.new(webhook_object_for(webhook, event), root: false).to_json + def webhook_object_for(webhook, event) + "Webhooks::#{webhook.kind.classify}::#{event.kind.classify}".constantize.new(event) + end end - - def self.webhook_object_for(webhook, event) - "Webhooks::#{webhook.kind.classify}::#{event.kind.classify}".constantize.new(event) - end - end diff --git a/config.ru b/config.ru index e83757ab..8a0f42cc 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require ::File.expand_path('../config/environment', __FILE__) run Metamaps::Application diff --git a/config/application.rb b/config/application.rb index 570b6959..afebfd6d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -7,7 +7,7 @@ Bundler.require(*Rails.groups) module Metamaps class Application < Rails::Application - config.active_job.queue_adapter = :delayed_job + config.active_job.queue_adapter = :delayed_job # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. @@ -31,12 +31,12 @@ module Metamaps # config.i18n.default_locale = :de # Configure the default encoding used in templates for Ruby 1.9. - config.encoding = "utf-8" + config.encoding = 'utf-8' config.to_prepare do - Doorkeeper::ApplicationsController.layout "doorkeeper" - Doorkeeper::AuthorizationsController.layout "doorkeeper" - Doorkeeper::AuthorizedApplicationsController.layout "doorkeeper" + Doorkeeper::ApplicationsController.layout 'doorkeeper' + Doorkeeper::AuthorizationsController.layout 'doorkeeper' + Doorkeeper::AuthorizedApplicationsController.layout 'doorkeeper' Doorkeeper::ApplicationController.helper ApplicationHelper end @@ -50,7 +50,7 @@ module Metamaps # Enable the asset pipeline config.assets.initialize_on_precompile = false - + # Version of your assets, change this if you want to expire all your assets config.assets.version = '2.0' @@ -60,6 +60,6 @@ module Metamaps config.active_record.raise_in_transactional_callbacks = true # pundit errors return 403 FORBIDDEN - config.action_dispatch.rescue_responses["Pundit::NotAuthorizedError"] = :forbidden + config.action_dispatch.rescue_responses['Pundit::NotAuthorizedError'] = :forbidden end end diff --git a/config/boot.rb b/config/boot.rb index 0f0d7c60..4add3ee3 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -11,4 +11,4 @@ end # Set up gems listed in the Gemfile. 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']) diff --git a/config/environments/development.rb b/config/environments/development.rb index bad33ab9..407a30f3 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -12,7 +12,7 @@ Metamaps::Application.configure do # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false - + # S3 file storage config.paperclip_defaults = { storage: :s3, @@ -23,7 +23,7 @@ Metamaps::Application.configure do }, s3_protocol: 'https' } - + config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: ENV['SMTP_SERVER'], @@ -33,8 +33,9 @@ Metamaps::Application.configure do domain: ENV['SMTP_DOMAIN'], authentication: 'plain', enable_starttls_auto: true, - openssl_verify_mode: 'none' } - config.action_mailer.default_url_options = { :host => 'localhost:3000' } + openssl_verify_mode: 'none' + } + config.action_mailer.default_url_options = { host: 'localhost:3000' } # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = true diff --git a/config/environments/production.rb b/config/environments/production.rb index 9654962a..5ad26ad3 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -19,11 +19,10 @@ Metamaps::Application.configure do # Compress JavaScripts and CSS config.assets.compress = true - # S3 file storage config.paperclip_defaults = { - :storage => :s3, + storage: :s3, s3_credentials: { bucket: ENV['S3_BUCKET_NAME'], access_key_id: ENV['AWS_ACCESS_KEY_ID'], @@ -31,18 +30,19 @@ Metamaps::Application.configure do }, s3_protocol: 'https' } - + config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: ENV['SMTP_SERVER'], port: ENV['SMTP_PORT'], user_name: ENV['SMTP_USERNAME'], password: ENV['SMTP_PASSWORD'], - #domain: ENV['SMTP_DOMAIN'] + # domain: ENV['SMTP_DOMAIN'] authentication: 'plain', enable_starttls_auto: true, - openssl_verify_mode: 'none' } - config.action_mailer.default_url_options = { :host => ENV['MAILER_DEFAULT_URL'] } + openssl_verify_mode: 'none' + } + config.action_mailer.default_url_options = { host: ENV['MAILER_DEFAULT_URL'] } # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = true @@ -78,7 +78,7 @@ Metamaps::Application.configure do # config.action_controller.asset_host = "http://assets.example.com" # 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 # config.action_mailer.raise_delivery_errors = false diff --git a/config/environments/test.rb b/config/environments/test.rb index be83469c..4980b34c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -11,7 +11,7 @@ Metamaps::Application.configure do # Configure static asset server for tests with Cache-Control for performance 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 config.consider_all_requests_local = true @@ -21,7 +21,7 @@ Metamaps::Application.configure do config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment - config.action_controller.allow_forgery_protection = false + config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the @@ -31,7 +31,7 @@ Metamaps::Application.configure do # Print deprecation notices to the stderr config.active_support.deprecation = :stderr - #assets config + # assets config config.assets.compile = true config.assets.compress = false config.assets.debug = false diff --git a/config/initializers/access_codes.rb b/config/initializers/access_codes.rb index adb4ae8b..66ace9a1 100644 --- a/config/initializers/access_codes.rb +++ b/config/initializers/access_codes.rb @@ -1,4 +1,4 @@ - $codes = [] - if ActiveRecord::Base.connection.table_exists? 'users' - $codes = ActiveRecord::Base.connection.execute("SELECT code FROM users").map {|user| user["code"] } - end \ No newline at end of file +$codes = [] +if ActiveRecord::Base.connection.table_exists? 'users' + $codes = ActiveRecord::Base.connection.execute('SELECT code FROM users').map { |user| user['code'] } +end diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb index 092bbeaf..a9a8dcff 100644 --- a/config/initializers/cors.rb +++ b/config/initializers/cors.rb @@ -2,7 +2,7 @@ Rails.application.config.middleware.insert_before 0, Rack::Cors do allow do origins '*' resource '/api/*', - headers: :any, - methods: [:get, :post, :put, :delete, :options, :head] + headers: :any, + methods: [:get, :post, :put, :delete, :options, :head] end end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 6590fddf..8a87b3b9 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -15,10 +15,9 @@ Devise.setup do |config| # Configure the class responsible to send e-mails. # config.mailer = "Devise::Mailer" - - + config.secret_key = ENV['DEVISE_SECRET_KEY'] - + # ==> ORM configuration # Load and configure the ORM. Supports :active_record (default) and # :mongoid (bson_ext recommended) by default. Other ORMs may be @@ -45,12 +44,12 @@ Devise.setup do |config| # Configure which authentication keys should be case-insensitive. # These keys will be downcased upon creating or modifying a user and when used # 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. # 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. - config.strip_whitespace_keys = [ :email ] + config.strip_whitespace_keys = [:email] # 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 diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 8b5e5425..54890c6e 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -4,4 +4,4 @@ # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone -Mime::Type.register "application/xls", :xls +Mime::Type.register 'application/xls', :xls diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb index 07d6e2f3..4a65d495 100644 --- a/config/initializers/paperclip.rb +++ b/config/initializers/paperclip.rb @@ -1,2 +1,2 @@ Paperclip::Attachment.default_options[:url] = ':s3_domain_url' -Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename' \ No newline at end of file +Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename' diff --git a/config/initializers/uservoice.rb b/config/initializers/uservoice.rb index 293b908b..df04eeaa 100644 --- a/config/initializers/uservoice.rb +++ b/config/initializers/uservoice.rb @@ -1,7 +1,7 @@ require 'uservoice-ruby' def current_sso_token - @current_sso_token ||= UserVoice.generate_sso_token('metamapscc', ENV['SSO_KEY'], { - :email => current_user.email - }, 300) # Default expiry time is 5 minutes = 300 seconds -end \ No newline at end of file + @current_sso_token ||= UserVoice.generate_sso_token('metamapscc', ENV['SSO_KEY'], { + email: current_user.email + }, 300) # Default expiry time is 5 minutes = 300 seconds +end diff --git a/config/initializers/version.rb b/config/initializers/version.rb index a04901a1..1d4b9aec 100644 --- a/config/initializers/version.rb +++ b/config/initializers/version.rb @@ -1 +1 @@ -METAMAPS_VERSION = '2.8.5' +METAMAPS_VERSION = '2.8.5'.freeze diff --git a/config/routes.rb b/config/routes.rb index a60749b7..81ef8dfe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,56 +1,55 @@ Metamaps::Application.routes.draw do - use_doorkeeper root to: 'main#home', via: :get - + get 'request', to: 'main#requestinvite', as: :request - + get 'search/topics', to: 'main#searchtopics', as: :searchtopics get 'search/maps', to: 'main#searchmaps', as: :searchmaps get 'search/mappers', to: 'main#searchmappers', as: :searchmappers 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 :synapses, only: [:create, :show, :update, :destroy] resources :topics, 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 - end + end end - + resources :messages, only: [:show, :create, :update, :destroy] 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' resources :synapses, except: [:index, :new, :edit] resources :topics, except: [:index, :new, :edit] do - get :autocomplete_topic, :on => :collection + get :autocomplete_topic, on: :collection end get 'topics/:id/network', to: 'topics#network', as: :network get 'topics/:id/relative_numbers', to: 'topics#relative_numbers', as: :relative_numbers get 'topics/:id/relatives', to: 'topics#relatives', as: :relatives - + resources :maps, except: [:index, :new, :edit] get 'maps/:id/export', to: 'maps#export' post 'maps/:id/events/:event', to: 'maps#events' get 'maps/:id/contains', to: 'maps#contains', as: :contains 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/featured', to: 'maps#featuredmaps' get 'explore/mine', to: 'maps#mymaps' get 'explore/shared', to: 'maps#sharedmaps' get 'explore/mapper/:id', to: 'maps#usermaps' - - devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, :skip => :sessions - devise_scope :user do + devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, skip: :sessions + + devise_scope :user do get 'login' => 'devise/sessions#new', :as => :new_user_session post 'login' => 'devise/sessions#create', :as => :user_session get 'logout' => 'devise/sessions#destroy', :as => :destroy_user_session diff --git a/db/migrate/20141121204712_add_generation_to_users.rb b/db/migrate/20141121204712_add_generation_to_users.rb index b31e2832..777bbd66 100644 --- a/db/migrate/20141121204712_add_generation_to_users.rb +++ b/db/migrate/20141121204712_add_generation_to_users.rb @@ -1,5 +1,5 @@ class AddGenerationToUsers < ActiveRecord::Migration def change - add_column :users, :generation, :integer + add_column :users, :generation, :integer end end diff --git a/db/migrate/20151001024122_mapping_polymorphism.rb b/db/migrate/20151001024122_mapping_polymorphism.rb index e6bbd5fc..7e3ae76b 100644 --- a/db/migrate/20151001024122_mapping_polymorphism.rb +++ b/db/migrate/20151001024122_mapping_polymorphism.rb @@ -5,21 +5,21 @@ class MappingPolymorphism < ActiveRecord::Migration add_index :mappings, [:mappable_id, :mappable_type] 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!" next 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!" next end - unless mapping.synapse_id.nil? - mapping.mappable = Synapse.find_by(id: mapping.synapse_id) - else + if mapping.synapse_id.nil? mapping.mappable = Topic.find_by(id: mapping.topic_id) + else + mapping.mappable = Synapse.find_by(id: mapping.synapse_id) end - + if mapping.mappable.nil? mapping.delete else diff --git a/db/migrate/20151205205831_messages.rb b/db/migrate/20151205205831_messages.rb index e892ebcc..f12e14db 100644 --- a/db/migrate/20151205205831_messages.rb +++ b/db/migrate/20151205205831_messages.rb @@ -1,6 +1,6 @@ class Messages < ActiveRecord::Migration def change - create_table :messages do |t| + create_table :messages do |t| t.text :message t.references :user t.integer :resource_id diff --git a/db/migrate/20160120061513_metacode_asset_path_update.rb b/db/migrate/20160120061513_metacode_asset_path_update.rb index a254597c..af5e7970 100644 --- a/db/migrate/20160120061513_metacode_asset_path_update.rb +++ b/db/migrate/20160120061513_metacode_asset_path_update.rb @@ -4,12 +4,11 @@ end class MetacodeAssetPathUpdate < ActiveRecord::Migration def change Metacode.first(50).each do |metacode| - if 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('blueprint_96px', 'blueprint/96px') - metacode.icon = metacode.icon.sub('generics_96px', 'generics/96px') - metacode.save - end + 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('blueprint_96px', 'blueprint/96px') + metacode.icon = metacode.icon.sub('generics_96px', 'generics/96px') + metacode.save end end end diff --git a/db/migrate/20160313003721_create_delayed_jobs.rb b/db/migrate/20160313003721_create_delayed_jobs.rb index 27fdcf6c..3d055fa7 100644 --- a/db/migrate/20160313003721_create_delayed_jobs.rb +++ b/db/migrate/20160313003721_create_delayed_jobs.rb @@ -13,7 +13,7 @@ class CreateDelayedJobs < ActiveRecord::Migration table.timestamps null: true end - add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority" + add_index :delayed_jobs, [:priority, :run_at], name: 'delayed_jobs_priority' end def self.down diff --git a/db/migrate/20160318141618_create_doorkeeper_tables.rb b/db/migrate/20160318141618_create_doorkeeper_tables.rb index d89b005c..a5ab182e 100644 --- a/db/migrate/20160318141618_create_doorkeeper_tables.rb +++ b/db/migrate/20160318141618_create_doorkeeper_tables.rb @@ -34,12 +34,12 @@ class CreateDoorkeeperTables < ActiveRecord::Migration # https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator # # t.text :token, null: false - t.string :token, null: false + t.string :token, null: false t.string :refresh_token t.integer :expires_in t.datetime :revoked_at - t.datetime :created_at, null: false + t.datetime :created_at, null: false t.string :scopes end diff --git a/db/schema.rb b/db/schema.rb index d3dc9634..49081d10 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,270 +11,269 @@ # # 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 - enable_extension "plpgsql" + enable_extension 'plpgsql' - create_table "delayed_jobs", force: :cascade do |t| - t.integer "priority", default: 0, null: false - t.integer "attempts", default: 0, null: false - t.text "handler", null: false - t.text "last_error" - t.datetime "run_at" - t.datetime "locked_at" - t.datetime "failed_at" - t.string "locked_by" - t.string "queue" - t.datetime "created_at" - t.datetime "updated_at" + create_table 'delayed_jobs', force: :cascade do |t| + t.integer 'priority', default: 0, null: false + t.integer 'attempts', default: 0, null: false + t.text 'handler', null: false + t.text 'last_error' + t.datetime 'run_at' + t.datetime 'locked_at' + t.datetime 'failed_at' + t.string 'locked_by' + t.string 'queue' + t.datetime 'created_at' + t.datetime 'updated_at' 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| - t.string "kind", limit: 255 - t.integer "eventable_id" - t.string "eventable_type" - t.integer "user_id" - t.integer "map_id" - t.integer "sequence_id" - t.datetime "created_at" - t.datetime "updated_at" + create_table 'events', force: :cascade do |t| + t.string 'kind', limit: 255 + t.integer 'eventable_id' + t.string 'eventable_type' + t.integer 'user_id' + t.integer 'map_id' + t.integer 'sequence_id' + t.datetime 'created_at' + t.datetime 'updated_at' end - add_index "events", ["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", ["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", ["user_id"], name: "index_events_on_user_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', %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', ['sequence_id'], name: 'index_events_on_sequence_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| - t.integer "metacode_id" - t.integer "metacode_set_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'in_metacode_sets', force: :cascade do |t| + t.integer 'metacode_id' + t.integer 'metacode_set_id' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - 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_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 - create_table "mappings", force: :cascade do |t| - t.text "category" - t.integer "xloc" - t.integer "yloc" - t.integer "topic_id" - t.integer "synapse_id" - t.integer "map_id" - t.integer "user_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "mappable_id" - t.string "mappable_type" + create_table 'mappings', force: :cascade do |t| + t.text 'category' + t.integer 'xloc' + t.integer 'yloc' + t.integer 'topic_id' + t.integer 'synapse_id' + t.integer 'map_id' + t.integer 'user_id' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.integer 'mappable_id' + t.string 'mappable_type' end - add_index "mappings", ["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", ["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", ["user_id"], name: "index_mappings_on_user_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', %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', %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 - create_table "maps", force: :cascade do |t| - t.text "name" - t.boolean "arranged" - t.text "desc" - t.text "permission" - t.integer "user_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "featured" - t.string "screenshot_file_name" - t.string "screenshot_content_type" - t.integer "screenshot_file_size" - t.datetime "screenshot_updated_at" + create_table 'maps', force: :cascade do |t| + t.text 'name' + t.boolean 'arranged' + t.text 'desc' + t.text 'permission' + t.integer 'user_id' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.boolean 'featured' + t.string 'screenshot_file_name' + t.string 'screenshot_content_type' + t.integer 'screenshot_file_size' + t.datetime 'screenshot_updated_at' 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| - t.text "message" - t.integer "user_id" - t.integer "resource_id" - t.string "resource_type" - t.datetime "created_at" - t.datetime "updated_at" + create_table 'messages', force: :cascade do |t| + t.text 'message' + t.integer 'user_id' + t.integer 'resource_id' + t.string 'resource_type' + t.datetime 'created_at' + t.datetime 'updated_at' end - 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", ["user_id"], name: "index_messages_on_user_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', ['user_id'], name: 'index_messages_on_user_id', using: :btree - create_table "metacode_sets", force: :cascade do |t| - t.string "name" - t.text "desc" - t.integer "user_id" - t.boolean "mapperContributed" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'metacode_sets', force: :cascade do |t| + t.string 'name' + t.text 'desc' + t.integer 'user_id' + t.boolean 'mapperContributed' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false 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| - t.text "name" - t.string "manual_icon" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "color" - t.string "aws_icon_file_name" - t.string "aws_icon_content_type" - t.integer "aws_icon_file_size" - t.datetime "aws_icon_updated_at" + create_table 'metacodes', force: :cascade do |t| + t.text 'name' + t.string 'manual_icon' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.string 'color' + t.string 'aws_icon_file_name' + t.string 'aws_icon_content_type' + t.integer 'aws_icon_file_size' + t.datetime 'aws_icon_updated_at' end - create_table "oauth_access_grants", force: :cascade do |t| - t.integer "resource_owner_id", null: false - t.integer "application_id", null: false - t.string "token", null: false - t.integer "expires_in", null: false - t.text "redirect_uri", null: false - t.datetime "created_at", null: false - t.datetime "revoked_at" - t.string "scopes" + create_table 'oauth_access_grants', force: :cascade do |t| + t.integer 'resource_owner_id', null: false + t.integer 'application_id', null: false + t.string 'token', null: false + t.integer 'expires_in', null: false + t.text 'redirect_uri', null: false + t.datetime 'created_at', null: false + t.datetime 'revoked_at' + t.string 'scopes' 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| - t.integer "resource_owner_id" - t.integer "application_id" - t.string "token", null: false - t.string "refresh_token" - t.integer "expires_in" - t.datetime "revoked_at" - t.datetime "created_at", null: false - t.string "scopes" + create_table 'oauth_access_tokens', force: :cascade do |t| + t.integer 'resource_owner_id' + t.integer 'application_id' + t.string 'token', null: false + t.string 'refresh_token' + t.integer 'expires_in' + t.datetime 'revoked_at' + t.datetime 'created_at', null: false + t.string 'scopes' 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", ["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', ['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', ['token'], name: 'index_oauth_access_tokens_on_token', unique: true, using: :btree - create_table "oauth_applications", force: :cascade do |t| - t.string "name", null: false - t.string "uid", null: false - t.string "secret", null: false - t.text "redirect_uri", null: false - t.string "scopes", default: "", null: false - t.datetime "created_at" - t.datetime "updated_at" + create_table 'oauth_applications', force: :cascade do |t| + t.string 'name', null: false + t.string 'uid', null: false + t.string 'secret', null: false + t.text 'redirect_uri', null: false + t.string 'scopes', default: '', null: false + t.datetime 'created_at' + t.datetime 'updated_at' 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| - t.text "desc" - t.text "category" - t.text "weight" - t.text "permission" - t.integer "node1_id" - t.integer "node2_id" - t.integer "user_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "defer_to_map_id" + create_table 'synapses', force: :cascade do |t| + t.text 'desc' + t.text 'category' + t.text 'weight' + t.text 'permission' + t.integer 'node1_id' + t.integer 'node2_id' + t.integer 'user_id' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.integer 'defer_to_map_id' end - add_index "synapses", ["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", ["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", ["user_id"], name: "index_synapses_on_user_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', %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', ['user_id'], name: 'index_synapses_on_user_id', using: :btree - create_table "tokens", force: :cascade do |t| - t.string "token" - t.string "description" - t.integer "user_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'tokens', force: :cascade do |t| + t.string 'token' + t.string 'description' + t.integer 'user_id' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false 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| - t.text "name" - t.text "desc" - t.text "link" - t.text "permission" - t.integer "user_id" - t.integer "metacode_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "image_file_name" - t.string "image_content_type" - t.integer "image_file_size" - t.datetime "image_updated_at" - t.string "audio_file_name" - t.string "audio_content_type" - t.integer "audio_file_size" - t.datetime "audio_updated_at" - t.integer "defer_to_map_id" + create_table 'topics', force: :cascade do |t| + t.text 'name' + t.text 'desc' + t.text 'link' + t.text 'permission' + t.integer 'user_id' + t.integer 'metacode_id' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.string 'image_file_name' + t.string 'image_content_type' + t.integer 'image_file_size' + t.datetime 'image_updated_at' + t.string 'audio_file_name' + t.string 'audio_content_type' + t.integer 'audio_file_size' + t.datetime 'audio_updated_at' + t.integer 'defer_to_map_id' end - 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', ['metacode_id'], name: 'index_topics_on_metacode_id', using: :btree + add_index 'topics', ['user_id'], name: 'index_topics_on_user_id', using: :btree - create_table "user_maps", force: :cascade do |t| - t.integer "user_id" - t.integer "map_id" - t.datetime "created_at" - t.datetime "updated_at" + create_table 'user_maps', force: :cascade do |t| + t.integer 'user_id' + t.integer 'map_id' + t.datetime 'created_at' + t.datetime 'updated_at' end - 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', ['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 - create_table "users", force: :cascade do |t| - t.string "name" - t.string "email" - t.text "settings" - t.string "code", limit: 8 - t.string "joinedwithcode", limit: 8 - t.string "crypted_password" - t.string "password_salt" - t.string "persistence_token" - t.string "perishable_token" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "encrypted_password", limit: 128, default: "" - t.string "remember_token" - t.datetime "remember_created_at" - t.string "reset_password_token" - t.datetime "last_sign_in_at" - t.string "last_sign_in_ip" - t.integer "sign_in_count", default: 0 - t.datetime "current_sign_in_at" - t.string "current_sign_in_ip" - t.datetime "reset_password_sent_at" - t.boolean "admin" - t.string "image_file_name" - t.string "image_content_type" - t.integer "image_file_size" - t.datetime "image_updated_at" - t.integer "generation" + create_table 'users', force: :cascade do |t| + t.string 'name' + t.string 'email' + t.text 'settings' + t.string 'code', limit: 8 + t.string 'joinedwithcode', limit: 8 + t.string 'crypted_password' + t.string 'password_salt' + t.string 'persistence_token' + t.string 'perishable_token' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.string 'encrypted_password', limit: 128, default: '' + t.string 'remember_token' + t.datetime 'remember_created_at' + t.string 'reset_password_token' + t.datetime 'last_sign_in_at' + t.string 'last_sign_in_ip' + t.integer 'sign_in_count', default: 0 + t.datetime 'current_sign_in_at' + t.string 'current_sign_in_ip' + t.datetime 'reset_password_sent_at' + t.boolean 'admin' + t.string 'image_file_name' + t.string 'image_content_type' + t.integer 'image_file_size' + t.datetime 'image_updated_at' + t.integer 'generation' 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| - t.integer "hookable_id" - t.string "hookable_type" - t.string "kind", null: false - t.string "uri", null: false - t.text "event_types", default: [], array: true + create_table 'webhooks', force: :cascade do |t| + t.integer 'hookable_id' + t.string 'hookable_type' + t.string 'kind', null: false + t.string 'uri', null: false + t.text 'event_types', default: [], array: true 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 diff --git a/db/seeds.rb b/db/seeds.rb index daece06f..9f586b9d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -2,305 +2,207 @@ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). ## USERS -User.new({ - name: 'user', - email: 'user@user.com', - password: 'toolsplusconsciousness', - code: 'qwertyui', - joinedwithcode: 'qwertyui', - admin: 'false' -}).save(validate: false) +User.new(name: 'user', + email: 'user@user.com', + password: 'toolsplusconsciousness', + code: 'qwertyui', + joinedwithcode: 'qwertyui', + admin: 'false').save(validate: false) -User.new({ - name: 'admin', - email: 'admin@admin.com', - password: 'toolsplusconsciousness', - code: 'iuytrewq', - joinedwithcode: 'iuytrewq', - admin: 'true' -}).save(validate: false) +User.new(name: 'admin', + email: 'admin@admin.com', + password: 'toolsplusconsciousness', + code: 'iuytrewq', + joinedwithcode: 'iuytrewq', + admin: 'true').save(validate: false) ## END USERS ## METACODES -Metacode.create({ - name: 'Action', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_action.png', - color: '#BD6C85' -}) +Metacode.create(name: 'Action', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_action.png', + color: '#BD6C85') -Metacode.create({ - name: 'Activity', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_activity.png', - color: '#6EBF65' -}) +Metacode.create(name: 'Activity', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_activity.png', + color: '#6EBF65') -Metacode.create({ - name: 'Catalyst', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_catalyst.png', - color: '#EF8964', -}) +Metacode.create(name: 'Catalyst', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_catalyst.png', + color: '#EF8964') -Metacode.create({ - name: 'Closed', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_closedissue.png', - color: '#ABB49F', -}) +Metacode.create(name: 'Closed', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_closedissue.png', + color: '#ABB49F') -Metacode.create({ - name: 'Process', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_process.png', - color: '#BDB25E', -}) +Metacode.create(name: 'Process', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_process.png', + color: '#BDB25E') -Metacode.create({ - name: 'Future', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_futuredev.png', - color: '#25A17F', -}) +Metacode.create(name: 'Future', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_futuredev.png', + color: '#25A17F') -Metacode.create({ - name: 'Group', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_group.png', - color: '#7076BC', -}) +Metacode.create(name: 'Group', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_group.png', + color: '#7076BC') -Metacode.create({ - name: 'Implication', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_implication.png', - color: '#83DECA', -}) +Metacode.create(name: 'Implication', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_implication.png', + color: '#83DECA') -Metacode.create({ - name: 'Insight', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_insight.png', - color: '#B074AD', -}) +Metacode.create(name: 'Insight', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_insight.png', + color: '#B074AD') -Metacode.create({ - name: 'Intention', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_intention.png', - color: '#BAEAFF', -}) +Metacode.create(name: 'Intention', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_intention.png', + color: '#BAEAFF') -Metacode.create({ - name: 'Knowledge', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_knowledge.png', - color: '#60ACF7', -}) +Metacode.create(name: 'Knowledge', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_knowledge.png', + color: '#60ACF7') -Metacode.create({ - name: 'Location', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_location.png', - color: '#ABD9A7', -}) +Metacode.create(name: 'Location', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_location.png', + color: '#ABD9A7') -Metacode.create({ - name: 'Need', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_need.png', - color: '#D2A7D4', -}) +Metacode.create(name: 'Need', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_need.png', + color: '#D2A7D4') -Metacode.create({ - name: 'Open', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_openissue.png', - color: '#9BBF71', -}) +Metacode.create(name: 'Open', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_openissue.png', + color: '#9BBF71') -Metacode.create({ - name: 'Opportunity', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_opportunity.png', - color: '#889F64', -}) +Metacode.create(name: 'Opportunity', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_opportunity.png', + color: '#889F64') -Metacode.create({ - name: 'Person', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_person.png', - color: '#DE925F', -}) +Metacode.create(name: 'Person', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_person.png', + color: '#DE925F') -Metacode.create({ - name: 'Platform', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_platform.png', - color: '#21C8FE', -}) +Metacode.create(name: 'Platform', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_platform.png', + color: '#21C8FE') -Metacode.create({ - name: 'Problem', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_problem.png', - color: '#99CFC4', -}) +Metacode.create(name: 'Problem', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_problem.png', + color: '#99CFC4') -Metacode.create({ - name: 'Resource', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_resource.png', - color: '#C98C63', -}) +Metacode.create(name: 'Resource', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_resource.png', + color: '#C98C63') -Metacode.create({ - name: 'Role', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_role.png', - color: '#A8595D', -}) +Metacode.create(name: 'Role', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_role.png', + color: '#A8595D') -Metacode.create({ - name: 'Task', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_task.png', - color: '#3397C4', -}) +Metacode.create(name: 'Task', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_task.png', + color: '#3397C4') -Metacode.create({ - name: 'Trajectory', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_trajectory.png', - color: '#D3AA4C', -}) +Metacode.create(name: 'Trajectory', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_trajectory.png', + color: '#D3AA4C') -Metacode.create({ - name: 'Argument', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_argument.png', - color: '#7FAEFD', -}) +Metacode.create(name: 'Argument', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_argument.png', + color: '#7FAEFD') -Metacode.create({ - name: 'Con', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_con.png', - color: '#CF7C74', -}) +Metacode.create(name: 'Con', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_con.png', + color: '#CF7C74') -Metacode.create({ - name: 'Subject', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_subject.png', - color: '#8293D8', -}) +Metacode.create(name: 'Subject', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_subject.png', + color: '#8293D8') -Metacode.create({ - name: 'Decision', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_decision.png', - color: '#CCA866', -}) +Metacode.create(name: 'Decision', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_decision.png', + color: '#CCA866') -Metacode.create({ - name: 'Event', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_event.png', - color: '#F5854B', -}) +Metacode.create(name: 'Event', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_event.png', + color: '#F5854B') -Metacode.create({ - name: 'Example', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_example.png', - color: '#618C61', -}) +Metacode.create(name: 'Example', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_example.png', + color: '#618C61') -Metacode.create({ - name: 'Experience', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_experience.png', - color: '#BE995F', -}) +Metacode.create(name: 'Experience', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_experience.png', + color: '#BE995F') -Metacode.create({ - name: 'Feedback', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_feedback.png', - color: '#54A19D', -}) +Metacode.create(name: 'Feedback', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_feedback.png', + color: '#54A19D') -Metacode.create({ - name: 'Aim', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_aim.png', - color: '#B0B0B0', -}) +Metacode.create(name: 'Aim', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_aim.png', + color: '#B0B0B0') -Metacode.create({ - name: 'Good', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_goodpractice.png', - color: '#BD9E86', -}) +Metacode.create(name: 'Good', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_goodpractice.png', + color: '#BD9E86') -Metacode.create({ - name: 'Idea', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_idea.png', - color: '#C4BC5E', -}) +Metacode.create(name: 'Idea', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_idea.png', + color: '#C4BC5E') -Metacode.create({ - name: 'List', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_list.png', - color: '#B7A499', -}) +Metacode.create(name: 'List', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_list.png', + color: '#B7A499') -Metacode.create({ - name: 'Media', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_media.png', - color: '#6D94CC', -}) +Metacode.create(name: 'Media', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_media.png', + color: '#6D94CC') -Metacode.create({ - name: 'Metamap', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_metamap.png', - color: '#AEA9FD', -}) +Metacode.create(name: 'Metamap', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_metamap.png', + color: '#AEA9FD') -Metacode.create({ - name: 'Model', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_model.png', - color: '#B385BA', -}) +Metacode.create(name: 'Model', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_model.png', + color: '#B385BA') -Metacode.create({ - name: 'Note', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_note.png', - color: '#A389A1', -}) +Metacode.create(name: 'Note', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_note.png', + color: '#A389A1') -Metacode.create({ - name: 'Perspective', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_perspective.png', - color: '#2EB6CC', -}) +Metacode.create(name: 'Perspective', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_perspective.png', + color: '#2EB6CC') -Metacode.create({ - name: 'Pro', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_pro.png', - color: '#89B879', -}) +Metacode.create(name: 'Pro', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_pro.png', + color: '#89B879') -Metacode.create({ - name: 'Project', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_project.png', - color: '#85A050', -}) +Metacode.create(name: 'Project', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_project.png', + color: '#85A050') -Metacode.create({ - name: 'Question', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_question.png', - color: '#5CB3B3', -}) +Metacode.create(name: 'Question', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_question.png', + color: '#5CB3B3') -Metacode.create({ - name: 'Reference', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_reference.png', - color: '#A7A7A7', -}) +Metacode.create(name: 'Reference', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_reference.png', + color: '#A7A7A7') -Metacode.create({ - name: 'Research', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_research.png', - color: '#CD8E89', -}) +Metacode.create(name: 'Research', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_research.png', + color: '#CD8E89') -Metacode.create({ - name: 'Status', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_status.png', - color: '#EFA7C0', -}) +Metacode.create(name: 'Status', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_status.png', + color: '#EFA7C0') -Metacode.create({ - name: 'Tool', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_tool.png', - color: '#828282', -}) +Metacode.create(name: 'Tool', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_tool.png', + color: '#828282') -Metacode.create({ - name: 'Wildcard', - manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png', - color: '#73C7DE', -}) +Metacode.create(name: 'Wildcard', + manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png', + color: '#73C7DE') ## END METACODES diff --git a/lib/tasks/heroku.rake b/lib/tasks/heroku.rake index 3e35fcbf..a523a778 100644 --- a/lib/tasks/heroku.rake +++ b/lib/tasks/heroku.rake @@ -1,15 +1,15 @@ require 'dotenv/tasks' namespace :heroku do - desc "Generate the Heroku gems manifest from gem dependencies" - task :gems => :dotenv do - RAILS_ENV='production' + desc 'Generate the Heroku gems manifest from gem dependencies' + task gems: :dotenv do + RAILS_ENV = 'production'.freeze Rake::Task[:environment].invoke - list = Rails.configuration.gems.collect do |g| - command, *options = g.send(:install_command) - options.join(" ") + "\n" + list = Rails.configuration.gems.collect do |g| + _command, *options = g.send(:install_command) + options.join(' ') + "\n" end - + File.open(File.join(RAILS_ROOT, '.gems'), 'w') do |f| f.write(list) end diff --git a/lib/tasks/perms.rake b/lib/tasks/perms.rake index 70cd60f0..39cb9b27 100644 --- a/lib/tasks/perms.rake +++ b/lib/tasks/perms.rake @@ -1,8 +1,8 @@ require 'dotenv/tasks' namespace :perms do - desc "Update the Unix permissions on the public directory" - task :fix => :environment do + desc 'Update the Unix permissions on the public directory' + task fix: :environment do # 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 diff --git a/script/rails b/script/rails index 81eab02f..a861c543 100644 --- a/script/rails +++ b/script/rails @@ -1,6 +1,6 @@ #!/usr/bin/env ruby.exe # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. -APP_PATH = File.expand_path('../../config/application', __FILE__) -require File.expand_path('../../config/boot', __FILE__) +APP_PATH = File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/boot', __FILE__) require 'rails/commands' diff --git a/spec/controllers/mappings_controller_spec.rb b/spec/controllers/mappings_controller_spec.rb index ffc9bac9..ecf726c2 100644 --- a/spec/controllers/mappings_controller_spec.rb +++ b/spec/controllers/mappings_controller_spec.rb @@ -10,7 +10,7 @@ RSpec.describe MappingsController, type: :controller do describe 'GET #show' 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) end end @@ -19,12 +19,12 @@ RSpec.describe MappingsController, type: :controller do context 'with valid params' do it 'creates a new Mapping' do expect do - post :create, { mapping: valid_attributes } + post :create, mapping: valid_attributes end.to change(Mapping, :count).by(1) end 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_persisted end @@ -32,7 +32,7 @@ RSpec.describe MappingsController, type: :controller do context 'with invalid params' 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) end end @@ -44,13 +44,13 @@ RSpec.describe MappingsController, type: :controller do it 'updates the requested mapping' do put :update, - { id: mapping.to_param, mapping: new_attributes } + id: mapping.to_param, mapping: new_attributes mapping.reload end it 'assigns the requested mapping as @mapping' do put :update, - { id: mapping.to_param, mapping: valid_attributes } + id: mapping.to_param, mapping: valid_attributes expect(assigns(:mapping)).to eq(mapping) end end @@ -58,7 +58,7 @@ RSpec.describe MappingsController, type: :controller do context 'with invalid params' do it 'assigns the mapping as @mapping' do put :update, - { id: mapping.to_param, mapping: invalid_attributes } + id: mapping.to_param, mapping: invalid_attributes expect(assigns(:mapping)).to eq(mapping) end end @@ -67,7 +67,7 @@ RSpec.describe MappingsController, type: :controller do describe 'DELETE #destroy' do it 'destroys the requested mapping' do expect do - delete :destroy, { id: mapping.to_param } + delete :destroy, id: mapping.to_param end.to change(Mapping, :count).by(-1) end end diff --git a/spec/controllers/maps_controller_spec.rb b/spec/controllers/maps_controller_spec.rb index 35c3ddcc..60b52ec1 100644 --- a/spec/controllers/maps_controller_spec.rb +++ b/spec/controllers/maps_controller_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe MapsController, type: :controller do let(:map) { create(:map) } let(:valid_attributes) { map.attributes.except(:id) } - let(:invalid_attributes) { { permission: :commons } } + let(:invalid_attributes) { { permission: :commons } } before :each do sign_in end @@ -17,14 +17,14 @@ RSpec.describe MapsController, type: :controller do describe 'GET #contains' 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) end end describe 'GET #show' 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) end end @@ -55,18 +55,18 @@ RSpec.describe MapsController, type: :controller do describe 'PUT #update' 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 put :update, - { id: map.to_param, map: new_attributes, format: :json } - expect(assigns(:map).name).to eq "Uncool map" + id: map.to_param, map: new_attributes, format: :json + expect(assigns(:map).name).to eq 'Uncool map' expect(assigns(:map).permission).to eq 'private' end it 'assigns the requested map as @map' do 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) end end @@ -74,7 +74,7 @@ RSpec.describe MapsController, type: :controller do context 'with invalid params' do it 'assigns the map as @map' do 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) end end @@ -87,7 +87,7 @@ RSpec.describe MapsController, type: :controller do it 'prevents deletion by non-owners' do unowned_map.reload 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) expect(response.body).to eq '' expect(response.status).to eq 403 @@ -96,7 +96,7 @@ RSpec.describe MapsController, type: :controller do it 'deletes owned map' do owned_map.reload # ensure it's in the database 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) expect(response.body).to eq '' expect(response.status).to eq 204 diff --git a/spec/controllers/metacodes_controller_spec.rb b/spec/controllers/metacodes_controller_spec.rb index 48688117..06434d49 100644 --- a/spec/controllers/metacodes_controller_spec.rb +++ b/spec/controllers/metacodes_controller_spec.rb @@ -17,14 +17,14 @@ RSpec.describe MetacodesController, type: :controller do describe 'GET #new' 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) end end describe 'GET #edit' 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) end end @@ -34,19 +34,19 @@ RSpec.describe MetacodesController, type: :controller do it 'creates a new Metacode' do metacode.reload # ensure it's present to start expect do - post :create, { metacode: valid_attributes } + post :create, metacode: valid_attributes end.to change(Metacode, :count).by(1) end 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(assigns(:metacode)).to be_a(Metacode) expect(assigns(:metacode)).to be_persisted end it 'redirects to the metacode index' do - post :create, { metacode: valid_attributes } + post :create, metacode: valid_attributes expect(response).to redirect_to(metacodes_url) end end @@ -63,7 +63,7 @@ RSpec.describe MetacodesController, type: :controller do it 'updates the requested metacode' do put :update, - { id: metacode.to_param, metacode: new_attributes } + id: metacode.to_param, metacode: new_attributes metacode.reload expect(metacode.icon).to eq 'https://newimages.ca/cool-image.jpg' expect(metacode.color).to eq '#ffffff' @@ -75,13 +75,13 @@ RSpec.describe MetacodesController, type: :controller do context 'not admin' do it 'denies access to create' do sign_in create(:user, admin: false) - post :create, { metacode: valid_attributes } + post :create, metacode: valid_attributes expect(response).to redirect_to root_url end it 'denies access to update' do 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 end end diff --git a/spec/controllers/synapses_controller_spec.rb b/spec/controllers/synapses_controller_spec.rb index 478ee6ed..55b2addb 100644 --- a/spec/controllers/synapses_controller_spec.rb +++ b/spec/controllers/synapses_controller_spec.rb @@ -3,14 +3,14 @@ require 'rails_helper' RSpec.describe SynapsesController, type: :controller do let(:synapse) { create(:synapse) } let(:valid_attributes) { synapse.attributes.except('id') } - let(:invalid_attributes) { { permission: :invalid_lol } } + let(:invalid_attributes) { { permission: :invalid_lol } } before :each do sign_in end describe 'GET #show' 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) end end @@ -20,25 +20,25 @@ RSpec.describe SynapsesController, type: :controller do it 'creates a new Synapse' do synapse.reload # ensure it's present expect do - post :create, { synapse: valid_attributes, format: :json } + post :create, synapse: valid_attributes, format: :json end.to change(Synapse, :count).by(1) end 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_persisted end 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 end end context 'with invalid params' 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 end end @@ -54,16 +54,16 @@ RSpec.describe SynapsesController, type: :controller do it 'updates the requested synapse' do put :update, - { id: synapse.to_param, synapse: new_attributes, format: :json } + id: synapse.to_param, synapse: new_attributes, format: :json synapse.reload expect(synapse.desc).to eq 'My new description' expect(synapse.category).to eq 'both' expect(synapse.permission).to eq 'public' end - it 'returns 204 NO CONTENT' do + it 'returns 204 NO CONTENT' do 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 end end @@ -71,7 +71,7 @@ RSpec.describe SynapsesController, type: :controller do context 'with invalid params' do it 'assigns the synapse as @synapse' do 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) end end @@ -83,12 +83,12 @@ RSpec.describe SynapsesController, type: :controller do it 'destroys the requested synapse' do synapse.reload # ensure it's present 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 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 end end diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index 2fc99b22..b6081701 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -10,7 +10,7 @@ RSpec.describe TopicsController, type: :controller do describe 'GET #show' 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) end end @@ -20,25 +20,25 @@ RSpec.describe TopicsController, type: :controller do it 'creates a new Topic' do topic.reload # ensure it's created expect do - post :create, { topic: valid_attributes, format: :json } + post :create, topic: valid_attributes, format: :json end.to change(Topic, :count).by(1) end 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_persisted end - it 'returns 201 CREATED' do - post :create, { topic: valid_attributes, format: :json } + it 'returns 201 CREATED' do + post :create, topic: valid_attributes, format: :json expect(response.status).to eq 201 end end context 'with invalid params' 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) end end @@ -55,7 +55,7 @@ RSpec.describe TopicsController, type: :controller do it 'updates the requested topic' do put :update, - { id: topic.to_param, topic: new_attributes, format: :json } + id: topic.to_param, topic: new_attributes, format: :json topic.reload expect(topic.name).to eq 'Cool Topic with no number' 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 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) end - it 'returns status of no content' do + it 'returns status of no content' do 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 end end @@ -79,7 +79,7 @@ RSpec.describe TopicsController, type: :controller do context 'with invalid params' do it 'assigns the topic as @topic' do 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) end end @@ -90,7 +90,7 @@ RSpec.describe TopicsController, type: :controller do it 'destroys the requested topic' do owned_topic.reload # ensure it's there 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) expect(response.body).to eq '' expect(response.status).to eq 204 diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 91da1d1c..746f52b1 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -15,8 +15,8 @@ FactoryGirl.define do password 'omgwtfbbq' factory :simple_user, aliases: [:user] do - joinedwithcode { "qwertyui" } - code { "qwertyui" } + joinedwithcode { 'qwertyui' } + code { 'qwertyui' } transient do validate false diff --git a/spec/mailers/map_mailer_spec.rb b/spec/mailers/map_mailer_spec.rb index 8572c8f5..9c398b20 100644 --- a/spec/mailers/map_mailer_spec.rb +++ b/spec/mailers/map_mailer_spec.rb @@ -1,4 +1,4 @@ -require "rails_helper" +require 'rails_helper' RSpec.describe MapMailer, type: :mailer do pending "add some examples to (or delete) #{__FILE__}" diff --git a/spec/models/map_spec.rb b/spec/models/map_spec.rb index 27227188..e70429be 100644 --- a/spec/models/map_spec.rb +++ b/spec/models/map_spec.rb @@ -6,4 +6,3 @@ RSpec.describe Map, type: :model do it { is_expected.to validate_presence_of :permission } it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) } end - diff --git a/spec/models/metacode_spec.rb b/spec/models/metacode_spec.rb index ad0b6ced..c9b34527 100644 --- a/spec/models/metacode_spec.rb +++ b/spec/models/metacode_spec.rb @@ -5,10 +5,14 @@ RSpec.describe Metacode, type: :model do it { is_expected.to have_many :metacode_sets } context 'BOTH aws_icon and manual_icon' do - let(:icon) { File.open(Rails.root.join('app', 'assets', 'images', - 'user.png')) } - let(:metacode) { build(:metacode, aws_icon: icon, - manual_icon: 'https://metamaps.cc/assets/user.png') } + let(:icon) do + File.open(Rails.root.join('app', 'assets', 'images', + '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 expect { metacode.save! }.to raise_error ActiveRecord::RecordInvalid end diff --git a/spec/models/synapse_spec.rb b/spec/models/synapse_spec.rb index 6ba5ff22..3bdb1ac4 100644 --- a/spec/models/synapse_spec.rb +++ b/spec/models/synapse_spec.rb @@ -9,5 +9,5 @@ RSpec.describe Synapse, type: :model do 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(: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 diff --git a/spec/models/token_spec.rb b/spec/models/token_spec.rb index ddb8d696..50e89c02 100644 --- a/spec/models/token_spec.rb +++ b/spec/models/token_spec.rb @@ -1,10 +1,10 @@ require 'rails_helper' RSpec.describe Token, type: :model do - context "#generate_token" do - subject (:token) { Token.new } - it "should generate an alphanumeric token of 32 characters" do - expect(token.send(:generate_token)).to match /^[a-zA-Z0-9]{32}$/ + context '#generate_token' do + subject(:token) { Token.new } + it 'should generate an alphanumeric token of 32 characters' do + expect(token.send(:generate_token)).to match(/^[a-zA-Z0-9]{32}$/) end end end diff --git a/spec/support/controller_helpers.rb b/spec/support/controller_helpers.rb index ed0d137a..a8364f91 100644 --- a/spec/support/controller_helpers.rb +++ b/spec/support/controller_helpers.rb @@ -21,6 +21,6 @@ module ControllerHelpers end RSpec.configure do |config| - config.include Devise::TestHelpers, :type => :controller - config.include ControllerHelpers, :type => :controller + config.include Devise::TestHelpers, type: :controller + config.include ControllerHelpers, type: :controller end