maps controller spec passes, 3 pending
This commit is contained in:
parent
374ac701c9
commit
43bdda61de
3 changed files with 34 additions and 34 deletions
|
@ -102,7 +102,6 @@ class MapsController < ApplicationController
|
||||||
|
|
||||||
# POST maps
|
# POST maps
|
||||||
def create
|
def create
|
||||||
|
|
||||||
@user = current_user
|
@user = current_user
|
||||||
@map = Map.new()
|
@map = Map.new()
|
||||||
@map.name = params[:name]
|
@map.name = params[:name]
|
||||||
|
@ -110,41 +109,46 @@ class MapsController < ApplicationController
|
||||||
@map.permission = params[:permission]
|
@map.permission = params[:permission]
|
||||||
@map.user = @user
|
@map.user = @user
|
||||||
@map.arranged = false
|
@map.arranged = false
|
||||||
@map.save
|
|
||||||
|
|
||||||
if params[:topicsToMap]
|
if params[:topicsToMap]
|
||||||
@all = params[:topicsToMap]
|
@all = params[:topicsToMap]
|
||||||
@all = @all.split(',')
|
@all = @all.split(',')
|
||||||
@all.each do |topic|
|
@all.each do |topic|
|
||||||
topic = topic.split('/')
|
topic = topic.split('/')
|
||||||
@mapping = Mapping.new()
|
mapping = Mapping.new()
|
||||||
@mapping.user = @user
|
mapping.user = @user
|
||||||
@mapping.map = @map
|
mapping.mappable = Topic.find(topic[0])
|
||||||
@mapping.mappable = Topic.find(topic[0])
|
mapping.xloc = topic[1]
|
||||||
@mapping.xloc = topic[1]
|
mapping.yloc = topic[2]
|
||||||
@mapping.yloc = topic[2]
|
@map.topicmappings << mapping
|
||||||
@mapping.save
|
mapping.save
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:synapsesToMap]
|
if params[:synapsesToMap]
|
||||||
@synAll = params[:synapsesToMap]
|
@synAll = params[:synapsesToMap]
|
||||||
@synAll = @synAll.split(',')
|
@synAll = @synAll.split(',')
|
||||||
@synAll.each do |synapse_id|
|
@synAll.each do |synapse_id|
|
||||||
@mapping = Mapping.new()
|
mapping = Mapping.new()
|
||||||
@mapping.user = @user
|
mapping.user = @user
|
||||||
@mapping.map = @map
|
mapping.map = @map
|
||||||
@mapping.mappable = Synapse.find(synapse_id)
|
mapping.mappable = Synapse.find(synapse_id)
|
||||||
@mapping.save
|
@map.synapsemappings << mapping
|
||||||
|
mapping.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@map.arranged = true
|
@map.arranged = true
|
||||||
@map.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @map.save
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json { render :json => @map }
|
format.json { render :json => @map }
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
respond_to do |format|
|
||||||
|
format.json { render :json => "invalid params" }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# PUT maps/:id
|
# PUT maps/:id
|
||||||
|
|
|
@ -41,41 +41,41 @@ class Map < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def topic_count
|
def topic_count
|
||||||
self.topics.length
|
topics.length
|
||||||
end
|
end
|
||||||
|
|
||||||
def synapse_count
|
def synapse_count
|
||||||
self.synapses.length
|
synapses.length
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_name
|
def user_name
|
||||||
self.user.name
|
user.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_image
|
def user_image
|
||||||
self.user.image.url
|
user.image.url
|
||||||
end
|
end
|
||||||
|
|
||||||
def contributor_count
|
def contributor_count
|
||||||
self.contributors.length
|
contributors.length
|
||||||
end
|
end
|
||||||
|
|
||||||
def screenshot_url
|
def screenshot_url
|
||||||
self.screenshot.url(:thumb)
|
screenshot.url(:thumb)
|
||||||
end
|
end
|
||||||
|
|
||||||
def created_at_str
|
def created_at_str
|
||||||
self.created_at.strftime("%m/%d/%Y")
|
created_at.strftime("%m/%d/%Y")
|
||||||
end
|
end
|
||||||
|
|
||||||
def updated_at_str
|
def updated_at_str
|
||||||
self.updated_at.strftime("%m/%d/%Y")
|
updated_at.strftime("%m/%d/%Y")
|
||||||
end
|
end
|
||||||
|
|
||||||
def as_json(options={})
|
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 = 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[:created_at_clean] = created_at_str
|
||||||
json[:updated_at_clean] = self.updated_at_str
|
json[:updated_at_clean] = updated_at_str
|
||||||
json
|
json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -32,26 +32,22 @@ RSpec.describe MapsController, type: :controller do
|
||||||
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
|
||||||
|
map.reload
|
||||||
expect do
|
expect do
|
||||||
post :create, { map: valid_attributes }
|
post :create, valid_attributes.merge(format: :json)
|
||||||
end.to change(Map, :count).by(1)
|
end.to change(Map, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'assigns a newly created map as @map' do
|
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_a(Map)
|
||||||
expect(assigns(:map)).to be_persisted
|
expect(assigns(:map)).to be_persisted
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'redirects to the created map' do
|
|
||||||
post :create, { map: valid_attributes }
|
|
||||||
expect(response).to redirect_to(Map.last)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with invalid params' do
|
context 'with invalid params' do
|
||||||
it 'assigns a newly created but unsaved map as @map' 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)
|
expect(assigns(:map)).to be_a_new(Map)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue