cirandas.net

ref: master

test/functional/embed_controller_test.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require_relative "../test_helper"

class EmbedControllerTest < ActionController::TestCase

  def setup
    login_as(create_admin_user(Environment.default))
    @block = LoginBlock.create!
    @block.class.any_instance.stubs(:embedable?).returns(true)
    @environment = Environment.default
    @environment.boxes.create!
    @environment.boxes.first.blocks << @block
  end

  should 'be able to get embed block' do
    get :block, :id => @block.id
    assert_tag :tag => 'div', :attributes => { :id => "block-#{@block.id}" }
  end

  should 'display error message when not found block' do
    Block.delete_all
    get :block, :id => 1
    assert_tag :tag => 'div', :attributes => { :id => "not-found" }
  end

  should 'display error message when block is not visible/public' do
    @block.display = 'never'
    assert @block.save
    get :block, :id => @block.id
    assert_tag :tag => 'div', :attributes => { :id => "unavailable" }
  end

  should 'display error message when block is not embedable' do
    @block.class.any_instance.stubs(:embedable?).returns(false)
    get :block, :id => @block.id
    assert_tag :tag => 'div', :attributes => { :id => "unavailable" }
  end


end