cirandas.net

ref: master

test/unit/plugin_settings_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
40
41
42
43
44
45
46
47
48
49
50
require_relative "../test_helper"

class SolarSystemPlugin < Noosfero::Plugin
  def self.secret_default_setting
    42
  end
end

class PluginSettingsTest < ActiveSupport::TestCase

  def setup
    @environment = Environment.new
    @profile = Profile.new
    @plugin = SolarSystemPlugin
  end

  attr_accessor :environment, :profile, :plugin, :settings

  should 'store setttings on any model that offers settings' do
    base = environment
    settings = Noosfero::Plugin::Settings.new(base, plugin)
    settings.star = 'sun'
    settings.planets = 8
    assert_equal 'sun', base.settings[:solar_system_plugin][:star]
    assert_equal 8, base.settings[:solar_system_plugin][:planets]
    assert_equal 'sun', settings.star
    assert_equal 8, settings.planets

    base = profile
    settings = Noosfero::Plugin::Settings.new(base, plugin)
    settings.star = 'sun'
    settings.planets = 8
    assert_equal 'sun', base.settings[:solar_system_plugin][:star]
    assert_equal 8, base.settings[:solar_system_plugin][:planets]
    assert_equal 'sun', settings.star
    assert_equal 8, settings.planets
  end

  should 'save base on save' do
    environment.expects(:save!)
    settings = Noosfero::Plugin::Settings.new(environment, plugin)
    settings.save!
  end

  should 'use default value defined on the plugin class' do
    settings = Noosfero::Plugin::Settings.new(profile, plugin)
    assert_equal 42, settings.secret
  end

end