Commit 27a02177 authored by azul's avatar azul

Merge branch 'fix-staging-issues' into 'staging'

fix: actually seed data in context controller

See merge request !284
parents 6ea554eb b7da32ac
......@@ -23,11 +23,11 @@ class DispatchController < ApplicationController
modify_params controller: controller_name
class_name = "#{params[:controller].camelcase}Controller"
klass = class_name.constantize
if klass.method_defined? :seed_instance
klass.seed_instance group: @group, user: @user, page: @page
else
klass.new
instance = klass.new
if instance.respond_to? :seed
instance.seed group: @group, user: @user, page: @page
end
return instance
end
def not_found
......
......@@ -30,14 +30,8 @@ class Page::BaseController < ApplicationController
after_action :save_if_needed, except: :create
after_action :update_viewed, only: :show
def self.seed_instance(args)
new.seed(args)
end
include Page::BeforeFilters
protected
# if the page controller is initialized by our custom DispatchController,
# objects which have already been loaded will be passed in via this
def seed(user: nil, group: nil, page: nil)
......@@ -46,6 +40,8 @@ class Page::BaseController < ApplicationController
@page = page # the page object, if already fetched
end
private
# to be overridden by subclasses
def fetch_data; end
......
......@@ -60,6 +60,11 @@ rainbow_own_page:
group_id: 3
access: 1
animal_own_page:
page_id: 1004
group_id: 2
access: 1
warm_committee_page:
page_id: 1001
group_id: 31
......
This diff is collapsed.
......@@ -91,7 +91,7 @@ blue_page:
rainbow_page:
id: 1003
name: "rainbow_page"
name: "duplicate-name"
title: "page owned by rainbow"
<% updated = rand(46080); created = updated + rand(46080) %>
updated_at: "<%= updated.minutes.ago.to_s(:db) %>"
......@@ -102,6 +102,18 @@ rainbow_page:
updated_by_id: 4
type: DiscussionPage
animals_page:
id: 1004
name: "duplicate-name"
title: "page owned by animals"
<% updated = rand(46080); created = updated + rand(46080) %>
updated_at: "<%= updated.minutes.ago.to_s(:db) %>"
created_at: "<%= created.minutes.ago.to_s(:db) %>"
owner_id: 2
owner_type: Group
owner_name: animals
updated_by_id: 4
type: DiscussionPage
ranked_vote:
id: 190
......
......@@ -4,14 +4,20 @@ require 'integration_test'
# Tests for the special shortcut urls based on contexts
#
class ContextUrlTest < IntegrationTest
def test_group_page
login users(:blue)
visit '/rainbow/rainbow_page'
def test_accessing_page_with_duplicate_name
login users(:orange)
visit 'rainbow/duplicate-name'
assert_content 'page owned by rainbow'
end
def test_accessing_other_page_with_same_name
login users(:kangaroo)
visit 'animals/duplicate-name'
assert_content 'page owned by animals'
end
def test_group_page_login
visit '/rainbow/rainbow_page'
visit '/rainbow/duplicate-name'
assert_content 'could not find'
login users(:blue)
assert_content 'page owned by rainbow'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment