I want to create a Project Custom Field in a plugin. Although running "rake redmine:plugins:migrate RAILS_ENV=production" appears to apply the migration, the project custom field is not created. Here is the migration:
Update: (can't answer my own Question so I'll fix the post with the answer).
class PopulateCustomFields < ActiveRecord::Migration
def self.up
ProjectCustomField.create(:name => 'Estimated time units'; :field_format => 'list', :possible_values => ['Hours', 'Points'], :default_value => 'Hours', :is_required => true, :editable => true, :visible => true)
end
(I previously had the wrong syntax for :possible_values, I was using {} instead of [], but no error was reported ).
I believe you have a typo after 'Estimated time units'. Replace the ';' by ','.
You can test your plugin migration script by installing/removing the plugin using the following commands:
for installing the plugin:
rake redmine:plugins:migrate RAILS_ENV=production
for uninstalling the plugin:
rake redmine:plugins:migrate NAME=plugin_name VERSION=0 RAILS_ENV=production
Check the official documentation for further details.
An example migration script could be like this:
class PopulateCustomFields < ActiveRecord::Migration
# method called when installing the plugin
def self.up
if CustomField.find_by_name('A New Custom Field').nil?
CustomField.create(name: 'A New Custom Field', field_format: 'text')
end
end
# method called when installing the plugin
def self.down
CustomField.find_by_name('A New Custom Field').delete unless CustomField.find_by_name('A New Custom Field').nil?
end
end
Check on the redmine database if the custom field 'A New Custom Field' of type 'text' is correctly added/removed when installing/uninstalling the plugin. Also, check that each step has no output errors (see the redmine log as well).
Related
I have created a method in controller where i have used action mailer for sending email.I want that method to be executed after every 12 am at night and email to be send to the person who is having a birthday on that day.
Create rake task under lib folder.And add whenever gem to execute rake task at every 12 am.
In lib folder
create a class
class Notification
def self.send_greetings
# give here your own logic to find users with birthday
users = User.all
users.each do |user|
UsersMailer.weekly_mail(u.email).deliver
end
end
end
setup whenever gem
every :day, :at => '12:00am' do
runner "Notification.send_greetings", :environment => 'development', :output => 'log/cron.log'
end
Seeing many question related to this but none of them gives answer to my problem.
I have Rails api application without ActiveRecord support. It is easy to reproduce problem. Follow steps:
Create rails api site without ActiveRecord support
rails new test001 -O --api
Change folder to test001 and run:
rails g scaffold testapp id name
Create model file testapp.rb in app/models folder
class Testapp
include ActiveModel::Model
attr_accessor :id, :name, :created_at, :updated_at
def self.all
t1 = Testapp.new(:id =>111, name: "t111")
return [t1]
end
end
Start server
rails s
Using postman REST client create GET request
http://localhost:3000/testapps.json
It fails with error ActionView::Template::Error (No route matches {:action=>"show", :controller=>"testapps", :format=>:json, :id=>#<Testapp:0x00000005411518 #id=111, #name="t111">} missing required keys: [:id]):
I have dummy implementation for POST, PUT, GET 1 item and all works. Here is dummy implementation of GET 1 item (/testapps/x.json)
def self.find(p)
return Testapp.new(:id =>p, name: "t123")
end
What is the problem with GET all (/testapps.json)?
Found solution.
Problem is scaffold generated index.json.jbuilder
file:
json.array!(#testapps) do |testapp|
json.extract! testapp, :id, :id, :name
json.url testapp_url(testapp, format: :json) #REMOVE
end
It added line json.url testapp_url(testapp, format: :json) for no reason. json.extract! deserialized object already.
Removing line solved problem.
I still do not know why testapp_url(testapp, format:json) caused error. Checking Rails Routing document http://guides.rubyonrails.org/routing.html
I'm having weird issues with some of my feature tests using Capybara with poltergeist driver.
The test should perform a simple checkout in my online shop.
They all pass fine on my local MacBook as well as on an Ubuntu vagrant box. However on CI services like Codeship, Wercker or Semaphore they fail with the very same error.
My spec:
require 'rails_helper'
describe 'Checkout' do
let!(:product) { FactoryGirl.create(:product) }
it 'checks out via CreditCard', js: true do
visit products_path
expect(page.body).to have_link('Test Product 1')
click_link('Test Product 1')
#rest of spec ommitted
end
end
The error I get on CI is:
2) Checkout checks out via CreditCard
Failure/Error: click_link('Test Product 1')
Capybara::ElementNotFound:
Unable to find link "Test Product 1"
To me this is super weird, as the first expectation 'expect(page.body).to have_link('Test Product 1')' seems to pass but then it fails on the next step where it should actually click the link it just assured to be present on the page?
I then reconfigured poltergeist driver as follows to gather more debug information.
Snippet of rails_helper.rb:
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {js_errors: false,
#inspector: true,
phantomjs_logger: Rails.logger,
logger: nil,
phantomjs_options: ['--debug=no', '--load-images=no', '--ignore-ssl-errors=yes', '--ssl-protocol=TLSv1'],
debug: true
})
end
Capybara.server_port = 3003
Capybara.app_host = 'http://application-test.lvh.me:3003' # lvh.me always resolves to 127.0.0.1
Capybara.javascript_driver = :poltergeist
Capybara.current_driver = :poltergeist
Capybara.default_wait_time = 5
Now I can see on CI console that the test successfully visits my products_path and the expected html page (including my the link it should click) is being returned.
I removed the rest of the HTML response to make it more readable:
{"name"=>"visit", "args"=>["http://application-test.lvh.me:3003/products"]}
{"response"=>{"status"=>"success"}}
{"name"=>"body", "args"=>[]}
{"response"=>"--- snip --- <div class=\"info\">\n<a class=\"name color-pomegranate\" href=\"/en/products/6\">\nTest Product 1\n</a>\n850,00 \n</div> --- snap ---"}
{"name"=>"find", "args"=>[:xpath, ".//a[./#href][(((./#id = 'Test Product 1' or normalize-space(string(.)) = 'Test Product 1') or ./#title = 'Test Product 1') or .//img[./#alt = 'Test Product 1'])]"]}
{"response"=>{"page_id"=>4, "ids"=>[0]}}
{"name"=>"visible", "args"=>[4, 0]}
{"response"=>false}
{"name"=>"find", "args"=>[:xpath, ".//a[./#href][(((./#id = 'Test Product 1' or contains(normalize-space(string(.)), 'Test Product 1')) or contains(./#title, 'Test Product 1')) or .//img[contains(./#alt, 'Test Product 1')])]"]}
{"response"=>{"page_id"=>4, "ids"=>[1]}}
{"name"=>"visible", "args"=>[4, 1]}
{"response"=>false}
The last two find actions repeat until Capybara reaches its timeout, then the test fails.
I double checked the xpath Capybara uses via some online xpath validators, but as expected it matches the HTML link.
I also used capybara-screenshot gem to dump the HTML body on failure and the link in question is also present.
So why is the test still failing?
Is there any race condition that I'm not aware of? Why is it passing locally but on none of the CI services?
Here are my gem version:
capybara (2.4.4)
capybara-screenshot (1.0.3)
database_cleaner (1.3.0)
factory_girl (4.5.0)
factory_girl_rails (4.5.0)
poltergeist (1.5.1)
rails (4.1.8)
rspec (3.1.0)
rspec-rails (3.1.0)
and phantomjs 1.9.7
While I can't reproduce this, I remember having this problem before. I believe your line:
expect(page.body).to have_link('Test Product 1')
is passing because the link is literally on the body of the html page, even though it may be hidden due to CSS or JS behavior. However, the line:
click_link('Test Product 1')
definitely checks for visibility before clicking the link. You should check your spec_helper.rb configurations to make sure:
Capybara.ignore_hidden_elements = true
is present, so that the first line wouldn't pass. I think I also had to change the first line I mentioned to:
# Change page.body to page, to look at the rendered page, not the literal one
expect(page).to have_link('Test Product 1')
Once you do this, the first line blocks the thread and waits until the link becomes visible. Then the rest of the test will pass.
Hope this solves it.
I am trying to use Minitest in a fresh Rails 4 install. My understanding is that if I have a class that doesn't inherit from ActiveRecord then I should be able to use Minitest itself, without Rails integration:
#test/models/blog.rb
require "minitest/autorun"
class Blog < Minitest::Unit::TestCase
def setup
#b = Blog.new
end
def test_entries
assert_empty "message", #b.entries
end
#app/models/blog.rb
class Blog
attr_reader :entries
def initialize
#entries = []
end
I run the test with ruby test/models/blog.rb.
My problem comes with the setup method. If I don't include an entry for my blog, the tests fails with the message that there are the wrong number of arguments in setup. If I include an entry in my setup message #b = Blog.new entries: "Twilight", my test fails in the test_entries method because entries is an undefined method.
You have a couple problems. First, you are not requiring "test_helper", which means that rails isn't getting loaded when you run this test, which means that the mechanism rails uses to resolve missing constants isn't loaded. You will either need to require the helper or require the blog file directly. Second, you are overwriting the constant you want to test with the test, which is why you are getting confusing messages. Name the test class BlogTest instead to avoid this.
This is what I think you are trying to do:
require "minitest/autorun"
require "models/blog" # Assuming "app" is in your load path when running the test
#require "test_helper" # Or require this instead if you need to use DB
class BlogTest < Minitest::Unit::TestCase
def setup
#b = Blog.new
end
def test_entries
assert_empty #b.entries, "Blog entries should be empty"
end
end
i use the following gemfile:
gem 'spree_gateway', :github => 'spree/spree_gateway'
gem 'spree_auth_devise', :github => 'spree/spree_auth_devise', :branch => 'edge'
gem 'spree_theme_v1', :path => '../spree_theme_v1'
when using the last "spree_theme_v1" gem i created using the command "spree extension theme_v1", i can't browse the login and the account route anylonger. instead i get the following error message:
NoMethodError in Spree/user_sessions#new - undefined method `get_taxonomies' for
the error comes from the file views/spree/shared/_main_nav_bar.html.erb which i overwrite in my extension. as soon as i remove the file it works again. any advice, why this isn't working? or do i have to overwrite another file?
thanks!
The problem is that the gem is not loading the products_helper.rb from spree: https://github.com/spree/spree/tree/master/core/app/helpers/spree
You can make it work adding helper 'spree/products' to the controller that is failing (something about devise in your case).
I 'll show you my redefined PagesController from spree_essential_cms, maybe it helps:
class Spree::PagesController < Spree::BaseController
helper 'spree/products'
def show
...
end
end
As noted here http://osdir.com/ml/spree-user/2013-01/msg00053.html you can also make a decorator in app/controllers and call it something like add_products_helper_decorator.rb, and then fill it with this content:
[Spree::UserPasswordsController, Spree::UserRegistrationsController, Spree::UserSessionsController].each do |klass|
klass.class_eval do
helper 'spree/products'
end
end
That should be enough to require that helper into the right places and make it available for you.