Closed kzr-pzr closed 6 years ago
Hello @kzr-pzr, this is a nice feature, I will check it out soon. Do you think you can also write a test for this?
Sure. Can you just point me out to some example test in the project, please? I'm not very familiar with Ruby, nor Rails so I'd like to see a quick how-to.
Sure, you can write a test like this one: https://github.com/ixti/redmine_tags/blob/master/test/functional/issues_controller_test.rb#L81-L94.
You might want to also play around with tag and tagging fixtures, they are located here: https://github.com/ixti/redmine_tags/tree/master/test/fixtures.
And here is the documentation for the assert_select
function: https://apidock.com/rails/ActionController/Assertions/SelectorAssertions/assert_select.
Not sure exactly how you can get the background color of an element, but I believe you can inspect the element like the following:
require 'pry'
assert_select '.tag-label-color' do |element|
pp element.inspect
binding.pry
end
And maybe figure something out based on the output or the debugger.
I finally had some spare time so I tried to write a test but I can't make it fail.
The test is literally just a raise so I can see failing it first:
def test_tags_with_contrast_colors
raise "this is my first test"
end
Unfortunatelly, when I run
rake redmine:plugins:spec RAILS_ENV=test NAME=redmine_tags
the output is just a couple warnings and then a few report lines stating:
............................ Finished in 8.5 seconds (files took 2.85 seconds to load) 28 examples, 0 failures
The number of "examples" is the same and no error is raised no matter if I include my test in the code or comment it out. It seems to me my code is not run at all.
I tried to look up a Rails testing guide (I'm mostly Java programmer) but they use bin/rails test
to run tests. That command just fails with rake test
as a suggestion. When I run rake test:functionals TEST=test/functional/issues_controller_test.rb
it runs 371 tests which all fail as errors and again the number of tests is not changed when I include my dummy test in the IssuesControllerTest
.
On top of all that I cannot find any report except the tmp/coverage
report which does not state what test were run.
So, I'm doing something wrong, but I cannot figure out what it is. Your help would be appreciated, @sdwolf.
It sounds like you added the test inside the test
directory, but the redmine:plugins:spec
runs the tests from the spec
directory.
Try the following command:
rake redmine:plugins:test RAILS_ENV=test NAME=redmine_tags
I tried it and it failed, because I'm using it against latest PostgresSQL 10.1 and it doesn't work with Rails 4.2 out of the box (it was backported to version 4.2 but I assume Redmine developers didn't include it yet in their release). There seems to be a way how to patch older Rails versions but I'm not sure if you are interested in doing things that way, so I'll probably switch my Postgres to some 9.x version and try it again in a couple days.
It is a nice improvement, thanks for the PR.
It's hard to read tags with light background colors and white text. This patch uses YIQ method to set text color to black or white, depending on which is the more contrasting to the background color.
The formula for YIQ was taken from a blog post by Brian Suda.
Slovak translation file is also included.