0001-Fix-test-not-to-raise-exception.patch

Mizuki ISHIKAWA, 2019-03-28 08:08

Download (9.91 KB)

View differences:

test/fixtures/plugins/other_plugin/_other_plugin_settings.html.erb
1
<p><label>Example setting</label><%= text_field_tag 'settings[sample_setting]', @settings['sample_setting'] %></p>
test/functional/admin_controller_test.rb
121 121
      description 'This is a test plugin'
122 122
      version '0.0.1'
123 123
      settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
124
      directory 'test/fixtures/plugins/foo_plugin'
124 125
    end
125
    Redmine::Plugin.register :bar do
126
    Redmine::Plugin.register :other do
127
      directory 'test/fixtures/plugins/other_plugin'
126 128
    end
127 129

  
128 130
    get :plugins
......
132 134
      assert_select 'td span.name', :text => 'Foo plugin'
133 135
      assert_select 'td.configure a[href="/settings/plugin/foo"]'
134 136
    end
135
    assert_select 'tr#plugin-bar' do
136
      assert_select 'td span.name', :text => 'Bar'
137
    assert_select 'tr#plugin-other' do
138
      assert_select 'td span.name', :text => 'Other'
137 139
      assert_select 'td.configure a', 0
138 140
    end
139 141
  end
test/functional/settings_controller_test.rb
201 201
    ActionController::Base.append_view_path(File.join(Rails.root, "test/fixtures/plugins"))
202 202
    Redmine::Plugin.register :foo do
203 203
      settings :partial => "foo_plugin/foo_plugin_settings"
204
      directory 'test/fixtures/plugins/foo_plugin'
204 205
    end
205 206
    Setting.plugin_foo = {'sample_setting' => 'Plugin setting value'}
206 207

  
......
220 221
  end
221 222

  
222 223
  def test_get_non_configurable_plugin_settings
223
    Redmine::Plugin.register(:foo) {}
224
    Redmine::Plugin.register(:foo) do
225
      directory 'test/fixtures/plugins/foo_plugin'
226
    end
224 227

  
225 228
    get :plugin, :params => {:id => 'foo'}
226 229
    assert_response 404
......
233 236
    Redmine::Plugin.register(:foo) do
234 237
      settings :partial => 'not blank', # so that configurable? is true
235 238
        :default => {'sample_setting' => 'Plugin setting value'}
239
      directory 'test/fixtures/plugins/foo_plugin'
236 240
    end
237 241

  
238 242
    post :plugin, :params => {
......
248 252
    Redmine::Plugin.register(:foo) do
249 253
      settings :partial => 'not blank', # so that configurable? is true
250 254
        :default => {'sample_setting' => 'Plugin setting value'}
255
      directory 'test/fixtures/plugins/foo_plugin'
251 256
    end
252 257

  
253 258
    post :plugin, :params => {
......
259 264
  end
260 265

  
261 266
  def test_post_non_configurable_plugin_settings
262
    Redmine::Plugin.register(:foo) {}
267
    Redmine::Plugin.register(:foo) do
268
      directory 'test/fixtures/plugins/foo_plugin'
269
    end
263 270

  
264 271
    post :plugin, :params => {
265 272
      :id => 'foo',
test/unit/lib/redmine/plugin_test.rb
22 22
class Redmine::PluginTest < ActiveSupport::TestCase
23 23
  def setup
24 24
    @klass = Redmine::Plugin
25
    # Change plugin directory for testing to default
26
    # plugins/foo => test/fixtures/plugins/foo
27
    @klass.directory = Rails.root.join('test/fixtures/plugins')
25 28
    # In case some real plugins are installed
26 29
    @klass.clear
27 30
  end
......
31 34
  end
32 35

  
33 36
  def test_register
34
    @klass.register :foo do
37
    @klass.register :foo_plugin do
35 38
      name 'Foo plugin'
36 39
      url 'http://example.net/plugins/foo'
37 40
      author 'John Smith'
......
43 46

  
44 47
    assert_equal 1, @klass.all.size
45 48

  
46
    plugin = @klass.find('foo')
49
    plugin = @klass.find('foo_plugin')
47 50
    assert plugin.is_a?(Redmine::Plugin)
48
    assert_equal :foo, plugin.id
51
    assert_equal :foo_plugin, plugin.id
49 52
    assert_equal 'Foo plugin', plugin.name
50 53
    assert_equal 'http://example.net/plugins/foo', plugin.url
51 54
    assert_equal 'John Smith', plugin.author
......
55 58
  end
56 59

  
57 60
  def test_installed
58
    @klass.register(:foo) {}
59
    assert_equal true, @klass.installed?(:foo)
61
    @klass.register(:foo_plugin) {}
62
    assert_equal true, @klass.installed?(:foo_plugin)
60 63
    assert_equal false, @klass.installed?(:bar)
61 64
  end
62 65

  
63 66
  def test_menu
64 67
    assert_difference 'Redmine::MenuManager.items(:project_menu).size' do
65
      @klass.register :foo do
68
      @klass.register :foo_plugin do
66 69
        menu :project_menu, :foo_menu_item, '/foo', :caption => 'Foo'
67 70
      end
68 71
    end
......
77 80
  def test_delete_menu_item
78 81
    Redmine::MenuManager.map(:project_menu).push(:foo_menu_item, '/foo', :caption => 'Foo')
79 82
    assert_difference 'Redmine::MenuManager.items(:project_menu).size', -1 do
80
      @klass.register :foo do
83
      @klass.register :foo_plugin do
81 84
        delete_menu_item :project_menu, :foo_menu_item
82 85
      end
83 86
    end
......
88 91

  
89 92
  def test_directory_with_override
90 93
    @klass.register(:foo) do
91
      directory '/path/to/foo'
94
      directory 'test/fixtures/plugins/foo_plugin'
92 95
    end
93
    assert_equal '/path/to/foo', @klass.find('foo').directory
96
    assert_equal 'test/fixtures/plugins/foo_plugin', @klass.find('foo').directory
94 97
  end
95 98

  
96 99
  def test_directory_without_override
97
    @klass.register(:foo) {}
98
    assert_equal File.join(@klass.directory, 'foo'), @klass.find('foo').directory
100
    @klass.register(:other_plugin) {}
101
    assert_equal File.join(@klass.directory, 'other_plugin'), @klass.find('other_plugin').directory
99 102
  end
100 103

  
101 104
  def test_requires_redmine
102
    plugin = Redmine::Plugin.register(:foo) {}
105
    plugin = Redmine::Plugin.register(:foo_plugin) {}
103 106
    Redmine::VERSION.stubs(:to_a).returns([2, 1, 3, "stable", 10817])
104 107
    # Specific version without hash
105 108
    assert plugin.requires_redmine('2.1.3')
......
148 151
  def test_requires_redmine_plugin
149 152
    test = self
150 153
    other_version = '0.5.0'
151
    @klass.register :other do
154
    @klass.register :other_plugin do
152 155
      name 'Other'
153 156
      version other_version
154 157
    end
155
    @klass.register :foo do
156
      test.assert requires_redmine_plugin(:other, :version_or_higher => '0.1.0')
157
      test.assert requires_redmine_plugin(:other, :version_or_higher => other_version)
158
      test.assert requires_redmine_plugin(:other, other_version)
158
    @klass.register :foo_plugin do
159
      test.assert requires_redmine_plugin(:other_plugin, :version_or_higher => '0.1.0')
160
      test.assert requires_redmine_plugin(:other_plugin, :version_or_higher => other_version)
161
      test.assert requires_redmine_plugin(:other_plugin, other_version)
159 162
      test.assert_raise Redmine::PluginRequirementError do
160
        requires_redmine_plugin(:other, :version_or_higher => '99.0.0')
163
        requires_redmine_plugin(:other_plugin, :version_or_higher => '99.0.0')
161 164
      end
162
      test.assert requires_redmine_plugin(:other, :version => other_version)
163
      test.assert requires_redmine_plugin(:other, :version => [other_version, '99.0.0'])
165
      test.assert requires_redmine_plugin(:other_plugin, :version => other_version)
166
      test.assert requires_redmine_plugin(:other_plugin, :version => [other_version, '99.0.0'])
164 167
      test.assert_raise Redmine::PluginRequirementError do
165
        requires_redmine_plugin(:other, :version => '99.0.0')
168
        requires_redmine_plugin(:other_plugin, :version => '99.0.0')
166 169
      end
167 170
      test.assert_raise Redmine::PluginRequirementError do
168
        requires_redmine_plugin(:other, :version => ['98.0.0', '99.0.0'])
171
        requires_redmine_plugin(:other_plugin, :version => ['98.0.0', '99.0.0'])
169 172
      end
170 173
      # Missing plugin
171 174
      test.assert_raise Redmine::PluginRequirementError do
......
181 184
  end
182 185

  
183 186
  def test_settings_warns_about_possible_partial_collision
184
    @klass.register(:foo) { settings :partial => 'foo/settings' }
187
    @klass.register(:foo_plugin) { settings :partial => 'foo/settings' }
185 188
    Rails.logger.expects(:warn)
186
    @klass.register(:bar) { settings :partial => 'foo/settings' }
189
    @klass.register(:other_plugin) { settings :partial => 'foo/settings' }
187 190
  end
188 191

  
189 192
  def test_migrate_redmine_plugin
190
    @klass.register :foo do
193
    @klass.register :foo_plugin do
191 194
      name 'Foo plugin'
192 195
      version '0.0.1'
193 196
    end
194 197

  
195
    assert Redmine::Plugin.migrate('foo')
198
    assert Redmine::Plugin.migrate('foo_plugin')
196 199
  end
197 200
end
198
-