explore controller spec

This commit is contained in:
Devin Howard 2016-09-24 14:35:23 +08:00
parent dad048eb20
commit 50f98aebea
4 changed files with 35 additions and 27 deletions

View file

@ -21,7 +21,7 @@ class ExploreController < ApplicationController
redirect_to(root_url) && return if authenticated? redirect_to(root_url) && return if authenticated?
respond_with(@maps, @user) respond_with(@maps, @user)
end end
format.json { render json: @maps } format.json { render json: @maps.to_json }
end end
end end
@ -35,7 +35,7 @@ class ExploreController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { respond_with(@maps, @user) } format.html { respond_with(@maps, @user) }
format.json { render json: @maps } format.json { render json: @maps.to_json }
end end
end end
@ -53,7 +53,7 @@ class ExploreController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { respond_with(@maps, @user) } format.html { respond_with(@maps, @user) }
format.json { render json: @maps } format.json { render json: @maps.to_json }
end end
end end
@ -71,7 +71,7 @@ class ExploreController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { respond_with(@maps, @user) } format.html { respond_with(@maps, @user) }
format.json { render json: @maps } format.json { render json: @maps.to_json }
end end
end end
@ -90,7 +90,7 @@ class ExploreController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { respond_with(@maps, @user) } format.html { respond_with(@maps, @user) }
format.json { render json: @maps } format.json { render json: @maps.to_json }
end end
end end
@ -103,7 +103,7 @@ class ExploreController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { respond_with(@maps, @user) } format.html { respond_with(@maps, @user) }
format.json { render json: @maps } format.json { render json: @maps.to_json }
end end
end end

View file

@ -1,25 +1,25 @@
class ExplorePolicy < ApplicationPolicy class ExplorePolicy < ApplicationPolicy
def activemaps? def active?
true true
end end
def featuredmaps? def featured?
true true
end end
def mymaps? def mine?
true true
end end
def sharedmaps? def shared?
true true
end end
def starredmaps? def starred?
true true
end end
def usermaps? def mapper?
true true
end end
end end

View 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

View file

@ -9,21 +9,6 @@ RSpec.describe MapsController, type: :controller do
sign_in create(:user) sign_in create(:user)
end 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 describe 'POST #create' do
context 'with valid params' do context 'with valid params' do
it 'creates a new Map' do it 'creates a new Map' do