Redmine project menu bar dissapeared when adding new plugin - ruby-on-rails

I am beginner in the development for Redmine. I created a plugin and added it into project menu. But when i clicked to this tab, it does not link to page I want and the project menu bar disappears. It's hard to control all activities on project management. What should i do?
This is code in my init.rb file:
permission :project_plan, { :project_plan => [:index,:show] }, :public => true
menu :project_menu, :redmine_project_plan, { :controller => 'project_plan', :action => 'index' }, :caption => :project_plan_title

I think your problem is that you don't give the project_id as a param, the code above should look more like
permission :project_plan, { :project_plan => [:index,:show] }, :public => true
menu :project_menu, :redmine_project_plan, { :controller => 'project_plan', :action ='index' }, :caption => :project_plan_title, :param => project_id
And on the controller you need recue this information :
#project= params[:project_id]

Had the same issue with my Redmine plugin, after hours of digging and research found out what appears to be the issue. What is important is to update the #project variable with project id parameter passed into your show method. Here is my controller file:
class YearlyController < ApplicationController
unloadable
helper :issues
include IssuesHelper
def show
require_login
#project = Project.find(params[:project_id])
end
end
And init.rb file:
Redmine::Plugin.register :weekly do
name 'Weekly Plan plugin'
description 'Display weekly plan for current and previous week'
version '0.0.2'
menu :project_menu, :yearly, { :controller => 'yearly', :action => 'show' }, :caption => 'Roadmap Year', :after => :overview, :param => :project_id
menu :project_menu, :weekly, { :controller => 'weekly', :action => 'show' }, :caption => 'Weekly Plan', :after => :yearly, :param => :project_id
settings :default => { :weeklabel_name => 'Weekly Label' }, :partial => 'settings/settings'
project_module :weekly do
permission :view_weekly, :weekly => :show
permission :view_yearly, :yearly => :show
end
end

Related

Request in Rails Testing not returning body

I'm starting to do some testing to my app in rails, and following official tutorial, I've written this:
class UserFlowTest < ActionDispatch::IntegrationTest
def login
post ns_login_user_path, { :user => { :username => 'user', :password => 'password' } }
assert_response 200
end
test "should complete a flow" do
login
post create_participant_path(:event_id => events(:myevent).id), {
:format => :json,
:event_role => event_roles(:regular_participant).id,
:in_team => true
}
r = JSON.parse(response.body)
assert_response 200
puts "response creating participation #{r.as_json}"
participant_id = r[:participant_id]
end
end
It does the login OK, but after that, when trying to create the participant, response is a variable with no .body attribute, just the number 200 (the status), so the JSON.parse method crashes.
This is the relevant part of my routes.rb:
# Events
scope 'events', :controller => :events do
# some routes
scope ':event_id', :controller => :events do
# some routes
scope 'participants', :controller => :participants do
post '', :action => :create_participant, :as => :create_participant
# some routes
end
end
end
And the controller ParticipantsController.rb:
class ParticipantsController < ApiController
before_action :require_login, :only => [:create_participant, :update_participant]
# Creates a participation of a person in the event
# Receives the following params:
# - +event_id+
# - +in_team+::_boolean
# - +event_role+
def create_participant
# … some logic
if participant.save
render :status => :ok, :json => Hash[
:participant_id => participant.id,
:team_participant_id => participant.team_participant_id
]
else
render :status => 406, :json => Hash[
:message => t('alerts.error_saving'),
:errors => participant.errors.as_json
]
end
end
end
I've seen the full response object on controller specs, but looking at the code, it appears that the ActionDispatch::IntegrationTest code only returns the response.status, not the entire response object.
The documentation doesn't directly say that you can access the response object. You might try doing a render_views and see if that makes any difference, but based on inspection of the code, it doesn't seem like it will.

trying to do a query session for Parse

using the gem parse-ruby-client and im trying to do a query session, here is my code.
im just curious on how to implement most of the https://parse.com/docs/rest/guide. Also i dont know if i created a session to begin with? i think the gem does it automatically? not too sure
class LoginController < ApplicationController
def index
end
def log_in
user = Parse::User.authenticate(params[:user][:username], params[:user][:password])
#username = params[:user][:username]
rescue Parse::ParseProtocolError
redirect_to :controller => "login"
end
def logout
Parse.client.post("https://api.parse.com/1/logout", {})
rescue Parse::ParseProtocolError
redirect_to :controller => "login"
end
def query_session
Parse.client.post("https://api.parse.com/1/users/", {})
end
end
here is log_in.html.erb
<h4>You are logged in as: <u><%= #username %></u></h4>
<%= link_to "logout", :controller => "login", :action => 'logout' %><br>
<%= link_to "test", :controller => "login", :action => 'query_session' %>
routes.rb
Rails.application.routes.draw do
root 'login#index'
get 'login/log_in' => 'login#log_in'
post 'login/log_in' => 'login#log_in'
get 'login/logout'
get 'login/query_session' => 'login#query_session'
end
this is my parse.rb
require 'parse-ruby-client'
Parselogin::Application.configure do
config.parse = Parse.init :application_id => 'APIKEY',
:api_key => 'APIKEY'
end
i get back this error when i click on 'test' button from the log_in.html.erb
201: missing user password
You are missing the initialization of the Parse.client. This is an example from the gem's official documentation.
require 'parse-ruby-client'
client = Parse.create :application_id => '<your_app_id>',
:api_key => '<your_api_key>',
:quiet => true | false
To use the client later on, do the actions like this.
client.post("https://api.parse.com/1/logout", {}), where client is the variable from 1st snippet.
In order to respond to the second part of your question, please consider the gem's documentation.

RSPEC how to post to a controller? What's wrong with this?

I'm trying to post to my controller in RSPEC, see anything wrong with this? It's failing w/o error:
it "should store create an IncomingMail record" do
lambda {
post 'create', {
"from" => 'XXX',
"to" => 'XXX',
"cc" => 'XXX',
"subject" => 'XXX',
"message_text" => 'XXX',
"message_html" => 'XXX' }
}.should change { IncomingMail.count }.by(1)
end
Updated:
it "should store create an IncomingMail record" do
post :create,
:from => 'xx',
:to => 'xx',
:cc => 'xx',
:subject => 'xx',
:message_text => 'xx',
:message_html => 'xx'
mail = IncomingMail.last(:order => 'created_at desc')
mail.from.should == 'xx'
end
Controller
class IncomingMailsController < ApplicationController
require 'iconv'
#make sure that rails doesn't raise an exception because we have no way of knowing the token
skip_before_filter :verify_authenticity_token
def create
begin
#incoming_mail = IncomingMail.create(
:from => params[:from],
:to => params[:to],
:cc => params[:cc],
:subject => params[:subject],
:message_text => message_text_utf8,
:message_html => message_html_utf8
)
.....
This is how i do it :
Route Example :
post 'train_ability/:ability' => :train_ability, :as => 'train_ability'
Spec :
it "should increase the strength ability by one point and also update the strength_points by one if strength is the trained ability" do
#user.str = 10
#user.str_points = 0
#user.save!
post :train_ability, :ability => 'str'
#user.reload
flash[:error].should be_nil
#user.str_points.should == 1
#user.str.should == 11
end

Rails 3 > Rendering views in rake task

I'm stuck with a rake task that need to prepare a newsletter for Mailchimp.
Using rails 2.x stuff googled I now have this code:
desc "Sends newsletter to Mailchimp list"
task :send_newsletter => :environment do
begin
# get render helpers
av = ActionView::Base.new(Rails::Application::Configuration.new(Rails.root).view_path)
av.class_eval do
include ApplicationHelper
end
things = Stuff.do.things
h = Hominid::Base.new({:api_key => "xxx"})
h.create_campaign(
{
:list_id => "xxx",
:subject => "Hey...",
:from_email => "xxx",
:from_name => "xxx",
:to_email => "",
:auto_footer => true,
:generate_text => true
},
{
:html => av.render(:template => "stuff/newsletter", :locals => {:things => things}, :layout => false)
},
"regular")
rescue Exception => e
STDERR.puts ">>> #{e.to_yaml}"
end
And I get this error message: "undefined method `virtual_path' for false:FalseClass"
My first try was with render_to_string but I just can't access as it is in the controller not the view.
Any help would be greatly appreciated :)
:layout => nil ?

How do I mix nested resources with multiple post values when testing Rails controllers?

I have a model called "Post" which is a nested resource under a model called "Project" and I'm trying to test the controller. The code works find in my browser, but I can't get it to work in the test. Here's the test
context "on POST to :edit" do
setup do
post( :edit,
:project_id => #project1.to_param,
:id => #post1.to_param,
:post => { :title => 'new title', :text => 'other text' }
)
end
should_assign_to :post
should_assign_to :project
should_respond_with :success
should "update post values" do
assert_equal 'other text', assigns['post'].text
end
Any idea how I'm screwing this up?
This was the result of me not understanding Rails' REST architecture -or- the post syntax. I should have been using PUT instead of POST, and the call should have looked like this:
context "on PUT to :update" do
setup do
put :update, {
:project_id => #project1.to_param,
:id => #post1.to_param,
:post => { :title => 'new title', :text => 'other text' }
}
end
should_assign_to :post
should_assign_to :project
should_respond_with :success
should "update post values" do
assert_equal 'new title', assigns['post'].title
assert_equal 'other text', assigns['post'].text
end
end
I had been using the wrong syntax because for some reason it was still handling my nested id's correctly.

Resources