explore controller spec
This commit is contained in:
parent
dad048eb20
commit
50f98aebea
4 changed files with 35 additions and 27 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
23
spec/controllers/explore_controller_spec.rb
Normal file
23
spec/controllers/explore_controller_spec.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue