From 50f98aebea73fab221a4d0534fb07aef7da6b48b Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sat, 24 Sep 2016 14:35:23 +0800 Subject: [PATCH] explore controller spec --- app/controllers/explore_controller.rb | 12 +++++------ app/policies/explore_policy.rb | 12 +++++------ spec/controllers/explore_controller_spec.rb | 23 +++++++++++++++++++++ spec/controllers/maps_controller_spec.rb | 15 -------------- 4 files changed, 35 insertions(+), 27 deletions(-) create mode 100644 spec/controllers/explore_controller_spec.rb diff --git a/app/controllers/explore_controller.rb b/app/controllers/explore_controller.rb index 3c099920..6f24eba5 100644 --- a/app/controllers/explore_controller.rb +++ b/app/controllers/explore_controller.rb @@ -21,7 +21,7 @@ class ExploreController < ApplicationController redirect_to(root_url) && return if authenticated? respond_with(@maps, @user) end - format.json { render json: @maps } + format.json { render json: @maps.to_json } end end @@ -35,7 +35,7 @@ class ExploreController < ApplicationController respond_to do |format| format.html { respond_with(@maps, @user) } - format.json { render json: @maps } + format.json { render json: @maps.to_json } end end @@ -53,7 +53,7 @@ class ExploreController < ApplicationController respond_to do |format| format.html { respond_with(@maps, @user) } - format.json { render json: @maps } + format.json { render json: @maps.to_json } end end @@ -71,7 +71,7 @@ class ExploreController < ApplicationController respond_to do |format| format.html { respond_with(@maps, @user) } - format.json { render json: @maps } + format.json { render json: @maps.to_json } end end @@ -90,7 +90,7 @@ class ExploreController < ApplicationController respond_to do |format| format.html { respond_with(@maps, @user) } - format.json { render json: @maps } + format.json { render json: @maps.to_json } end end @@ -103,7 +103,7 @@ class ExploreController < ApplicationController respond_to do |format| format.html { respond_with(@maps, @user) } - format.json { render json: @maps } + format.json { render json: @maps.to_json } end end diff --git a/app/policies/explore_policy.rb b/app/policies/explore_policy.rb index 6cbdab15..b4d52fe5 100644 --- a/app/policies/explore_policy.rb +++ b/app/policies/explore_policy.rb @@ -1,25 +1,25 @@ class ExplorePolicy < ApplicationPolicy - def activemaps? + def active? true end - def featuredmaps? + def featured? true end - def mymaps? + def mine? true end - def sharedmaps? + def shared? true end - def starredmaps? + def starred? true end - def usermaps? + def mapper? true end end diff --git a/spec/controllers/explore_controller_spec.rb b/spec/controllers/explore_controller_spec.rb new file mode 100644 index 00000000..4e298a92 --- /dev/null +++ b/spec/controllers/explore_controller_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true +require 'rails_helper' + +RSpec.describe ExploreController, type: :controller do + before :each do + sign_in create(:user) + end + + describe 'GET explore/active' do + context 'always returns an array' do + it 'with 0 records' do + Map.delete_all + get :active, format: :json + expect(JSON.parse(response.body)).to eq [] + end + it 'with 1 record' do + map = create(:map) + get :active, format: :json + expect(JSON.parse(response.body).class).to be Array + end + end + end +end diff --git a/spec/controllers/maps_controller_spec.rb b/spec/controllers/maps_controller_spec.rb index b877dc88..0f053dd9 100644 --- a/spec/controllers/maps_controller_spec.rb +++ b/spec/controllers/maps_controller_spec.rb @@ -9,21 +9,6 @@ RSpec.describe MapsController, type: :controller do sign_in create(:user) end - describe 'GET #activemaps' do - context 'always returns an array' do - it 'with 0 records' do - Map.delete_all - get :activemaps, format: :json - expect(JSON.parse(response.body)).to eq [] - end - it 'with 1 record' do - map = create(:map) - get :activemaps, format: :json - expect(JSON.parse(response.body).class).to be Array - end - end - end - describe 'POST #create' do context 'with valid params' do it 'creates a new Map' do