ensure there is a default eportfolio page
fixes CNVS-14580 test plan: 1. create an eportfolio 2. click organize/manage pages 3. create a second page 4. open the eportfolio in a new tab 5. in one tab, delete the welcome page 6. in the second tab, delete the new page 7. refresh the eportfolio 8. it should still load the welcome page (having recreated it) Change-Id: I400b2d4689773a8f48d8b3bfa577982492a4bfb4 Reviewed-on: https://gerrit.instructure.com/38847 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Cameron Matheson <cameron@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Product-Review: Simon Williams <simon@instructure.com>
This commit is contained in:
parent
4d84e1cdc2
commit
24d3ddd01f
|
@ -40,7 +40,7 @@ class EportfoliosController < ApplicationController
|
|||
@portfolio = @current_user.eportfolios.build(params[:eportfolio])
|
||||
respond_to do |format|
|
||||
if @portfolio.save
|
||||
@portfolio.setup_defaults
|
||||
@portfolio.ensure_defaults
|
||||
flash[:notice] = t('notices.created', "Porfolio successfully created")
|
||||
format.html { redirect_to eportfolio_url(@portfolio) }
|
||||
format.json { render :json => @portfolio.as_json(:permissions => {:user => @current_user, :session => session}) }
|
||||
|
@ -60,8 +60,8 @@ class EportfoliosController < ApplicationController
|
|||
session[:permissions_key] = CanvasUUID.generate
|
||||
end
|
||||
if authorized_action(@portfolio, @current_user, :read)
|
||||
@category = @portfolio.eportfolio_categories.first rescue nil
|
||||
@category ||= @portfolio.setup_defaults
|
||||
@portfolio.ensure_defaults
|
||||
@category = @portfolio.eportfolio_categories.first
|
||||
@page = @category.eportfolio_entries.first
|
||||
@owner_view = @portfolio.user == @current_user && params[:view] != 'preview'
|
||||
if @owner_view
|
||||
|
@ -89,7 +89,7 @@ class EportfoliosController < ApplicationController
|
|||
if authorized_action(@portfolio, @current_user, :update)
|
||||
respond_to do |format|
|
||||
if @portfolio.update_attributes(params[:eportfolio])
|
||||
@portfolio.setup_defaults
|
||||
@portfolio.ensure_defaults
|
||||
flash[:notice] = t('notices.updated', "Porfolio successfully updated")
|
||||
format.html { redirect_to eportfolio_url(@portfolio) }
|
||||
format.json { render :json => @portfolio.as_json(:permissions => {:user => @current_user, :session => session}) }
|
||||
|
|
|
@ -65,12 +65,13 @@ class Eportfolio < ActiveRecord::Base
|
|||
can :read
|
||||
end
|
||||
|
||||
def setup_defaults
|
||||
cat = self.eportfolio_categories.create(:name => t(:first_category, "Home")) if self.eportfolio_categories.empty?
|
||||
def ensure_defaults
|
||||
cat = self.eportfolio_categories.first
|
||||
cat ||= self.eportfolio_categories.create!(:name => t(:first_category, "Home"))
|
||||
if cat && cat.eportfolio_entries.empty?
|
||||
entry = cat.eportfolio_entries.build(:eportfolio => self, :name => t('first_entry.title', "Welcome"))
|
||||
entry.content = t('first_entry.content', "Nothing entered yet")
|
||||
entry.save
|
||||
entry.save!
|
||||
end
|
||||
cat
|
||||
end
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
module EportfolioPage
|
||||
def eportfolio_page_attributes
|
||||
@portfolio.setup_defaults
|
||||
@categories = @portfolio.eportfolio_categories
|
||||
if @portfolio.grants_right?(@current_user, session, :manage)
|
||||
@recent_submissions = @current_user.submissions.order("created_at DESC").all if @current_user && @current_user == @portfolio.user
|
||||
|
@ -49,4 +48,4 @@ module EportfolioPage
|
|||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -94,6 +94,21 @@ describe EportfoliosController do
|
|||
response.should be_success
|
||||
assigns[:portfolio].should_not be_nil
|
||||
end
|
||||
|
||||
it "should create a category if one doesn't exist" do
|
||||
user_session(@user)
|
||||
get 'show', :id => @portfolio.id
|
||||
response.should be_success
|
||||
assigns[:category].should_not be_nil
|
||||
end
|
||||
|
||||
it "should create an entry in the first category if one doesn't exist" do
|
||||
@portfolio.eportfolio_categories.create!(:name => "Home")
|
||||
user_session(@user)
|
||||
get 'show', :id => @portfolio.id
|
||||
response.should be_success
|
||||
assigns[:page].should_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT 'update'" do
|
||||
|
|
|
@ -19,4 +19,22 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
||||
|
||||
describe Eportfolio do
|
||||
describe "#ensure_defaults" do
|
||||
before(:once) do
|
||||
eportfolio
|
||||
end
|
||||
|
||||
it "should create a category if one doesn't exist" do
|
||||
@portfolio.eportfolio_categories.should be_empty
|
||||
@portfolio.ensure_defaults
|
||||
@portfolio.reload.eportfolio_categories.should_not be_empty
|
||||
end
|
||||
|
||||
it "should create an entry in the first category if one doesn't exist" do
|
||||
@category = @portfolio.eportfolio_categories.create!(:name => "Hi")
|
||||
@category.eportfolio_entries.should be_empty
|
||||
@portfolio.ensure_defaults
|
||||
@category.reload.eportfolio_entries.should_not be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue