maps controller spec passes, 3 pending

This commit is contained in:
Devin Howard 2016-02-09 11:48:07 +08:00
parent 374ac701c9
commit 43bdda61de
3 changed files with 34 additions and 34 deletions

View file

@ -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

View file

@ -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

View file

@ -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