From caa65c1170b3d7592ad38fd4644a9c4f47af2964 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 26 Jan 2016 17:29:18 +0800 Subject: [PATCH 01/39] metacode spec --- spec/models/metacode_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/metacode_spec.rb b/spec/models/metacode_spec.rb index 10571a81..6e6435b0 100644 --- a/spec/models/metacode_spec.rb +++ b/spec/models/metacode_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' RSpec.describe Metacode, type: :model do - pending "add some examples to (or delete) #{__FILE__}" - it { is_expected.to have_many(:topics) } + it { is_expected.to have_many :topics } + it { is_expected.to have_many :metacode_sets } end From b3f8f6652a91e10407d90d7fd1f045ccc28bac14 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 26 Jan 2016 17:53:10 +0800 Subject: [PATCH 02/39] simplecov added --- .gitignore | 2 ++ .simplecov | 3 +++ Gemfile | 2 ++ Gemfile.lock | 12 +++++++++++- 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .simplecov diff --git a/.gitignore b/.gitignore index a2b03a61..43009ea4 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,8 @@ vendor/ log/*.log tmp +coverage + .DS_Store */.DS_Store .DS_Store? diff --git a/.simplecov b/.simplecov new file mode 100644 index 00000000..678db531 --- /dev/null +++ b/.simplecov @@ -0,0 +1,3 @@ +require 'simplecov-rcov' +SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter +SimpleCov.start 'rails' diff --git a/Gemfile b/Gemfile index b4e3bdf6..c00a87f9 100644 --- a/Gemfile +++ b/Gemfile @@ -42,6 +42,8 @@ group :test do gem 'rspec-rails' gem 'factory_girl_rails' gem 'shoulda-matchers' + gem 'simplecov', require: false + gem 'simplecov-rcov' end group :production do #this is used on heroku diff --git a/Gemfile.lock b/Gemfile.lock index 5525a8cc..f26652ce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -78,6 +78,7 @@ GEM thread_safe (~> 0.1) warden (~> 1.2.3) diff-lcs (1.2.5) + docile (1.1.5) dotenv (2.0.2) erubis (2.7.0) execjs (2.6.0) @@ -203,6 +204,13 @@ GEM tilt (>= 1.1, < 3) shoulda-matchers (3.0.1) activesupport (>= 4.0.0) + simplecov (0.11.1) + docile (~> 1.1.0) + json (~> 1.8) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) + simplecov-rcov (0.2.3) + simplecov (>= 0.4.1) slop (3.6.0) sprockets (3.4.0) rack (> 1, < 3) @@ -258,9 +266,11 @@ DEPENDENCIES rspec-rails sass-rails shoulda-matchers + simplecov + simplecov-rcov tunemygc uglifier uservoice-ruby BUNDLED WITH - 1.10.6 + 1.11.2 From fa3a725df92a9e81e17f42b31e814015c629a624 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 26 Jan 2016 17:58:33 +0800 Subject: [PATCH 03/39] mapping spec --- app/models/mapping.rb | 7 +++++-- spec/models/mapping_spec.rb | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/models/mapping.rb b/app/models/mapping.rb index 318aa5cf..680dbf8a 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -4,10 +4,13 @@ class Mapping < ActiveRecord::Base scope :synapsemapping, -> { where(mappable_type: :Synapse) } belongs_to :mappable, polymorphic: true - belongs_to :map, :class_name => "Map", :foreign_key => "map_id" - belongs_to :user + + validates :xloc, presence: true + validates :yloc, presence: true + validates :map, presence: true + validates :mappable, presence: true def user_name self.user.name diff --git a/spec/models/mapping_spec.rb b/spec/models/mapping_spec.rb index 32d34796..54c72b88 100644 --- a/spec/models/mapping_spec.rb +++ b/spec/models/mapping_spec.rb @@ -1,5 +1,11 @@ require 'rails_helper' RSpec.describe Mapping, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + it { is_expected.to belong_to :user } + it { is_expected.to belong_to :map } + it { is_expected.to belong_to :mappable } + it { is_expected.to validate_presence_of :xloc } + it { is_expected.to validate_presence_of :yloc } + it { is_expected.to validate_presence_of :map } + it { is_expected.to validate_presence_of :mappable } end From 46013bc1b564a3d376c692feabe2df8dd4186b14 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 26 Jan 2016 18:14:32 +0800 Subject: [PATCH 04/39] start speccing out mappings controller --- spec/controllers/mappings_controller_spec.rb | 107 ++----------------- spec/factories/mappings.rb | 9 ++ spec/spec_helper.rb | 8 ++ 3 files changed, 28 insertions(+), 96 deletions(-) create mode 100644 spec/factories/mappings.rb diff --git a/spec/controllers/mappings_controller_spec.rb b/spec/controllers/mappings_controller_spec.rb index 8a7acda5..b2568b51 100644 --- a/spec/controllers/mappings_controller_spec.rb +++ b/spec/controllers/mappings_controller_spec.rb @@ -1,60 +1,14 @@ require 'rails_helper' -# This spec was generated by rspec-rails when you ran the scaffold generator. -# It demonstrates how one might use RSpec to specify the controller code that -# was generated by Rails when you ran the scaffold generator. -# -# It assumes that the implementation code is generated by the rails scaffold -# generator. If you are using any extension libraries to generate different -# controller code, this generated spec may or may not pass. -# -# It only uses APIs available in rails and/or rspec-rails. There are a number -# of tools you can use to make these specs even more expressive, but we're -# sticking to rails and rspec-rails APIs to keep things simple and stable. -# -# Compared to earlier versions of this generator, there is very limited use of -# stubs and message expectations in this spec. Stubs are only used when there -# is no simpler way to get a handle on the object needed for the example. -# Message expectations are only used when there is no simpler way to specify -# that an instance is receiving a specific message. - RSpec.describe MappingsController, type: :controller do - # This should return the minimal set of attributes required to create a valid - # Mapping. As you add validations to Mapping, be sure to - # adjust the attributes here as well. - let(:valid_attributes) do - skip('Add a hash of attributes valid for your model') - end - - let(:invalid_attributes) do - skip('Add a hash of attributes invalid for your model') - end - - # This should return the minimal set of values that should be in the session - # in order to pass any filters (e.g. authentication) defined in - # MappingsController. Be sure to keep this updated too. - let(:valid_session) { {} } - - describe 'GET #index' do - it 'assigns all mappings as @mappings' do - mapping = Mapping.create! valid_attributes - get :index, {}, valid_session - expect(assigns(:mappings)).to eq([mapping]) - end + let(:mapping) { create(:mapping) } + before :each do + sign_in end describe 'GET #show' do it 'assigns the requested mapping as @mapping' do - mapping = Mapping.create! valid_attributes - get :show, { id: mapping.to_param }, valid_session - expect(assigns(:mapping)).to eq(mapping) - end - end - - describe 'GET #edit' do - it 'assigns the requested mapping as @mapping' do - mapping = Mapping.create! valid_attributes - get :edit, { id: mapping.to_param }, valid_session + get :show, { id: mapping.to_param } expect(assigns(:mapping)).to eq(mapping) end end @@ -63,32 +17,22 @@ RSpec.describe MappingsController, type: :controller do context 'with valid params' do it 'creates a new Mapping' do expect do - post :create, { mapping: valid_attributes }, valid_session + 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 }, valid_session + post :create, { mapping: valid_attributes } expect(assigns(:mapping)).to be_a(Mapping) expect(assigns(:mapping)).to be_persisted end - - it 'redirects to the created mapping' do - post :create, { mapping: valid_attributes }, valid_session - expect(response).to redirect_to(Mapping.last) - end end context 'with invalid params' do it 'assigns a newly created but unsaved mapping as @mapping' do - post :create, { mapping: invalid_attributes }, valid_session + post :create, { mapping: invalid_attributes } expect(assigns(:mapping)).to be_a_new(Mapping) end - - it "re-renders the 'new' template" do - post :create, { mapping: invalid_attributes }, valid_session - expect(response).to render_template('new') - end end end @@ -99,62 +43,33 @@ RSpec.describe MappingsController, type: :controller do end it 'updates the requested mapping' do - mapping = Mapping.create! valid_attributes put :update, - { id: mapping.to_param, mapping: new_attributes }, - valid_session + { id: mapping.to_param, mapping: new_attributes } mapping.reload skip('Add assertions for updated state') end it 'assigns the requested mapping as @mapping' do - mapping = Mapping.create! valid_attributes put :update, - { id: mapping.to_param, mapping: valid_attributes }, - valid_session + { id: mapping.to_param, mapping: valid_attributes } expect(assigns(:mapping)).to eq(mapping) end - - it 'redirects to the mapping' do - mapping = Mapping.create! valid_attributes - put :update, - { id: mapping.to_param, mapping: valid_attributes }, - valid_session - expect(response).to redirect_to(mapping) - end end context 'with invalid params' do it 'assigns the mapping as @mapping' do - mapping = Mapping.create! valid_attributes put :update, - { id: mapping.to_param, mapping: invalid_attributes }, - valid_session + { id: mapping.to_param, mapping: invalid_attributes } expect(assigns(:mapping)).to eq(mapping) end - - it "re-renders the 'edit' template" do - mapping = Mapping.create! valid_attributes - put :update, - { id: mapping.to_param, mapping: invalid_attributes }, - valid_session - expect(response).to render_template('edit') - end end end describe 'DELETE #destroy' do it 'destroys the requested mapping' do - mapping = Mapping.create! valid_attributes expect do - delete :destroy, { id: mapping.to_param }, valid_session + delete :destroy, { id: mapping.to_param } end.to change(Mapping, :count).by(-1) end - - it 'redirects to the mappings list' do - mapping = Mapping.create! valid_attributes - delete :destroy, { id: mapping.to_param }, valid_session - expect(response).to redirect_to(mappings_url) - end end end diff --git a/spec/factories/mappings.rb b/spec/factories/mappings.rb new file mode 100644 index 00000000..479a3a16 --- /dev/null +++ b/spec/factories/mappings.rb @@ -0,0 +1,9 @@ +FactoryGirl.define do + factory :mapping do + xloc 0 + yloc 0 + map + user + association :mappable, factory: :topic + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a2b164b2..9cab52e4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,6 @@ +require 'support/controller_helpers' +require 'devise' + RSpec.configure do |config| config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true @@ -6,4 +9,9 @@ RSpec.configure do |config| config.mock_with :rspec do |mocks| mocks.verify_partial_doubles = true end + + RSpec.configure do |config| + config.include Devise::TestHelpers, type: :controller + config.extend ControllerHelpers, type: :controller + end end From cc99ed001d8318ee642ab68e55bf3ab247c83c6a Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 26 Jan 2016 18:42:24 +0800 Subject: [PATCH 05/39] fix mapping_controller_spec.rb --- app/controllers/mappings_controller.rb | 6 ------ app/models/mapping.rb | 2 +- spec/controllers/mappings_controller_spec.rb | 9 ++++----- spec/factories/mappings.rb | 5 +++++ spec/spec_helper.rb | 6 ------ spec/support/controller_helpers.rb | 8 ++++++++ 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/controllers/mappings_controller.rb b/app/controllers/mappings_controller.rb index 27567eb4..c20b0153 100644 --- a/app/controllers/mappings_controller.rb +++ b/app/controllers/mappings_controller.rb @@ -15,8 +15,6 @@ class MappingsController < ApplicationController def create @mapping = Mapping.new(mapping_params) - @mapping.map.touch(:updated_at) - if @mapping.save render json: @mapping, status: :created else @@ -28,8 +26,6 @@ class MappingsController < ApplicationController def update @mapping = Mapping.find(params[:id]) - @mapping.map.touch(:updated_at) - if @mapping.update_attributes(mapping_params) head :no_content else @@ -44,8 +40,6 @@ class MappingsController < ApplicationController @mapping.destroy - @map.touch(:updated_at) - head :no_content end diff --git a/app/models/mapping.rb b/app/models/mapping.rb index 680dbf8a..425f358d 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -4,7 +4,7 @@ class Mapping < ActiveRecord::Base scope :synapsemapping, -> { where(mappable_type: :Synapse) } belongs_to :mappable, polymorphic: true - belongs_to :map, :class_name => "Map", :foreign_key => "map_id" + belongs_to :map, :class_name => "Map", :foreign_key => "map_id", touch: true belongs_to :user validates :xloc, presence: true diff --git a/spec/controllers/mappings_controller_spec.rb b/spec/controllers/mappings_controller_spec.rb index b2568b51..ffc9bac9 100644 --- a/spec/controllers/mappings_controller_spec.rb +++ b/spec/controllers/mappings_controller_spec.rb @@ -1,7 +1,9 @@ require 'rails_helper' RSpec.describe MappingsController, type: :controller do - let(:mapping) { create(:mapping) } + let!(:mapping) { create(:mapping) } + let(:valid_attributes) { mapping.attributes.except('id') } + let(:invalid_attributes) { { xloc: 0 } } before :each do sign_in end @@ -38,15 +40,12 @@ RSpec.describe MappingsController, type: :controller do describe 'PUT #update' do context 'with valid params' do - let(:new_attributes) do - skip('Add a hash of attributes valid for your model') - end + let(:new_attributes) { build(:mapping_random_location).attributes.except('id') } it 'updates the requested mapping' do put :update, { id: mapping.to_param, mapping: new_attributes } mapping.reload - skip('Add assertions for updated state') end it 'assigns the requested mapping as @mapping' do diff --git a/spec/factories/mappings.rb b/spec/factories/mappings.rb index 479a3a16..bed0b754 100644 --- a/spec/factories/mappings.rb +++ b/spec/factories/mappings.rb @@ -5,5 +5,10 @@ FactoryGirl.define do map user association :mappable, factory: :topic + + factory :mapping_random_location do + xloc { rand(-100...100) } + yloc { rand(-100...100) } + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9cab52e4..842badd5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,4 @@ require 'support/controller_helpers' -require 'devise' RSpec.configure do |config| config.expect_with :rspec do |expectations| @@ -9,9 +8,4 @@ RSpec.configure do |config| config.mock_with :rspec do |mocks| mocks.verify_partial_doubles = true end - - RSpec.configure do |config| - config.include Devise::TestHelpers, type: :controller - config.extend ControllerHelpers, type: :controller - end end diff --git a/spec/support/controller_helpers.rb b/spec/support/controller_helpers.rb index 5fe34854..dc301e11 100644 --- a/spec/support/controller_helpers.rb +++ b/spec/support/controller_helpers.rb @@ -1,4 +1,7 @@ # https://github.com/plataformatec/devise/wiki/How-To:-Stub-authentication-in-controller-specs + +require 'devise' + module ControllerHelpers # rubocop:disable Metrics/AbcSize def sign_in(user = create(:user)) @@ -15,3 +18,8 @@ module ControllerHelpers end # rubocop:enable Metrics/AbcSize end + +RSpec.configure do |config| + config.include Devise::TestHelpers, :type => :controller + config.include ControllerHelpers, :type => :controller +end From d64fe002dc906dc0c91fbcf390358b99275b45bd Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 26 Jan 2016 18:47:42 +0800 Subject: [PATCH 06/39] suppress devise warnings on rspec tests --- spec/support/controller_helpers.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/support/controller_helpers.rb b/spec/support/controller_helpers.rb index dc301e11..ed0d137a 100644 --- a/spec/support/controller_helpers.rb +++ b/spec/support/controller_helpers.rb @@ -10,6 +10,7 @@ module ControllerHelpers receive(:authenticate!).and_throw(:warden, scope: :user) ) else # simulate authenticated + allow_message_expectations_on_nil allow(request.env['warden']).to( receive(:authenticate!).and_return(user) ) From e460899ea34a710c8dea5f82dcde5b5a9f8dcd47 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 1 Feb 2016 17:25:06 +0800 Subject: [PATCH 07/39] testing simplecov and rcov stuff --- .simplecov | 10 +++++++--- app/models/synapse.rb | 6 ++++++ bin/jenkins-test.sh | 4 ++-- spec/spec_helper.rb | 1 + 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.simplecov b/.simplecov index 678db531..deb2c46e 100644 --- a/.simplecov +++ b/.simplecov @@ -1,3 +1,7 @@ -require 'simplecov-rcov' -SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter -SimpleCov.start 'rails' +if ENV['COVERAGE_FORMATTER'] == 'rcov' + require 'simplecov-rcov' + SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter +end +if ENV['COVERAGE'] == 'on' + SimpleCov.start 'rails' +end diff --git a/app/models/synapse.rb b/app/models/synapse.rb index 225485e5..0b40da02 100644 --- a/app/models/synapse.rb +++ b/app/models/synapse.rb @@ -13,17 +13,23 @@ class Synapse < ActiveRecord::Base validates :permission, presence: true validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) } + # :nocov: def user_name self.user.name end + # :nocov: + # :nocov: def user_image self.user.image.url end + # :nocov: + # :nocov: def as_json(options={}) super(:methods =>[:user_name, :user_image]) end + # :nocov: ##### PERMISSIONS ###### diff --git a/bin/jenkins-test.sh b/bin/jenkins-test.sh index 313c23b3..511899c7 100755 --- a/bin/jenkins-test.sh +++ b/bin/jenkins-test.sh @@ -1,6 +1,6 @@ #!/bin/bash -l -#prerequisites +# jenkins machine prerequisites #sudo aptitude -q -y install libpq-dev source "$HOME/.rvm/scripts/rvm" @@ -21,4 +21,4 @@ sed -i -e "s/DB_USERNAME='.*'/DB_USERNAME='jenkins'/" .env #test bundle install rake db:create db:test:prepare -bundle exec rspec +COVERAGE=on COVERAGE_FORMATTER=rcov bundle exec rspec diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 842badd5..08ffd17f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,4 @@ +require 'simplecov' require 'support/controller_helpers' RSpec.configure do |config| From 80a6bcbca2bcd1ef1f6c6a528ba9547c40406c78 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 5 Feb 2016 15:35:06 +0800 Subject: [PATCH 08/39] remove annoying rcov gem --- .simplecov | 4 ---- Gemfile | 1 - Gemfile.lock | 3 --- bin/jenkins-test.sh | 5 +++-- 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/.simplecov b/.simplecov index deb2c46e..b81ebfeb 100644 --- a/.simplecov +++ b/.simplecov @@ -1,7 +1,3 @@ -if ENV['COVERAGE_FORMATTER'] == 'rcov' - require 'simplecov-rcov' - SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter -end if ENV['COVERAGE'] == 'on' SimpleCov.start 'rails' end diff --git a/Gemfile b/Gemfile index c00a87f9..b8872752 100644 --- a/Gemfile +++ b/Gemfile @@ -43,7 +43,6 @@ group :test do gem 'factory_girl_rails' gem 'shoulda-matchers' gem 'simplecov', require: false - gem 'simplecov-rcov' end group :production do #this is used on heroku diff --git a/Gemfile.lock b/Gemfile.lock index f26652ce..710f5f10 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -209,8 +209,6 @@ GEM json (~> 1.8) simplecov-html (~> 0.10.0) simplecov-html (0.10.0) - simplecov-rcov (0.2.3) - simplecov (>= 0.4.1) slop (3.6.0) sprockets (3.4.0) rack (> 1, < 3) @@ -267,7 +265,6 @@ DEPENDENCIES sass-rails shoulda-matchers simplecov - simplecov-rcov tunemygc uglifier uservoice-ruby diff --git a/bin/jenkins-test.sh b/bin/jenkins-test.sh index 511899c7..f9059d30 100755 --- a/bin/jenkins-test.sh +++ b/bin/jenkins-test.sh @@ -1,7 +1,8 @@ #!/bin/bash -l # jenkins machine prerequisites -#sudo aptitude -q -y install libpq-dev +# sudo aptitude -q -y install libpq-dev +# install rvm with user gemsets source "$HOME/.rvm/scripts/rvm" rvm use $(cat .ruby-version) || \ @@ -21,4 +22,4 @@ sed -i -e "s/DB_USERNAME='.*'/DB_USERNAME='jenkins'/" .env #test bundle install rake db:create db:test:prepare -COVERAGE=on COVERAGE_FORMATTER=rcov bundle exec rspec +COVERAGE=on bundle exec rspec From 17ee69b1475f9ea28f23b475453ddab80b6822b0 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 8 Feb 2016 11:56:46 +0800 Subject: [PATCH 09/39] start fixing other controller specs --- spec/controllers/maps_controller_spec.rb | 82 +++++------------ spec/controllers/metacodes_controller_spec.rb | 87 +++++-------------- spec/controllers/synapses_controller_spec.rb | 82 +++++------------ spec/controllers/topics_controller_spec.rb | 58 +++++-------- 4 files changed, 80 insertions(+), 229 deletions(-) diff --git a/spec/controllers/maps_controller_spec.rb b/spec/controllers/maps_controller_spec.rb index fdaa064a..3a8d3f0b 100644 --- a/spec/controllers/maps_controller_spec.rb +++ b/spec/controllers/maps_controller_spec.rb @@ -1,60 +1,30 @@ require 'rails_helper' -# This spec was generated by rspec-rails when you ran the scaffold generator. -# It demonstrates how one might use RSpec to specify the controller code that -# was generated by Rails when you ran the scaffold generator. -# -# It assumes that the implementation code is generated by the rails scaffold -# generator. If you are using any extension libraries to generate different -# controller code, this generated spec may or may not pass. -# -# It only uses APIs available in rails and/or rspec-rails. There are a number -# of tools you can use to make these specs even more expressive, but we're -# sticking to rails and rspec-rails APIs to keep things simple and stable. -# -# Compared to earlier versions of this generator, there is very limited use of -# stubs and message expectations in this spec. Stubs are only used when there -# is no simpler way to get a handle on the object needed for the example. -# Message expectations are only used when there is no simpler way to specify -# that an instance is receiving a specific message. - RSpec.describe MapsController, type: :controller do - # This should return the minimal set of attributes required to create a valid - # Map. As you add validations to Map, be sure to - # adjust the attributes here as well. - let(:valid_attributes) do - skip('Add a hash of attributes valid for your model') + let(:map) { create(:map) } + let(:valid_attributes) { map.attributes.except(:id) } + let(:invalid_attributes) { { permission: :commons } } + before :each do + sign_in end - let(:invalid_attributes) do - skip('Add a hash of attributes invalid for your model') - end - - # This should return the minimal set of values that should be in the session - # in order to pass any filters (e.g. authentication) defined in - # MapsController. Be sure to keep this updated too. - let(:valid_session) { {} } - describe 'GET #index' do it 'assigns all maps as @maps' do - map = Map.create! valid_attributes - get :index, {}, valid_session + get :index, {} expect(assigns(:maps)).to eq([map]) end end describe 'GET #show' do it 'assigns the requested map as @map' do - map = Map.create! valid_attributes - get :show, { id: map.to_param }, valid_session + get :show, { id: map.to_param } expect(assigns(:map)).to eq(map) end end describe 'GET #edit' do it 'assigns the requested map as @map' do - map = Map.create! valid_attributes - get :edit, { id: map.to_param }, valid_session + get :edit, { id: map.to_param } expect(assigns(:map)).to eq(map) end end @@ -63,30 +33,30 @@ RSpec.describe MapsController, type: :controller do context 'with valid params' do it 'creates a new Map' do expect do - post :create, { map: valid_attributes }, valid_session + post :create, { map: valid_attributes } end.to change(Map, :count).by(1) end it 'assigns a newly created map as @map' do - post :create, { map: valid_attributes }, valid_session + post :create, { map: valid_attributes } expect(assigns(:map)).to be_a(Map) expect(assigns(:map)).to be_persisted end it 'redirects to the created map' do - post :create, { map: valid_attributes }, valid_session + post :create, { map: valid_attributes } expect(response).to redirect_to(Map.last) end end context 'with invalid params' do it 'assigns a newly created but unsaved map as @map' do - post :create, { map: invalid_attributes }, valid_session + post :create, { map: invalid_attributes } expect(assigns(:map)).to be_a_new(Map) end it "re-renders the 'new' template" do - post :create, { map: invalid_attributes }, valid_session + post :create, { map: invalid_attributes } expect(response).to render_template('new') end end @@ -99,45 +69,35 @@ RSpec.describe MapsController, type: :controller do end it 'updates the requested map' do - map = Map.create! valid_attributes put :update, - { id: map.to_param, map: new_attributes }, - valid_session + { id: map.to_param, map: new_attributes } map.reload skip('Add assertions for updated state') end it 'assigns the requested map as @map' do - map = Map.create! valid_attributes put :update, - { id: map.to_param, map: valid_attributes }, - valid_session + { id: map.to_param, map: valid_attributes } expect(assigns(:map)).to eq(map) end it 'redirects to the map' do - map = Map.create! valid_attributes put :update, - { id: map.to_param, map: valid_attributes }, - valid_session + { id: map.to_param, map: valid_attributes } expect(response).to redirect_to(map) end end context 'with invalid params' do it 'assigns the map as @map' do - map = Map.create! valid_attributes put :update, - { id: map.to_param, map: invalid_attributes }, - valid_session + { id: map.to_param, map: invalid_attributes } expect(assigns(:map)).to eq(map) end it "re-renders the 'edit' template" do - map = Map.create! valid_attributes put :update, - { id: map.to_param, map: invalid_attributes }, - valid_session + { id: map.to_param, map: invalid_attributes } expect(response).to render_template('edit') end end @@ -145,15 +105,13 @@ RSpec.describe MapsController, type: :controller do describe 'DELETE #destroy' do it 'destroys the requested map' do - map = Map.create! valid_attributes expect do - delete :destroy, { id: map.to_param }, valid_session + delete :destroy, { id: map.to_param } end.to change(Map, :count).by(-1) end it 'redirects to the maps list' do - map = Map.create! valid_attributes - delete :destroy, { id: map.to_param }, valid_session + delete :destroy, { id: map.to_param } expect(response).to redirect_to(maps_url) end end diff --git a/spec/controllers/metacodes_controller_spec.rb b/spec/controllers/metacodes_controller_spec.rb index 6e1ba2b9..5f9a148e 100644 --- a/spec/controllers/metacodes_controller_spec.rb +++ b/spec/controllers/metacodes_controller_spec.rb @@ -1,72 +1,37 @@ require 'rails_helper' -# This spec was generated by rspec-rails when you ran the scaffold generator. -# It demonstrates how one might use RSpec to specify the controller code that -# was generated by Rails when you ran the scaffold generator. -# -# It assumes that the implementation code is generated by the rails scaffold -# generator. If you are using any extension libraries to generate different -# controller code, this generated spec may or may not pass. -# -# It only uses APIs available in rails and/or rspec-rails. There are a number -# of tools you can use to make these specs even more expressive, but we're -# sticking to rails and rspec-rails APIs to keep things simple and stable. -# -# Compared to earlier versions of this generator, there is very limited use of -# stubs and message expectations in this spec. Stubs are only used when there -# is no simpler way to get a handle on the object needed for the example. -# Message expectations are only used when there is no simpler way to specify -# that an instance is receiving a specific message. - RSpec.describe MetacodesController, type: :controller do + let(:metacode) { create(:metacode) } + let(:valid_attributes) { metacode.attributes.except(:id) } + let(:invalid_attributes) { { permission: :commons } } before :each do - @user = create(:user, admin: true) - sign_in @user + sign_in end - # This should return the minimal set of attributes required to create a valid - # Metacode. As you add validations to Metacode, be sure to - # adjust the attributes here as well. - let(:valid_attributes) do - skip('Add a hash of attributes valid for your model') - end - - let(:invalid_attributes) do - skip('Add a hash of attributes invalid for your model') - end - - # This should return the minimal set of values that should be in the session - # in order to pass any filters (e.g. authentication) defined in - # MetacodesController. Be sure to keep this updated too. - let(:valid_session) { {} } - describe 'GET #index' do it 'assigns all metacodes as @metacodes' do - metacode = Metacode.create! valid_attributes - get :index, {}, valid_session + get :index, {} expect(assigns(:metacodes)).to eq([metacode]) end end describe 'GET #show' do it 'assigns the requested metacode as @metacode' do - metacode = Metacode.create! valid_attributes - get :show, { id: metacode.to_param }, valid_session + get :show, { id: metacode.to_param } expect(assigns(:metacode)).to eq(metacode) end end describe 'GET #new' do it 'assigns a new metacode as @metacode' do - get :new, {}, valid_session + get :new, {} expect(assigns(:metacode)).to be_a_new(Metacode) end end describe 'GET #edit' do it 'assigns the requested metacode as @metacode' do - metacode = Metacode.create! valid_attributes - get :edit, { id: metacode.to_param }, valid_session + get :edit, { id: metacode.to_param } expect(assigns(:metacode)).to eq(metacode) end end @@ -75,30 +40,30 @@ RSpec.describe MetacodesController, type: :controller do context 'with valid params' do it 'creates a new Metacode' do expect do - post :create, { metacode: valid_attributes }, valid_session + post :create, { metacode: valid_attributes } end.to change(Metacode, :count).by(1) end it 'assigns a newly created metacode as @metacode' do - post :create, { metacode: valid_attributes }, valid_session + post :create, { metacode: valid_attributes } expect(assigns(:metacode)).to be_a(Metacode) expect(assigns(:metacode)).to be_persisted end it 'redirects to the created metacode' do - post :create, { metacode: valid_attributes }, valid_session + post :create, { metacode: valid_attributes } expect(response).to redirect_to(Metacode.last) end end context 'with invalid params' do it 'assigns a newly created but unsaved metacode as @metacode' do - post :create, { metacode: invalid_attributes }, valid_session + post :create, { metacode: invalid_attributes } expect(assigns(:metacode)).to be_a_new(Metacode) end it "re-renders the 'new' template" do - post :create, { metacode: invalid_attributes }, valid_session + post :create, { metacode: invalid_attributes } expect(response).to render_template('new') end end @@ -111,45 +76,35 @@ RSpec.describe MetacodesController, type: :controller do end it 'updates the requested metacode' do - metacode = Metacode.create! valid_attributes put :update, - { id: metacode.to_param, metacode: new_attributes }, - valid_session + { id: metacode.to_param, metacode: new_attributes } metacode.reload skip('Add assertions for updated state') end it 'assigns the requested metacode as @metacode' do - metacode = Metacode.create! valid_attributes put :update, - { id: metacode.to_param, metacode: valid_attributes }, - valid_session + { id: metacode.to_param, metacode: valid_attributes } expect(assigns(:metacode)).to eq(metacode) end it 'redirects to the metacode' do - metacode = Metacode.create! valid_attributes put :update, - { id: metacode.to_param, metacode: valid_attributes }, - valid_session + { id: metacode.to_param, metacode: valid_attributes } expect(response).to redirect_to(metacode) end end context 'with invalid params' do it 'assigns the metacode as @metacode' do - metacode = Metacode.create! valid_attributes put :update, - { id: metacode.to_param, metacode: invalid_attributes }, - valid_session + { id: metacode.to_param, metacode: invalid_attributes } expect(assigns(:metacode)).to eq(metacode) end it "re-renders the 'edit' template" do - metacode = Metacode.create! valid_attributes put :update, - { id: metacode.to_param, metacode: invalid_attributes }, - valid_session + { id: metacode.to_param, metacode: invalid_attributes } expect(response).to render_template('edit') end end @@ -157,15 +112,13 @@ RSpec.describe MetacodesController, type: :controller do describe 'DELETE #destroy' do it 'destroys the requested metacode' do - metacode = Metacode.create! valid_attributes expect do - delete :destroy, { id: metacode.to_param }, valid_session + delete :destroy, { id: metacode.to_param } end.to change(Metacode, :count).by(-1) end it 'redirects to the metacodes list' do - metacode = Metacode.create! valid_attributes - delete :destroy, { id: metacode.to_param }, valid_session + delete :destroy, { id: metacode.to_param } expect(response).to redirect_to(metacodes_url) end end diff --git a/spec/controllers/synapses_controller_spec.rb b/spec/controllers/synapses_controller_spec.rb index ff05ea6f..90d70e8d 100644 --- a/spec/controllers/synapses_controller_spec.rb +++ b/spec/controllers/synapses_controller_spec.rb @@ -1,60 +1,30 @@ require 'rails_helper' -# This spec was generated by rspec-rails when you ran the scaffold generator. -# It demonstrates how one might use RSpec to specify the controller code that -# was generated by Rails when you ran the scaffold generator. -# -# It assumes that the implementation code is generated by the rails scaffold -# generator. If you are using any extension libraries to generate different -# controller code, this generated spec may or may not pass. -# -# It only uses APIs available in rails and/or rspec-rails. There are a number -# of tools you can use to make these specs even more expressive, but we're -# sticking to rails and rspec-rails APIs to keep things simple and stable. -# -# Compared to earlier versions of this generator, there is very limited use of -# stubs and message expectations in this spec. Stubs are only used when there -# is no simpler way to get a handle on the object needed for the example. -# Message expectations are only used when there is no simpler way to specify -# that an instance is receiving a specific message. - RSpec.describe SynapsesController, type: :controller do - # This should return the minimal set of attributes required to create a valid - # Synapse. As you add validations to Synapse, be sure to - # adjust the attributes here as well. - let(:valid_attributes) do - skip('Add a hash of attributes valid for your model') + let(:synapse) { create(:synapse) } + let(:valid_attributes) { synapse.attributes.except(:id) } + let(:invalid_attributes) { { permission: :commons } } + before :each do + sign_in end - let(:invalid_attributes) do - skip('Add a hash of attributes invalid for your model') - end - - # This should return the minimal set of values that should be in the session - # in order to pass any filters (e.g. authentication) defined in - # SynapsesController. Be sure to keep this updated too. - let(:valid_session) { {} } - describe 'GET #index' do it 'assigns all synapses as @synapses' do - synapse = Synapse.create! valid_attributes - get :index, {}, valid_session + get :index, {} expect(assigns(:synapses)).to eq([synapse]) end end describe 'GET #show' do it 'assigns the requested synapse as @synapse' do - synapse = Synapse.create! valid_attributes - get :show, { id: synapse.to_param }, valid_session + get :show, { id: synapse.to_param } expect(assigns(:synapse)).to eq(synapse) end end describe 'GET #edit' do it 'assigns the requested synapse as @synapse' do - synapse = Synapse.create! valid_attributes - get :edit, { id: synapse.to_param }, valid_session + get :edit, { id: synapse.to_param } expect(assigns(:synapse)).to eq(synapse) end end @@ -63,30 +33,30 @@ RSpec.describe SynapsesController, type: :controller do context 'with valid params' do it 'creates a new Synapse' do expect do - post :create, { synapse: valid_attributes }, valid_session + post :create, { synapse: valid_attributes } end.to change(Synapse, :count).by(1) end it 'assigns a newly created synapse as @synapse' do - post :create, { synapse: valid_attributes }, valid_session + post :create, { synapse: valid_attributes } expect(assigns(:synapse)).to be_a(Synapse) expect(assigns(:synapse)).to be_persisted end it 'redirects to the created synapse' do - post :create, { synapse: valid_attributes }, valid_session + post :create, { synapse: valid_attributes } expect(response).to redirect_to(Synapse.last) end end context 'with invalid params' do it 'assigns a newly created but unsaved synapse as @synapse' do - post :create, { synapse: invalid_attributes }, valid_session + post :create, { synapse: invalid_attributes } expect(assigns(:synapse)).to be_a_new(Synapse) end it "re-renders the 'new' template" do - post :create, { synapse: invalid_attributes }, valid_session + post :create, { synapse: invalid_attributes } expect(response).to render_template('new') end end @@ -99,45 +69,35 @@ RSpec.describe SynapsesController, type: :controller do end it 'updates the requested synapse' do - synapse = Synapse.create! valid_attributes put :update, - { id: synapse.to_param, synapse: new_attributes }, - valid_session + { id: synapse.to_param, synapse: new_attributes } synapse.reload skip('Add assertions for updated state') end it 'assigns the requested synapse as @synapse' do - synapse = Synapse.create! valid_attributes put :update, - { id: synapse.to_param, synapse: valid_attributes }, - valid_session + { id: synapse.to_param, synapse: valid_attributes } expect(assigns(:synapse)).to eq(synapse) end it 'redirects to the synapse' do - synapse = Synapse.create! valid_attributes put :update, - { id: synapse.to_param, synapse: valid_attributes }, - valid_session + { id: synapse.to_param, synapse: valid_attributes } expect(response).to redirect_to(synapse) end end context 'with invalid params' do it 'assigns the synapse as @synapse' do - synapse = Synapse.create! valid_attributes put :update, - { id: synapse.to_param, synapse: invalid_attributes }, - valid_session + { id: synapse.to_param, synapse: invalid_attributes } expect(assigns(:synapse)).to eq(synapse) end it "re-renders the 'edit' template" do - synapse = Synapse.create! valid_attributes put :update, - { id: synapse.to_param, synapse: invalid_attributes }, - valid_session + { id: synapse.to_param, synapse: invalid_attributes } expect(response).to render_template('edit') end end @@ -145,15 +105,13 @@ RSpec.describe SynapsesController, type: :controller do describe 'DELETE #destroy' do it 'destroys the requested synapse' do - synapse = Synapse.create! valid_attributes expect do - delete :destroy, { id: synapse.to_param }, valid_session + delete :destroy, { id: synapse.to_param } end.to change(Synapse, :count).by(-1) end it 'redirects to the synapses list' do - synapse = Synapse.create! valid_attributes - delete :destroy, { id: synapse.to_param }, valid_session + delete :destroy, { id: synapse.to_param } expect(response).to redirect_to(synapses_url) end end diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index 35b2156e..5191c2fe 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -1,36 +1,30 @@ require 'rails_helper' RSpec.describe TopicsController, type: :controller do - let(:valid_attributes) do - skip('Add a hash of attributes valid for your model') + let(:topic) { create(:topic) } + let(:valid_attributes) { topic.attributes.except(:id) } + let(:invalid_attributes) { { permission: :commons } } + before :each do + sign_in end - let(:invalid_attributes) do - skip('Add a hash of attributes invalid for your model') - end - - let(:valid_session) { {} } - describe 'GET #index' do it 'assigns all topics as @topics' do - topic = Topic.create! valid_attributes - get :index, {}, valid_session + get :index, {} expect(assigns(:topics)).to eq([topic]) end end describe 'GET #show' do it 'assigns the requested topic as @topic' do - topic = Topic.create! valid_attributes - get :show, { id: topic.to_param }, valid_session + get :show, { id: topic.to_param } expect(assigns(:topic)).to eq(topic) end end describe 'GET #edit' do it 'assigns the requested topic as @topic' do - topic = Topic.create! valid_attributes - get :edit, { id: topic.to_param }, valid_session + get :edit, { id: topic.to_param } expect(assigns(:topic)).to eq(topic) end end @@ -39,30 +33,30 @@ RSpec.describe TopicsController, type: :controller do context 'with valid params' do it 'creates a new Topic' do expect do - post :create, { topic: valid_attributes }, valid_session + post :create, { topic: valid_attributes } end.to change(Topic, :count).by(1) end it 'assigns a newly created topic as @topic' do - post :create, { topic: valid_attributes }, valid_session + post :create, { topic: valid_attributes } expect(assigns(:topic)).to be_a(Topic) expect(assigns(:topic)).to be_persisted end it 'redirects to the created topic' do - post :create, { topic: valid_attributes }, valid_session + post :create, { topic: valid_attributes } expect(response).to redirect_to(Topic.last) end end context 'with invalid params' do it 'assigns a newly created but unsaved topic as @topic' do - post :create, { topic: invalid_attributes }, valid_session + post :create, { topic: invalid_attributes } expect(assigns(:topic)).to be_a_new(Topic) end it "re-renders the 'new' template" do - post :create, { topic: invalid_attributes }, valid_session + post :create, { topic: invalid_attributes } expect(response).to render_template('new') end end @@ -75,45 +69,35 @@ RSpec.describe TopicsController, type: :controller do end it 'updates the requested topic' do - topic = Topic.create! valid_attributes put :update, - { id: topic.to_param, topic: new_attributes }, - valid_session + { id: topic.to_param, topic: new_attributes } topic.reload skip('Add assertions for updated state') end it 'assigns the requested topic as @topic' do - topic = Topic.create! valid_attributes put :update, - { id: topic.to_param, topic: valid_attributes }, - valid_session + { id: topic.to_param, topic: valid_attributes } expect(assigns(:topic)).to eq(topic) end it 'redirects to the topic' do - topic = Topic.create! valid_attributes put :update, - { id: topic.to_param, topic: valid_attributes }, - valid_session + { id: topic.to_param, topic: valid_attributes } expect(response).to redirect_to(topic) end end context 'with invalid params' do it 'assigns the topic as @topic' do - topic = Topic.create! valid_attributes put :update, - { id: topic.to_param, topic: invalid_attributes }, - valid_session + { id: topic.to_param, topic: invalid_attributes } expect(assigns(:topic)).to eq(topic) end it "re-renders the 'edit' template" do - topic = Topic.create! valid_attributes put :update, - { id: topic.to_param, topic: invalid_attributes }, - valid_session + { id: topic.to_param, topic: invalid_attributes } expect(response).to render_template('edit') end end @@ -121,15 +105,13 @@ RSpec.describe TopicsController, type: :controller do describe 'DELETE #destroy' do it 'destroys the requested topic' do - topic = Topic.create! valid_attributes expect do - delete :destroy, { id: topic.to_param }, valid_session + delete :destroy, { id: topic.to_param } end.to change(Topic, :count).by(-1) end it 'redirects to the topics list' do - topic = Topic.create! valid_attributes - delete :destroy, { id: topic.to_param }, valid_session + delete :destroy, { id: topic.to_param } expect(response).to redirect_to(topics_url) end end From 451ed81010f8be04eedd854380cf3c1606f97d0c Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 8 Feb 2016 12:00:38 +0800 Subject: [PATCH 10/39] remove tests that shouldn't be there --- spec/controllers/maps_controller_spec.rb | 18 ------------- spec/controllers/metacodes_controller_spec.rb | 20 --------------- spec/controllers/synapses_controller_spec.rb | 25 ------------------- spec/controllers/topics_controller_spec.rb | 25 ------------------- 4 files changed, 88 deletions(-) diff --git a/spec/controllers/maps_controller_spec.rb b/spec/controllers/maps_controller_spec.rb index 3a8d3f0b..7c7a0499 100644 --- a/spec/controllers/maps_controller_spec.rb +++ b/spec/controllers/maps_controller_spec.rb @@ -22,13 +22,6 @@ RSpec.describe MapsController, type: :controller do end end - describe 'GET #edit' do - it 'assigns the requested map as @map' do - get :edit, { id: map.to_param } - expect(assigns(:map)).to eq(map) - end - end - describe 'POST #create' do context 'with valid params' do it 'creates a new Map' do @@ -54,11 +47,6 @@ RSpec.describe MapsController, type: :controller do post :create, { map: invalid_attributes } expect(assigns(:map)).to be_a_new(Map) end - - it "re-renders the 'new' template" do - post :create, { map: invalid_attributes } - expect(response).to render_template('new') - end end end @@ -94,12 +82,6 @@ RSpec.describe MapsController, type: :controller do { id: map.to_param, map: invalid_attributes } expect(assigns(:map)).to eq(map) end - - it "re-renders the 'edit' template" do - put :update, - { id: map.to_param, map: invalid_attributes } - expect(response).to render_template('edit') - end end end diff --git a/spec/controllers/metacodes_controller_spec.rb b/spec/controllers/metacodes_controller_spec.rb index 5f9a148e..b0b2a0ff 100644 --- a/spec/controllers/metacodes_controller_spec.rb +++ b/spec/controllers/metacodes_controller_spec.rb @@ -15,13 +15,6 @@ RSpec.describe MetacodesController, type: :controller do end end - describe 'GET #show' do - it 'assigns the requested metacode as @metacode' do - get :show, { id: metacode.to_param } - expect(assigns(:metacode)).to eq(metacode) - end - end - describe 'GET #new' do it 'assigns a new metacode as @metacode' do get :new, {} @@ -109,17 +102,4 @@ RSpec.describe MetacodesController, type: :controller do end end end - - describe 'DELETE #destroy' do - it 'destroys the requested metacode' do - expect do - delete :destroy, { id: metacode.to_param } - end.to change(Metacode, :count).by(-1) - end - - it 'redirects to the metacodes list' do - delete :destroy, { id: metacode.to_param } - expect(response).to redirect_to(metacodes_url) - end - end end diff --git a/spec/controllers/synapses_controller_spec.rb b/spec/controllers/synapses_controller_spec.rb index 90d70e8d..9b7471ab 100644 --- a/spec/controllers/synapses_controller_spec.rb +++ b/spec/controllers/synapses_controller_spec.rb @@ -8,13 +8,6 @@ RSpec.describe SynapsesController, type: :controller do sign_in end - describe 'GET #index' do - it 'assigns all synapses as @synapses' do - get :index, {} - expect(assigns(:synapses)).to eq([synapse]) - end - end - describe 'GET #show' do it 'assigns the requested synapse as @synapse' do get :show, { id: synapse.to_param } @@ -22,13 +15,6 @@ RSpec.describe SynapsesController, type: :controller do end end - describe 'GET #edit' do - it 'assigns the requested synapse as @synapse' do - get :edit, { id: synapse.to_param } - expect(assigns(:synapse)).to eq(synapse) - end - end - describe 'POST #create' do context 'with valid params' do it 'creates a new Synapse' do @@ -54,11 +40,6 @@ RSpec.describe SynapsesController, type: :controller do post :create, { synapse: invalid_attributes } expect(assigns(:synapse)).to be_a_new(Synapse) end - - it "re-renders the 'new' template" do - post :create, { synapse: invalid_attributes } - expect(response).to render_template('new') - end end end @@ -94,12 +75,6 @@ RSpec.describe SynapsesController, type: :controller do { id: synapse.to_param, synapse: invalid_attributes } expect(assigns(:synapse)).to eq(synapse) end - - it "re-renders the 'edit' template" do - put :update, - { id: synapse.to_param, synapse: invalid_attributes } - expect(response).to render_template('edit') - end end end diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index 5191c2fe..51610d33 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -8,13 +8,6 @@ RSpec.describe TopicsController, type: :controller do sign_in end - describe 'GET #index' do - it 'assigns all topics as @topics' do - get :index, {} - expect(assigns(:topics)).to eq([topic]) - end - end - describe 'GET #show' do it 'assigns the requested topic as @topic' do get :show, { id: topic.to_param } @@ -22,13 +15,6 @@ RSpec.describe TopicsController, type: :controller do end end - describe 'GET #edit' do - it 'assigns the requested topic as @topic' do - get :edit, { id: topic.to_param } - expect(assigns(:topic)).to eq(topic) - end - end - describe 'POST #create' do context 'with valid params' do it 'creates a new Topic' do @@ -54,11 +40,6 @@ RSpec.describe TopicsController, type: :controller do post :create, { topic: invalid_attributes } expect(assigns(:topic)).to be_a_new(Topic) end - - it "re-renders the 'new' template" do - post :create, { topic: invalid_attributes } - expect(response).to render_template('new') - end end end @@ -94,12 +75,6 @@ RSpec.describe TopicsController, type: :controller do { id: topic.to_param, topic: invalid_attributes } expect(assigns(:topic)).to eq(topic) end - - it "re-renders the 'edit' template" do - put :update, - { id: topic.to_param, topic: invalid_attributes } - expect(response).to render_template('edit') - end end end From 0b98e446ca0ce3be4a84ac5987b9ab986b7f099d Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 9 Feb 2016 11:20:04 +0800 Subject: [PATCH 11/39] fiddle with maps_controller code style --- app/controllers/maps_controller.rb | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index add8a0c1..05123fdb 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -1,5 +1,4 @@ class MapsController < ApplicationController - before_filter :require_user, only: [:create, :update, :screenshot, :destroy] respond_to :html, :json @@ -10,38 +9,24 @@ class MapsController < ApplicationController # GET /explore/featured # GET /explore/mapper/:id def index - - if request.path == "/explore" - redirect_to activemaps_url and return - end + return redirect_to activemaps_url if request.path == "/explore" @current = current_user - @user = nil @maps = [] - @mapperId = nil - - if !params[:page] - page = 1 - else - page = params[:page] - end + page = params[:page].present ? params[:page] : 1 if request.path.index("/explore/active") != nil @maps = Map.where("maps.permission != ?", "private").order("updated_at DESC").page(page).per(20) @request = "active" - elsif request.path.index("/explore/featured") != nil @maps = Map.where("maps.featured = ? AND maps.permission != ?", true, "private").order("updated_at DESC").page(page).per(20) @request = "featured" - elsif request.path.index('/explore/mine') != nil # looking for maps by me - if !authenticated? - redirect_to activemaps_url and return - end + return redirect_to activemaps_url if !authenticated? + # don't need to exclude private maps because they all belong to you @maps = Map.where("maps.user_id = ?", @current.id).order("updated_at DESC").page(page).per(20) @request = "you" - elsif request.path.index('/explore/mapper/') != nil # looking for maps by a mapper @user = User.find(params[:id]) @maps = Map.where("maps.user_id = ? AND maps.permission != ?", @user.id, "private").order("updated_at DESC").page(page).per(20) From 7956e6d289f3dbb60b175a099b1f62346523a299 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 9 Feb 2016 11:20:27 +0800 Subject: [PATCH 12/39] check map#contains matches json schema in spec --- Gemfile | 1 + Gemfile.lock | 4 +++ spec/controllers/maps_controller_spec.rb | 8 +++++ spec/schemas/map.json | 0 spec/schemas/map_contains.json | 42 ++++++++++++++++++++++++ spec/support/schema_matcher.rb | 7 ++++ 6 files changed, 62 insertions(+) create mode 100644 spec/schemas/map.json create mode 100644 spec/schemas/map_contains.json create mode 100644 spec/support/schema_matcher.rb diff --git a/Gemfile b/Gemfile index b8872752..8379a7db 100644 --- a/Gemfile +++ b/Gemfile @@ -43,6 +43,7 @@ group :test do gem 'factory_girl_rails' gem 'shoulda-matchers' gem 'simplecov', require: false + gem 'json-schema' end group :production do #this is used on heroku diff --git a/Gemfile.lock b/Gemfile.lock index 710f5f10..3a5f1b41 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,6 +36,7 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + addressable (2.3.8) arel (6.0.3) aws-sdk (1.66.0) aws-sdk-v1 (= 1.66.0) @@ -105,6 +106,8 @@ GEM jquery-ui-rails (5.0.5) railties (>= 3.2.16) json (1.8.3) + json-schema (2.6.0) + addressable (~> 2.3.8) kaminari (0.16.3) actionpack (>= 3.0.0) activesupport (>= 3.0.0) @@ -251,6 +254,7 @@ DEPENDENCIES jquery-rails jquery-ui-rails json + json-schema kaminari paperclip pg diff --git a/spec/controllers/maps_controller_spec.rb b/spec/controllers/maps_controller_spec.rb index 7c7a0499..74a03b7d 100644 --- a/spec/controllers/maps_controller_spec.rb +++ b/spec/controllers/maps_controller_spec.rb @@ -15,6 +15,14 @@ RSpec.describe MapsController, type: :controller do end end + describe 'GET #contains' do + it 'returns json matching schema' do + get :contains, { id: map.to_param, format: :json } + # get "maps/#{map.id}/contains" + 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 } diff --git a/spec/schemas/map.json b/spec/schemas/map.json new file mode 100644 index 00000000..e69de29b diff --git a/spec/schemas/map_contains.json b/spec/schemas/map_contains.json new file mode 100644 index 00000000..0b4faebf --- /dev/null +++ b/spec/schemas/map_contains.json @@ -0,0 +1,42 @@ +{ + "name": "Map Contents", + "type": "object", + "properties": { + "map": { + "type": "object" + }, + "topics": { + "type": "array", + "items": { + "type": "object" + } + }, + "synapses": { + "type": "array", + "items": { + "type": "object" + } + }, + "mappings": { + "type": "array", + "items": { + "type": "object" + } + }, + "mappers": { + "type": "array", + "items": { + "type": "object" + } + } + }, + "required": [ + "map", + "topics", + "synapses", + "mappings", + "mappers" + ] +} + + diff --git a/spec/support/schema_matcher.rb b/spec/support/schema_matcher.rb new file mode 100644 index 00000000..b2a89352 --- /dev/null +++ b/spec/support/schema_matcher.rb @@ -0,0 +1,7 @@ +RSpec::Matchers.define :match_json_schema do |schema| + match do |json| + schema_directory = Rails.root.join('spec', 'schemas').to_s + schema_path = "#{schema_directory}/#{schema}.json" + JSON::Validator.validate!(schema_path, json) + end +end From 005250f330797f34c4941d1b14a2214f61089d26 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 9 Feb 2016 11:26:42 +0800 Subject: [PATCH 13/39] typo --- app/controllers/maps_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 05123fdb..5be69133 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -13,7 +13,7 @@ class MapsController < ApplicationController @current = current_user @maps = [] - page = params[:page].present ? params[:page] : 1 + page = params[:page].present? ? params[:page] : 1 if request.path.index("/explore/active") != nil @maps = Map.where("maps.permission != ?", "private").order("updated_at DESC").page(page).per(20) From 374ac701c9b9b8efc7f98bdb8fee3dba27ad6e61 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 9 Feb 2016 11:33:43 +0800 Subject: [PATCH 14/39] filling out map controller spec --- spec/controllers/maps_controller_spec.rb | 49 +++++++++++++++--------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/spec/controllers/maps_controller_spec.rb b/spec/controllers/maps_controller_spec.rb index 74a03b7d..c5379b93 100644 --- a/spec/controllers/maps_controller_spec.rb +++ b/spec/controllers/maps_controller_spec.rb @@ -9,7 +9,7 @@ RSpec.describe MapsController, type: :controller do end describe 'GET #index' do - it 'assigns all maps as @maps' do + it 'viewable maps as @maps' do get :index, {} expect(assigns(:maps)).to eq([map]) end @@ -18,7 +18,6 @@ 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 "maps/#{map.id}/contains" expect(response.body).to match_json_schema(:map_contains) end end @@ -66,43 +65,55 @@ RSpec.describe MapsController, type: :controller do it 'updates the requested map' do put :update, - { id: map.to_param, map: new_attributes } + { id: map.to_param, map: new_attributes, format: :json } map.reload skip('Add assertions for updated state') end it 'assigns the requested map as @map' do put :update, - { id: map.to_param, map: valid_attributes } + { id: map.to_param, map: valid_attributes, format: :json } expect(assigns(:map)).to eq(map) end - - it 'redirects to the map' do - put :update, - { id: map.to_param, map: valid_attributes } - expect(response).to redirect_to(map) - end end context 'with invalid params' do it 'assigns the map as @map' do put :update, - { id: map.to_param, map: invalid_attributes } + { id: map.to_param, map: invalid_attributes, format: :json } expect(assigns(:map)).to eq(map) end end end - describe 'DELETE #destroy' do - it 'destroys the requested map' do - expect do - delete :destroy, { id: map.to_param } - end.to change(Map, :count).by(-1) + describe 'update the map screenshot' do + it 'successfully if authorized' do + skip end - it 'redirects to the maps list' do - delete :destroy, { id: map.to_param } - expect(response).to redirect_to(maps_url) + it 'unsucessfully if not authorized' do + skip + end + end + + describe 'DELETE #destroy' do + let(:unowned_map) { create(:map) } + let(:owned_map) { create(:map, user: controller.current_user) } + + it 'prevents deletion by non-owners' do + unowned_map.reload + expect do + delete :destroy, { id: unowned_map.to_param, format: :json } + end.to change(Map, :count).by(0) + expect(response.body).to eq("unauthorized") + end + + 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 } + end.to change(Map, :count).by(-1) + expect(response.body).to eq("success") end end end From 43bdda61de5bd6b289743a459c0b8931b85810ae Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 9 Feb 2016 11:48:07 +0800 Subject: [PATCH 15/39] maps controller spec passes, 3 pending --- app/controllers/maps_controller.rb | 36 +++++++++++++----------- app/models/map.rb | 20 ++++++------- spec/controllers/maps_controller_spec.rb | 12 +++----- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 5be69133..9ad05810 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -102,7 +102,6 @@ class MapsController < ApplicationController # POST maps def create - @user = current_user @map = Map.new() @map.name = params[:name] @@ -110,40 +109,45 @@ class MapsController < ApplicationController @map.permission = params[:permission] @map.user = @user @map.arranged = false - @map.save if params[:topicsToMap] @all = params[:topicsToMap] @all = @all.split(',') @all.each do |topic| topic = topic.split('/') - @mapping = Mapping.new() - @mapping.user = @user - @mapping.map = @map - @mapping.mappable = Topic.find(topic[0]) - @mapping.xloc = topic[1] - @mapping.yloc = topic[2] - @mapping.save + mapping = Mapping.new() + mapping.user = @user + mapping.mappable = Topic.find(topic[0]) + mapping.xloc = topic[1] + mapping.yloc = topic[2] + @map.topicmappings << mapping + mapping.save end if params[:synapsesToMap] @synAll = params[:synapsesToMap] @synAll = @synAll.split(',') @synAll.each do |synapse_id| - @mapping = Mapping.new() - @mapping.user = @user - @mapping.map = @map - @mapping.mappable = Synapse.find(synapse_id) - @mapping.save + mapping = Mapping.new() + mapping.user = @user + mapping.map = @map + mapping.mappable = Synapse.find(synapse_id) + @map.synapsemappings << mapping + mapping.save end end @map.arranged = true - @map.save end - respond_to do |format| + 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 end diff --git a/app/models/map.rb b/app/models/map.rb index 87019d2a..6c2caca2 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -41,41 +41,41 @@ class Map < ActiveRecord::Base end def topic_count - self.topics.length + topics.length end def synapse_count - self.synapses.length + synapses.length end def user_name - self.user.name + user.name end def user_image - self.user.image.url + user.image.url end def contributor_count - self.contributors.length + contributors.length end def screenshot_url - self.screenshot.url(:thumb) + screenshot.url(:thumb) end def created_at_str - self.created_at.strftime("%m/%d/%Y") + created_at.strftime("%m/%d/%Y") end def updated_at_str - self.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, :screenshot_url], :except => [:screenshot_content_type, :screenshot_file_size, :screenshot_file_name, :screenshot_updated_at]) - json[:created_at_clean] = self.created_at_str - json[:updated_at_clean] = self.updated_at_str + json[:created_at_clean] = created_at_str + json[:updated_at_clean] = updated_at_str json end diff --git a/spec/controllers/maps_controller_spec.rb b/spec/controllers/maps_controller_spec.rb index c5379b93..4c85f9b1 100644 --- a/spec/controllers/maps_controller_spec.rb +++ b/spec/controllers/maps_controller_spec.rb @@ -32,26 +32,22 @@ RSpec.describe MapsController, type: :controller do describe 'POST #create' do context 'with valid params' do it 'creates a new Map' do + map.reload expect do - post :create, { map: valid_attributes } + post :create, valid_attributes.merge(format: :json) end.to change(Map, :count).by(1) end it 'assigns a newly created map as @map' do - post :create, { map: valid_attributes } + post :create, valid_attributes.merge(format: :json) expect(assigns(:map)).to be_a(Map) expect(assigns(:map)).to be_persisted end - - it 'redirects to the created map' do - post :create, { map: valid_attributes } - expect(response).to redirect_to(Map.last) - end end context 'with invalid params' do it 'assigns a newly created but unsaved map as @map' do - post :create, { map: invalid_attributes } + post :create, invalid_attributes.merge(format: :json) expect(assigns(:map)).to be_a_new(Map) end end From f3f8bfbea8fe418786a61db87703b946e1af5e15 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 9 Feb 2016 11:59:04 +0800 Subject: [PATCH 16/39] remove map screenshot tests for now. maps controller spec passes --- spec/controllers/maps_controller_spec.rb | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/spec/controllers/maps_controller_spec.rb b/spec/controllers/maps_controller_spec.rb index 4c85f9b1..b2f0abec 100644 --- a/spec/controllers/maps_controller_spec.rb +++ b/spec/controllers/maps_controller_spec.rb @@ -55,15 +55,13 @@ RSpec.describe MapsController, type: :controller do describe 'PUT #update' do context 'with valid params' do - let(:new_attributes) do - skip('Add a hash of attributes valid for your model') - end + 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 } - map.reload - skip('Add assertions for updated state') + expect(assigns(:map).name).to eq "Uncool map" + expect(assigns(:map).permission).to eq 'private' end it 'assigns the requested map as @map' do @@ -82,16 +80,6 @@ RSpec.describe MapsController, type: :controller do end end - describe 'update the map screenshot' do - it 'successfully if authorized' do - skip - end - - it 'unsucessfully if not authorized' do - skip - end - end - describe 'DELETE #destroy' do let(:unowned_map) { create(:map) } let(:owned_map) { create(:map, user: controller.current_user) } From 6d0dcec1ba819e9436bb782bf0c7575ef31e52e6 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 9 Feb 2016 12:43:34 +0800 Subject: [PATCH 17/39] mess with metacode tests --- app/controllers/metacodes_controller.rb | 42 ++++--------------- spec/controllers/metacodes_controller_spec.rb | 12 ++---- 2 files changed, 11 insertions(+), 43 deletions(-) diff --git a/app/controllers/metacodes_controller.rb b/app/controllers/metacodes_controller.rb index 5d1e1367..f026c58a 100644 --- a/app/controllers/metacodes_controller.rb +++ b/app/controllers/metacodes_controller.rb @@ -15,24 +15,12 @@ class MetacodesController < ApplicationController redirect_to root_url, notice: "You need to be an admin for that." return false end - render action: "index" + render :index } format.json { render json: @metacodes } end end - ### SHOW IS CURRENTLY DISABLED - # GET /metacodes/1 - # GET /metacodes/1.json -# def show -# @metacode = Metacode.find(params[:id]) -# -# respond_to do |format| -# format.html # show.html.erb -# format.json { render json: @metacode } -# end -# end - # GET /metacodes/new # GET /metacodes/new.json def new @@ -59,7 +47,7 @@ class MetacodesController < ApplicationController format.html { redirect_to metacodes_url, notice: 'Metacode was successfully created.' } format.json { render json: @metacode, status: :created, location: metacodes_url } else - format.html { render action: "new" } + format.html { render :new } format.json { render json: @metacode.errors, status: :unprocessable_entity } end end @@ -71,34 +59,20 @@ class MetacodesController < ApplicationController @metacode = Metacode.find(params[:id]) respond_to do |format| - if @metacode.update_attributes(metacode_params) + if @metacode.update(metacode_params) format.html { redirect_to metacodes_url, notice: 'Metacode was successfully updated.' } format.json { head :no_content } else - format.html { render action: "edit" } + format.html { render :edit } format.json { render json: @metacode.errors, status: :unprocessable_entity } end end end - - ### DESTROY IS CURRENTLY DISABLED - # DELETE /metacodes/1 - # DELETE /metacodes/1.json -# def destroy -# @metacode = Metacode.find(params[:id]) -# @metacode.destroy -# -# respond_to do |format| -# format.html { redirect_to metacodes_url } -# format.json { head :no_content } -# end -# end - private - # Never trust parameters from the scary internet, only allow the white list through. - def metacode_params - params.require(:metacode).permit(:id, :name, :icon, :color) - end + # Never trust parameters from the scary internet, only allow the white list through. + def metacode_params + params.require(:metacode).permit(:id, :name, :icon, :color) + end end diff --git a/spec/controllers/metacodes_controller_spec.rb b/spec/controllers/metacodes_controller_spec.rb index b0b2a0ff..d8edcbf0 100644 --- a/spec/controllers/metacodes_controller_spec.rb +++ b/spec/controllers/metacodes_controller_spec.rb @@ -11,7 +11,7 @@ RSpec.describe MetacodesController, type: :controller do describe 'GET #index' do it 'assigns all metacodes as @metacodes' do get :index, {} - expect(assigns(:metacodes)).to eq([metacode]) + expect(assigns(:metacodes).to_a).to eq([metacode]) end end @@ -89,16 +89,10 @@ RSpec.describe MetacodesController, type: :controller do end context 'with invalid params' do - it 'assigns the metacode as @metacode' do + it 'redirects to edit template' do put :update, { id: metacode.to_param, metacode: invalid_attributes } - expect(assigns(:metacode)).to eq(metacode) - end - - it "re-renders the 'edit' template" do - put :update, - { id: metacode.to_param, metacode: invalid_attributes } - expect(response).to render_template('edit') + expect(response.status).to eq 302 end end end From 7f50db1ae93df33e94b1ebe17aab91105416ecaa Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 9 Feb 2016 13:30:49 +0800 Subject: [PATCH 18/39] ok metacode spec done --- app/models/metacode.rb | 1 - spec/controllers/metacodes_controller_spec.rb | 72 ++++++++----------- spec/factories/metacodes.rb | 3 + 3 files changed, 33 insertions(+), 43 deletions(-) diff --git a/app/models/metacode.rb b/app/models/metacode.rb index 03b0f0c0..aa8f9104 100644 --- a/app/models/metacode.rb +++ b/app/models/metacode.rb @@ -1,5 +1,4 @@ class Metacode < ActiveRecord::Base - has_many :in_metacode_sets has_many :metacode_sets, :through => :in_metacode_sets has_many :topics diff --git a/spec/controllers/metacodes_controller_spec.rb b/spec/controllers/metacodes_controller_spec.rb index d8edcbf0..d950e77d 100644 --- a/spec/controllers/metacodes_controller_spec.rb +++ b/spec/controllers/metacodes_controller_spec.rb @@ -2,22 +2,22 @@ require 'rails_helper' RSpec.describe MetacodesController, type: :controller do let(:metacode) { create(:metacode) } - let(:valid_attributes) { metacode.attributes.except(:id) } - let(:invalid_attributes) { { permission: :commons } } + let(:valid_attributes) { metacode.attributes.except('id') } before :each do - sign_in + sign_in create(:user, admin: true) end describe 'GET #index' do it 'assigns all metacodes as @metacodes' do + metacode.reload # ensure it's created get :index, {} - expect(assigns(:metacodes).to_a).to eq([metacode]) + expect(Metacode.all.to_a).to eq([metacode]) end end describe 'GET #new' do it 'assigns a new metacode as @metacode' do - get :new, {} + get :new, { format: :json } expect(assigns(:metacode)).to be_a_new(Metacode) end end @@ -32,32 +32,22 @@ RSpec.describe MetacodesController, type: :controller do describe 'POST #create' do context 'with valid params' do it 'creates a new Metacode' do + metacode.reload # ensure it's present to start expect do post :create, { metacode: valid_attributes } end.to change(Metacode, :count).by(1) end - it 'assigns a newly created metacode as @metacode' do + it 'has the correct attributes' do 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 created metacode' do + it 'redirects to the metacode index' do post :create, { metacode: valid_attributes } - expect(response).to redirect_to(Metacode.last) - end - end - - context 'with invalid params' do - it 'assigns a newly created but unsaved metacode as @metacode' do - post :create, { metacode: invalid_attributes } - expect(assigns(:metacode)).to be_a_new(Metacode) - end - - it "re-renders the 'new' template" do - post :create, { metacode: invalid_attributes } - expect(response).to render_template('new') + expect(response).to redirect_to(metacodes_url) end end end @@ -65,35 +55,33 @@ RSpec.describe MetacodesController, type: :controller do describe 'PUT #update' do context 'with valid params' do let(:new_attributes) do - skip('Add a hash of attributes valid for your model') + { icon: 'https://newimages.ca/cool-image.jpg', + color: '#ffffff', + name: 'Cognition' } end it 'updates the requested metacode' do put :update, { id: metacode.to_param, metacode: new_attributes } metacode.reload - skip('Add assertions for updated state') - end - - it 'assigns the requested metacode as @metacode' do - put :update, - { id: metacode.to_param, metacode: valid_attributes } - expect(assigns(:metacode)).to eq(metacode) - end - - it 'redirects to the metacode' do - put :update, - { id: metacode.to_param, metacode: valid_attributes } - expect(response).to redirect_to(metacode) - end - end - - context 'with invalid params' do - it 'redirects to edit template' do - put :update, - { id: metacode.to_param, metacode: invalid_attributes } - expect(response.status).to eq 302 + expect(metacode.icon).to eq 'https://newimages.ca/cool-image.jpg' + expect(metacode.color).to eq '#ffffff' + expect(metacode.name).to eq 'Cognition' end end end + + context 'not admin' do + it 'denies access to create' do + sign_in create(:user, admin: false) + 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 } + expect(response).to redirect_to root_url + end + end end diff --git a/spec/factories/metacodes.rb b/spec/factories/metacodes.rb index 5cfb38f6..eb040e09 100644 --- a/spec/factories/metacodes.rb +++ b/spec/factories/metacodes.rb @@ -1,4 +1,7 @@ FactoryGirl.define do factory :metacode do + sequence(:name) { |n| "Cool Metacode ##{n}" } + icon 'https://images.com/image.png' + color '#cccccc' end end From 0c81c8d9de30022238a05ccaab2ab00374373a75 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 9 Feb 2016 13:42:24 +0800 Subject: [PATCH 19/39] topics controller spec --- spec/controllers/topics_controller_spec.rb | 51 +++++++++++++--------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index 51610d33..2dd999a1 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -2,15 +2,15 @@ require 'rails_helper' RSpec.describe TopicsController, type: :controller do let(:topic) { create(:topic) } - let(:valid_attributes) { topic.attributes.except(:id) } - let(:invalid_attributes) { { permission: :commons } } + let(:valid_attributes) { topic.attributes.except('id') } + let(:invalid_attributes) { { permission: :invalid_lol } } before :each do sign_in end describe 'GET #show' do it 'assigns the requested topic as @topic' do - get :show, { id: topic.to_param } + get :show, { id: topic.to_param, format: :json } expect(assigns(:topic)).to eq(topic) end end @@ -18,26 +18,27 @@ RSpec.describe TopicsController, type: :controller do describe 'POST #create' do context 'with valid params' do it 'creates a new Topic' do + topic.reload # ensure it's created expect do - post :create, { topic: valid_attributes } + 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 } + post :create, { topic: valid_attributes, format: :json } expect(assigns(:topic)).to be_a(Topic) expect(assigns(:topic)).to be_persisted end - it 'redirects to the created topic' do - post :create, { topic: valid_attributes } - expect(response).to redirect_to(Topic.last) + 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 } + post :create, { topic: invalid_attributes, format: :json } expect(assigns(:topic)).to be_a_new(Topic) end end @@ -46,48 +47,56 @@ RSpec.describe TopicsController, type: :controller do describe 'PUT #update' do context 'with valid params' do let(:new_attributes) do - skip('Add a hash of attributes valid for your model') + { name: 'Cool Topic with no number', + desc: 'This is a cool topic.', + link: 'https://cool-topics.com/4', + permission: :public } end it 'updates the requested topic' do put :update, - { id: topic.to_param, topic: new_attributes } + { id: topic.to_param, topic: new_attributes, format: :json } topic.reload - skip('Add assertions for updated state') + expect(topic.name).to eq 'Cool Topic with no number' + expect(topic.desc).to eq 'This is a cool topic.' + expect(topic.link).to eq 'https://cool-topics.com/4' + expect(topic.permission).to eq 'public' end it 'assigns the requested topic as @topic' do put :update, - { id: topic.to_param, topic: valid_attributes } + { id: topic.to_param, topic: valid_attributes, format: :json } expect(assigns(:topic)).to eq(topic) end - it 'redirects to the topic' do + it 'returns status of no content' do put :update, - { id: topic.to_param, topic: valid_attributes } - expect(response).to redirect_to(topic) + { id: topic.to_param, topic: valid_attributes, format: :json } + expect(response.status).to eq 204 end end context 'with invalid params' do it 'assigns the topic as @topic' do put :update, - { id: topic.to_param, topic: invalid_attributes } + { id: topic.to_param, topic: invalid_attributes, format: :json } expect(assigns(:topic)).to eq(topic) end end end describe 'DELETE #destroy' do + let(:owned_topic) { create(:topic, user: controller.current_user) } it 'destroys the requested topic' do + owned_topic.reload # ensure it's there expect do - delete :destroy, { id: topic.to_param } + delete :destroy, { id: owned_topic.to_param, format: :json } end.to change(Topic, :count).by(-1) end - it 'redirects to the topics list' do - delete :destroy, { id: topic.to_param } - expect(response).to redirect_to(topics_url) + it 'return 204 NO CONTENT' do + delete :destroy, { id: topic.to_param, format: :json } + expect(response.status).to eq 204 end end end From f9bcd3334419755e8e494f68f40a31157cf63296 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 9 Feb 2016 14:25:39 +0800 Subject: [PATCH 20/39] update synapses specs; all specs pass again. all models/controllers tested --- app/models/synapse.rb | 7 ++- spec/controllers/synapses_controller_spec.rb | 58 ++++++++++---------- spec/factories/synapses.rb | 3 +- spec/models/synapse_spec.rb | 1 + 4 files changed, 37 insertions(+), 32 deletions(-) diff --git a/app/models/synapse.rb b/app/models/synapse.rb index 0b40da02..ea5889cc 100644 --- a/app/models/synapse.rb +++ b/app/models/synapse.rb @@ -1,5 +1,4 @@ class Synapse < ActiveRecord::Base - belongs_to :user belongs_to :topic1, :class_name => "Topic", :foreign_key => "node1_id" @@ -13,15 +12,17 @@ class Synapse < ActiveRecord::Base validates :permission, presence: true validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) } + validates :category, inclusion: { in: ['from-to', 'both'], allow_nil: true } + # :nocov: def user_name - self.user.name + user.name end # :nocov: # :nocov: def user_image - self.user.image.url + user.image.url end # :nocov: diff --git a/spec/controllers/synapses_controller_spec.rb b/spec/controllers/synapses_controller_spec.rb index 9b7471ab..478ee6ed 100644 --- a/spec/controllers/synapses_controller_spec.rb +++ b/spec/controllers/synapses_controller_spec.rb @@ -2,15 +2,15 @@ require 'rails_helper' RSpec.describe SynapsesController, type: :controller do let(:synapse) { create(:synapse) } - let(:valid_attributes) { synapse.attributes.except(:id) } - let(:invalid_attributes) { { permission: :commons } } + let(:valid_attributes) { synapse.attributes.except('id') } + 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 } + get :show, { id: synapse.to_param, format: :json } expect(assigns(:synapse)).to eq(synapse) end end @@ -18,27 +18,28 @@ RSpec.describe SynapsesController, type: :controller do describe 'POST #create' do context 'with valid params' do it 'creates a new Synapse' do + synapse.reload # ensure it's present expect do - post :create, { synapse: valid_attributes } + 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 } + post :create, { synapse: valid_attributes, format: :json } expect(assigns(:synapse)).to be_a(Synapse) expect(assigns(:synapse)).to be_persisted end - it 'redirects to the created synapse' do - post :create, { synapse: valid_attributes } - expect(response).to redirect_to(Synapse.last) + it 'returns 201 CREATED' do + post :create, { synapse: valid_attributes, format: :json } + expect(response.status).to eq 201 end end context 'with invalid params' do - it 'assigns a newly created but unsaved synapse as @synapse' do - post :create, { synapse: invalid_attributes } - expect(assigns(:synapse)).to be_a_new(Synapse) + it 'returns 422 UNPROCESSABLE ENTITY' do + post :create, { synapse: invalid_attributes, format: :json } + expect(response.status).to eq 422 end end end @@ -46,48 +47,49 @@ RSpec.describe SynapsesController, type: :controller do describe 'PUT #update' do context 'with valid params' do let(:new_attributes) do - skip('Add a hash of attributes valid for your model') + { desc: 'My new description', + category: 'both', + permission: :public } end it 'updates the requested synapse' do put :update, - { id: synapse.to_param, synapse: new_attributes } + { id: synapse.to_param, synapse: new_attributes, format: :json } synapse.reload - skip('Add assertions for updated state') + expect(synapse.desc).to eq 'My new description' + expect(synapse.category).to eq 'both' + expect(synapse.permission).to eq 'public' end - it 'assigns the requested synapse as @synapse' do + it 'returns 204 NO CONTENT' do put :update, - { id: synapse.to_param, synapse: valid_attributes } - expect(assigns(:synapse)).to eq(synapse) - end - - it 'redirects to the synapse' do - put :update, - { id: synapse.to_param, synapse: valid_attributes } - expect(response).to redirect_to(synapse) + { id: synapse.to_param, synapse: valid_attributes, format: :json } + expect(response.status).to eq 204 end end context 'with invalid params' do it 'assigns the synapse as @synapse' do put :update, - { id: synapse.to_param, synapse: invalid_attributes } + { id: synapse.to_param, synapse: invalid_attributes, format: :json } expect(assigns(:synapse)).to eq(synapse) end end end describe 'DELETE #destroy' do + let(:synapse) { create(:synapse, user: controller.current_user) } + it 'destroys the requested synapse' do + synapse.reload # ensure it's present expect do - delete :destroy, { id: synapse.to_param } + delete :destroy, { id: synapse.to_param, format: :json } end.to change(Synapse, :count).by(-1) end - it 'redirects to the synapses list' do - delete :destroy, { id: synapse.to_param } - expect(response).to redirect_to(synapses_url) + it 'returns 204 NO CONTENT' do + delete :destroy, { id: synapse.to_param, format: :json } + expect(response.status).to eq 204 end end end diff --git a/spec/factories/synapses.rb b/spec/factories/synapses.rb index b83a0073..4454a7a4 100644 --- a/spec/factories/synapses.rb +++ b/spec/factories/synapses.rb @@ -1,9 +1,10 @@ FactoryGirl.define do factory :synapse do sequence(:desc) { |n| "Cool synapse ##{n}" } - category :to + category :'from-to' permission :commons association :topic1, factory: :topic association :topic2, factory: :topic + user end end diff --git a/spec/models/synapse_spec.rb b/spec/models/synapse_spec.rb index a1069805..dcf85358 100644 --- a/spec/models/synapse_spec.rb +++ b/spec/models/synapse_spec.rb @@ -8,6 +8,7 @@ RSpec.describe Synapse, type: :model do it { is_expected.to have_many :mappings } 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 context 'permissions' do From 48863ce24633703f430a3745c7f4011411de353e Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 2 Mar 2015 18:05:45 -0500 Subject: [PATCH 21/39] create synapse if you click away from the synapse title form --- app/assets/javascripts/src/Metamaps.JIT.js.erb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/src/Metamaps.JIT.js.erb b/app/assets/javascripts/src/Metamaps.JIT.js.erb index c34fcb6b..6cd0fa88 100644 --- a/app/assets/javascripts/src/Metamaps.JIT.js.erb +++ b/app/assets/javascripts/src/Metamaps.JIT.js.erb @@ -1047,7 +1047,11 @@ Metamaps.JIT = { Metamaps.TopicCard.hideCard(); Metamaps.SynapseCard.hideCard(); Metamaps.Create.newTopic.hide(); - Metamaps.Create.newSynapse.hide(); + if ($('#new_synapse').is(":visible")) { + // Hide the new_synapse form and create the synapse! + Metamaps.Synapse.createSynapseLocally(); + }//if + $('.rightclickmenu').remove(); // reset the draw synapse positions to false Metamaps.Mouse.synapseStartCoordinates = []; From 056ef2b5b64b9a95a6cb3fa8a075cf7181ecdab9 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 11 Feb 2016 14:54:00 +0800 Subject: [PATCH 22/39] smoother synapse creation with clicks/tabs --- app/assets/javascripts/src/Metamaps.js.erb | 16 +++++++++++----- app/controllers/synapses_controller.rb | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/src/Metamaps.js.erb b/app/assets/javascripts/src/Metamaps.js.erb index 3f0e0ae3..fb636f11 100644 --- a/app/assets/javascripts/src/Metamaps.js.erb +++ b/app/assets/javascripts/src/Metamaps.js.erb @@ -736,10 +736,6 @@ Metamaps.Create = { init: function () { var self = Metamaps.Create.newSynapse; - $('#synapse_desc').keyup(function () { - Metamaps.Create.newSynapse.description = $(this).val(); - }); - var synapseBloodhound = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), queryTokenizer: Bloodhound.tokenizers.whitespace, @@ -795,6 +791,16 @@ Metamaps.Create = { }] ); + $('#synapse_desc').keyup(function () { + Metamaps.Create.newSynapse.description = $(this).val(); + }); + + $('#synapse_desc').focusout(function() { + // Metamaps.Create.newSynapse.description = $(this).val(); + Metamaps.Synapse.createSynapseLocally(); + }); + + $('#synapse_desc').bind('typeahead:select', function (event, datum, dataset) { if (datum.id) { // if they clicked on an existing synapse get it Metamaps.Synapse.getSynapseFromAutocomplete(datum.id); @@ -811,7 +817,7 @@ Metamaps.Create = { topic2id: null, newSynapseId: null, open: function () { - $('#new_synapse').fadeIn('fast', function () { + $('#new_synapse').fadeIn(100, function () { $('#synapse_desc').focus(); }); Metamaps.Create.newSynapse.beingCreated = true; diff --git a/app/controllers/synapses_controller.rb b/app/controllers/synapses_controller.rb index 2c3c08d0..f19dc053 100644 --- a/app/controllers/synapses_controller.rb +++ b/app/controllers/synapses_controller.rb @@ -22,7 +22,7 @@ class SynapsesController < ApplicationController # POST /synapses.json def create @synapse = Synapse.new(synapse_params) - @synapse.update_attribute :desc, "" if @synapse.desc.nil? + @synapse.desc = "" if @synapse.desc.nil? respond_to do |format| if @synapse.save @@ -37,7 +37,7 @@ class SynapsesController < ApplicationController # PUT /synapses/1.json def update @synapse = Synapse.find(params[:id]) - @synapse.update_attribute :desc, "" if @synapse.desc.nil? + @synapse.desc = "" if @synapse.desc.nil? respond_to do |format| if @synapse.update_attributes(synapse_params) From 9469b08ffa890fd4675d010230a6d0731396f6bd Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 12 Feb 2016 11:21:22 +0800 Subject: [PATCH 23/39] cancel synapse creation with esc, backspace, or delete --- app/assets/javascripts/src/Metamaps.js.erb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/src/Metamaps.js.erb b/app/assets/javascripts/src/Metamaps.js.erb index fb636f11..82b033ca 100644 --- a/app/assets/javascripts/src/Metamaps.js.erb +++ b/app/assets/javascripts/src/Metamaps.js.erb @@ -791,16 +791,22 @@ Metamaps.Create = { }] ); - $('#synapse_desc').keyup(function () { + $('#synapse_desc').keyup(function (e) { + var ESC = 27, BACKSPACE = 8, DELETE = 46; + if (e.keyCode === BACKSPACE && $(this).val() === "" || + e.keyCode === DELETE && $(this).val() === "" || + e.keyCode === ESC) { + Metamaps.Create.newSynapse.hide(); + }//if Metamaps.Create.newSynapse.description = $(this).val(); }); $('#synapse_desc').focusout(function() { - // Metamaps.Create.newSynapse.description = $(this).val(); - Metamaps.Synapse.createSynapseLocally(); + if (Metamaps.Create.newSynapse.beingCreated) { + Metamaps.Synapse.createSynapseLocally(); + } }); - $('#synapse_desc').bind('typeahead:select', function (event, datum, dataset) { if (datum.id) { // if they clicked on an existing synapse get it Metamaps.Synapse.getSynapseFromAutocomplete(datum.id); From dc1aa1e28e433c7f82427f921020a0a67e4f4c11 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 12 Feb 2016 15:08:24 +0800 Subject: [PATCH 24/39] document synapse cancellation in cheatsheet --- app/views/shared/_cheatsheet.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/shared/_cheatsheet.html.erb b/app/views/shared/_cheatsheet.html.erb index 1f57e6f9..c02246ac 100644 --- a/app/views/shared/_cheatsheet.html.erb +++ b/app/views/shared/_cheatsheet.html.erb @@ -76,7 +76,8 @@
Open 'Create Synapse' prompt: Right-click & drag from one topic to another
-
Enter: Create synapse
+
Enter or Tab: Create synapse
+
Esc or Delete: Cancel synapse creation
*You do not have to add a description
Create new Topic with Synapse: Right-click + drag from topic to open canvas
Enter: Create topic
From 9ff6375e62333be1fab70ba4ce3772980c62409f Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 12 Feb 2016 15:30:36 +0800 Subject: [PATCH 25/39] don't need to create synapse on canvas click --- app/assets/javascripts/src/Metamaps.JIT.js.erb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/assets/javascripts/src/Metamaps.JIT.js.erb b/app/assets/javascripts/src/Metamaps.JIT.js.erb index 6cd0fa88..4ccc63fa 100644 --- a/app/assets/javascripts/src/Metamaps.JIT.js.erb +++ b/app/assets/javascripts/src/Metamaps.JIT.js.erb @@ -1047,10 +1047,6 @@ Metamaps.JIT = { Metamaps.TopicCard.hideCard(); Metamaps.SynapseCard.hideCard(); Metamaps.Create.newTopic.hide(); - if ($('#new_synapse').is(":visible")) { - // Hide the new_synapse form and create the synapse! - Metamaps.Synapse.createSynapseLocally(); - }//if $('.rightclickmenu').remove(); // reset the draw synapse positions to false From d61b6c12808d8bc0febab9087470e31eb8a21aab Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 14 Feb 2016 14:02:53 +0800 Subject: [PATCH 26/39] smarter db creation. don't use db:reset or db:setup. This jenkins setup will load and migrate db without seeding. --- bin/jenkins-test.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/jenkins-test.sh b/bin/jenkins-test.sh index f9059d30..0afd3f66 100755 --- a/bin/jenkins-test.sh +++ b/bin/jenkins-test.sh @@ -21,5 +21,8 @@ sed -i -e "s/DB_USERNAME='.*'/DB_USERNAME='jenkins'/" .env #test bundle install -rake db:create db:test:prepare +rake db:drop +rake db:create +rake db:schema:load +rake db:migrate COVERAGE=on bundle exec rspec From affb1672aeea0e4b6ea3f79b2036206ef47b822f Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 18 Feb 2016 14:11:39 +0800 Subject: [PATCH 27/39] bite the bullet and link build icon to the jenkins job --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5cfd3a37..293265ac 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Metamaps ======= [![Join the chat at https://gitter.im/metamaps/metamaps_gen002](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/metamaps/metamaps_gen002?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -![Build Status](https://jenkins.devinhoward.ca/job/metamaps_gen002.develop/badge/icon) +[![Build Status](https://jenkins.devinhoward.ca/job/metamaps_gen002.develop/badge/icon)](https://jenkins.devinhoward.ca/job/metamaps_gen002.develop/) Welcome to the Metamaps GitHub repo. From 00c10c99d821ab5669cc04de245aed2d50632689 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 18 Feb 2016 14:25:47 +0800 Subject: [PATCH 28/39] remove phantom js --- script/phantomjs-save-screenshot.js | 57 ----------------------------- 1 file changed, 57 deletions(-) delete mode 100755 script/phantomjs-save-screenshot.js diff --git a/script/phantomjs-save-screenshot.js b/script/phantomjs-save-screenshot.js deleted file mode 100755 index 5ca47835..00000000 --- a/script/phantomjs-save-screenshot.js +++ /dev/null @@ -1,57 +0,0 @@ -//parse arguments passed from command line (or more likely, from rails) -var system = require('system'); -var args = system.args; -if (args.length <= 1) { - phantom.exit(); - throw new Error("no arguments supplied on command line"); -}//if - -//configurable variables - CHANGE ME -var mapID = args[1]; -var environment = args[2]; -var address = environment === 'development' ? 'http://localhost:3000' : 'http://metamaps.herokuapp.com'; -var url = address + '/maps/' + mapID; -var width = 940; -var height = 630; - -//set up page and the area we'll render as a PNG -var page = require('webpage').create(); -page.viewportSize = { - width: width, - height: height -}; - -page.open(url, function (status) { - if (status === 'success') { - //since this isn't evaluateAsync, it should also ensure the asynchronous - //js stuff is loaded too, hopefully? - - page.onCallback = function(data){ - - //pass to ruby - console.log(page.renderBase64('PNG')); - - //render to the metamaps_gen002 directory for debug - //page.render('map1.png', 'PNG'); - - phantom.exit(); - }; - - page.evaluate(function() { - - $(document).ready(function () { - //$(document).on(Metamaps.JIT.events.animationDone, function() { - setTimeout(function(){ - $('.upperLeftUI, .upperRightUI, .mapControls, .infoAndHelp, .uv-icon, .footer').hide(); - Metamaps.JIT.zoomExtents(); - window.callPhantom(); - }, 5000); - }); - - });//page.evaluate - - } else { - //failed to load - phantom.exit(); - }//if -}); From 7b9c6459e3f74b2c8eeffc0c41c3dd8d5002c1e4 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 19 Feb 2016 09:23:39 +0800 Subject: [PATCH 29/39] allow embedding --- app/controllers/application_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 74d56340..fb29d7f3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base protect_from_forgery before_filter :get_invite_link + after_action :allow_embedding # this is for global login include ContentHelper @@ -69,4 +70,11 @@ private safe_uri = (unsafe_uri.match(valid_url)) ? unsafe_uri : '//metamaps.cc/' @invite_link = "#{safe_uri}join" + (current_user ? "?code=#{current_user.code}" : "") end + + def allow_embedding + #allow all + response.headers.except! 'X-Frame-Options' + # or allow a whitelist + # response.headers['X-Frame-Options'] = 'ALLOW-FROM http://blog.metamaps.cc' + end end From e629a9bf7108435e34c77ee1b7f340903ee59968 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 19 Feb 2016 18:09:46 +0800 Subject: [PATCH 30/39] fix get_invite_link function. fixes #471 --- app/controllers/application_controller.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 74d56340..8a8d54ea 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -64,9 +64,6 @@ private end def get_invite_link - unsafe_uri = request.env["REQUEST_URI"] || 'https://metamaps.cc' - valid_url = /^https?:\/\/([\w\.-]+)(:\d{1,5})?\/?$/ - safe_uri = (unsafe_uri.match(valid_url)) ? unsafe_uri : '//metamaps.cc/' - @invite_link = "#{safe_uri}join" + (current_user ? "?code=#{current_user.code}" : "") + @invite_link = "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : "") end end From b385efafa932240a6894ceac3821ebc8901f333f Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 21 Feb 2016 17:25:39 +0800 Subject: [PATCH 31/39] don't need xloc or yloc for Synapse mappings --- app/models/mapping.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/mapping.rb b/app/models/mapping.rb index 425f358d..d034de1c 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -7,8 +7,10 @@ class Mapping < ActiveRecord::Base belongs_to :map, :class_name => "Map", :foreign_key => "map_id", touch: true belongs_to :user - validates :xloc, presence: true - validates :yloc, presence: true + validates :xloc, presence: true, + unless: Proc.new { |m| m.mappable_type == 'Synapse' } + validates :yloc, presence: true, + unless: Proc.new { |m| m.mappable_type == 'Synapse' } validates :map, presence: true validates :mappable, presence: true From 295534e4abf084b839f595427912b72f598aee8c Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 23 Feb 2016 14:58:20 +0800 Subject: [PATCH 32/39] migrate to using aws/paperclip for metacodes. RUN RAKE TASK ON PRODUCTION --- Gemfile.lock | 3 - app/models/metacode.rb | 9 ++ app/views/metacodes/_form.html.erb | 2 +- ...061711_add_attachment_icon_to_metacodes.rb | 8 ++ db/schema.rb | 12 ++- db/seeds.rb | 94 +++++++++---------- lib/tasks/aws.rake | 17 ++++ 7 files changed, 90 insertions(+), 55 deletions(-) create mode 100644 db/migrate/20160223061711_add_attachment_icon_to_metacodes.rb create mode 100644 lib/tasks/aws.rake diff --git a/Gemfile.lock b/Gemfile.lock index 3a5f1b41..eb8edec5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -272,6 +272,3 @@ DEPENDENCIES tunemygc uglifier uservoice-ruby - -BUNDLED WITH - 1.11.2 diff --git a/app/models/metacode.rb b/app/models/metacode.rb index aa8f9104..954605fd 100644 --- a/app/models/metacode.rb +++ b/app/models/metacode.rb @@ -3,6 +3,15 @@ class Metacode < ActiveRecord::Base has_many :metacode_sets, :through => :in_metacode_sets has_many :topics + # This method associates the attribute ":icon" with a file attachment + has_attached_file :icon, :styles => { + :ninetysix => ['96x96#', :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 :icon, :content_type => /\Aimage\/.*\Z/ + def hasSelected(user) return true if user.settings.metacodes.include? self.id.to_s return false diff --git a/app/views/metacodes/_form.html.erb b/app/views/metacodes/_form.html.erb index ee19048b..b82eabc7 100644 --- a/app/views/metacodes/_form.html.erb +++ b/app/views/metacodes/_form.html.erb @@ -18,7 +18,7 @@
<%= f.label :icon %> - <%= f.text_field :icon %> + <%= f.file_field :icon %>
diff --git a/db/migrate/20160223061711_add_attachment_icon_to_metacodes.rb b/db/migrate/20160223061711_add_attachment_icon_to_metacodes.rb new file mode 100644 index 00000000..a3d17047 --- /dev/null +++ b/db/migrate/20160223061711_add_attachment_icon_to_metacodes.rb @@ -0,0 +1,8 @@ +class AddAttachmentIconToMetacodes < ActiveRecord::Migration + def change + change_table :metacodes do |t| + t.rename :icon, :old_icon + t.attachment :icon + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 9ecb3488..4601c71a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160120061513) do +ActiveRecord::Schema.define(version: 20160223061711) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -76,10 +76,14 @@ ActiveRecord::Schema.define(version: 20160120061513) do create_table "metacodes", force: :cascade do |t| t.text "name" - t.string "icon" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "old_icon" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "color" + t.string "icon_file_name" + t.string "icon_content_type" + t.integer "icon_file_size" + t.datetime "icon_updated_at" end create_table "synapses", force: :cascade do |t| diff --git a/db/seeds.rb b/db/seeds.rb index 51aa01d9..102332cc 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -24,283 +24,283 @@ User.new({ ## METACODES Metacode.create({ name: 'Action', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_action.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_action.png', color: '#BD6C85' }) Metacode.create({ name: 'Activity', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_activity.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_activity.png', color: '#6EBF65' }) Metacode.create({ name: 'Catalyst', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_catalyst.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_catalyst.png', color: '#EF8964', }) Metacode.create({ name: 'Closed', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_closedissue.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_closedissue.png', color: '#ABB49F', }) Metacode.create({ name: 'Process', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_process.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_process.png', color: '#BDB25E', }) Metacode.create({ name: 'Future', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_futuredev.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_futuredev.png', color: '#25A17F', }) Metacode.create({ name: 'Group', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_group.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_group.png', color: '#7076BC', }) Metacode.create({ name: 'Implication', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_implication.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_implication.png', color: '#83DECA', }) Metacode.create({ name: 'Insight', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_insight.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_insight.png', color: '#B074AD', }) Metacode.create({ name: 'Intention', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_intention.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_intention.png', color: '#BAEAFF', }) Metacode.create({ name: 'Knowledge', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_knowledge.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_knowledge.png', color: '#60ACF7', }) Metacode.create({ name: 'Location', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_location.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_location.png', color: '#ABD9A7', }) Metacode.create({ name: 'Need', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_need.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_need.png', color: '#D2A7D4', }) Metacode.create({ name: 'Open', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_openissue.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_openissue.png', color: '#9BBF71', }) Metacode.create({ name: 'Opportunity', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_opportunity.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_opportunity.png', color: '#889F64', }) Metacode.create({ name: 'Person', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_person.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_person.png', color: '#DE925F', }) Metacode.create({ name: 'Platform', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_platform.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_platform.png', color: '#21C8FE', }) Metacode.create({ name: 'Problem', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_problem.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_problem.png', color: '#99CFC4', }) Metacode.create({ name: 'Resource', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_resource.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_resource.png', color: '#C98C63', }) Metacode.create({ name: 'Role', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_role.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_role.png', color: '#A8595D', }) Metacode.create({ name: 'Task', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_task.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_task.png', color: '#3397C4', }) Metacode.create({ name: 'Trajectory', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_trajectory.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_trajectory.png', color: '#D3AA4C', }) Metacode.create({ name: 'Argument', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_argument.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_argument.png', color: '#7FAEFD', }) Metacode.create({ name: 'Con', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_con.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_con.png', color: '#CF7C74', }) Metacode.create({ name: 'Subject', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_subject.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_subject.png', color: '#8293D8', }) Metacode.create({ name: 'Decision', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_decision.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_decision.png', color: '#CCA866', }) Metacode.create({ name: 'Event', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_event.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_event.png', color: '#F5854B', }) Metacode.create({ name: 'Example', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_example.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_example.png', color: '#618C61', }) Metacode.create({ name: 'Experience', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_experience.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_experience.png', color: '#BE995F', }) Metacode.create({ name: 'Feedback', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_feedback.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_feedback.png', color: '#54A19D', }) Metacode.create({ name: 'Aim', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_aim.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_aim.png', color: '#B0B0B0', }) Metacode.create({ name: 'Good', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_goodpractice.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_goodpractice.png', color: '#BD9E86', }) Metacode.create({ name: 'Idea', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_idea.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_idea.png', color: '#C4BC5E', }) Metacode.create({ name: 'List', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_list.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_list.png', color: '#B7A499', }) Metacode.create({ name: 'Media', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_media.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_media.png', color: '#6D94CC', }) Metacode.create({ name: 'Metamap', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_metamap.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_metamap.png', color: '#AEA9FD', }) Metacode.create({ name: 'Model', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_model.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_model.png', color: '#B385BA', }) Metacode.create({ name: 'Note', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_note.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_note.png', color: '#A389A1', }) Metacode.create({ name: 'Perspective', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_perspective.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_perspective.png', color: '#2EB6CC', }) Metacode.create({ name: 'Pro', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_pro.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_pro.png', color: '#89B879', }) Metacode.create({ name: 'Project', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_project.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_project.png', color: '#85A050', }) Metacode.create({ name: 'Question', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_question.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_question.png', color: '#5CB3B3', }) Metacode.create({ name: 'Reference', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_reference.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_reference.png', color: '#A7A7A7', }) Metacode.create({ name: 'Research', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_research.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_research.png', color: '#CD8E89', }) Metacode.create({ name: 'Status', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_status.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_status.png', color: '#EFA7C0', }) Metacode.create({ name: 'Tool', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_tool.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_tool.png', color: '#828282', }) Metacode.create({ name: 'Wildcard', - icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png', + icon_file_name: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png', color: '#73C7DE', }) ## END METACODES diff --git a/lib/tasks/aws.rake b/lib/tasks/aws.rake new file mode 100644 index 00000000..c49f3f81 --- /dev/null +++ b/lib/tasks/aws.rake @@ -0,0 +1,17 @@ +namespace :aws do + desc 'migrate metacodes to aws' + task metacode_icon_migrate: :environment do + def no_aws(msg) + Rails.logger.error msg + end + + no_aws 'You need to configure S3_BUCKET' unless ENV['S3_BUCKET'].present? + no_aws 'You need to configure AWS_ACCESS_KEY_ID' unless ENV['AWS_ACCESS_KEY_ID'].present? + no_aws 'You need to configure AWS_SECRET_ACCESS_KEY' unless ENV['AWS_SECRET_ACCESS_KEY'].present? + + Metacode.find_each do |metacode| + metacode.icon = metacode.old_icon + metacode.save + end + end +end From 7a74668c8dcf959b566c3661339e0902908c927b Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 23 Feb 2016 18:56:50 +0800 Subject: [PATCH 33/39] tweaks to lightboxes view post-SSL --- app/views/layouts/_lightboxes.html.erb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/views/layouts/_lightboxes.html.erb b/app/views/layouts/_lightboxes.html.erb index e2c9de50..f9bb78ff 100644 --- a/app/views/layouts/_lightboxes.html.erb +++ b/app/views/layouts/_lightboxes.html.erb @@ -46,7 +46,6 @@
  • - <% # TODO enable ssl on blog.metamaps.cc %>
    blog @@ -59,8 +58,7 @@
  • - <% # TODO switch to https:// once we're confident %> - +
    terms
    @@ -154,7 +152,6 @@ Chrome Firefox Safari - <% # TODO https for blog.metamaps.cc %>

    While it's downloading, explore our blog,
    watch the tutorials, or visit our knowledge base!

  • @@ -171,7 +168,7 @@

    If you'd like to know what your money is going towards, we publish our financials transparently - everything is recorded through our value accounting system.

    - +
    @@ -203,8 +200,7 @@

    Want to help with design, code, community building, or communications for Metamaps? We're an open value network, which for us means we want to invite and empower peers to participate in creating value together. - <% # TODO change this link to https once it works %> -

    To be a USER, request an invite! We'll expect you to abide by our terms of service.

    +

    To be a USER, request an invite! We'll expect you to abide by our terms of service.

    To be a CONTRIBUTOR, simply enter our spaces and join the conversation! We'll expect you to follow some guidelines.

    From 59f84cfe204baf6bbc5ff23ebdd04a7c9d617d21 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 23 Feb 2016 18:59:45 +0800 Subject: [PATCH 34/39] cleanup TODO lines --- app/views/maps/index.html.erb | 16 +++++++++------- app/views/synapses/_new.html.erb | 10 ---------- 2 files changed, 9 insertions(+), 17 deletions(-) delete mode 100644 app/views/synapses/_new.html.erb diff --git a/app/views/maps/index.html.erb b/app/views/maps/index.html.erb index cd9661e0..0e067a63 100644 --- a/app/views/maps/index.html.erb +++ b/app/views/maps/index.html.erb @@ -1,10 +1,12 @@ -<%# - # @file - # Shows a list of all maps, or just a user's maps. - # TODO: What url is this accessible at? - #%> - - +<% # + # @file + # Shows a list of all maps, or just a user's maps. + # GET /explore/active(.:format) + # GET /explore/featured(.:format) + # GET /explore/mine(.:format) + # GET /explore/mapper/:id(.:format) + # GET /maps(.:format) + # %>