undefined method `destroy_user_session_path' for active admin with cancancan and sorcery - activeadmin

HI I am working on rails 4.2.4 app and i am using sorcery for authentication, cancancan for authorization.. so far so good i can login and users can do as well .... I am trying to add activeadmin for admin dashboard I so far set up almost everything but when i fire up the link http://localhost:3000/admin when logged in the app as admin i get the error :
undefined method `destroy_user_session_path' for
:ActiveAdmin::Views::TabbedNavigation
here are my modules:
Activeadmin.rb
ActiveAdmin.setup do |config|
config.site_title = "title goes here"
def authenticate_user!
if !current_user.admin?
redirect_to new_user_session_path
end
end
config.authentication_method = :authenticate_user!
config.current_user_method = :current_user
config.logout_link_method = :delete
config.logout_link_path = :destroy_user_session_path
config.batch_actions = true
config.authorization_adapter = ActiveAdmin::CanCanAdapter
config.localize_format = :long
end
ability.rb
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
if user.admin?
can :read, ActiveAdmin::Page, :name => "Dashboard"
can :manage, :all
elsif user.client?
can :manage, [Act, Do, Fact, Task, T]
cannot :read, ActiveAdmin::Page, :name => "Dashboard"
else
can :read, Activity
end
can :manage, UserSessionsController do |user_session|
user == user_session
end
if user.active?
can :time, Activity
can :read, ActiveAdmin::Page, :name => "Dashboard"
end
can :log_in, User
can :log_out, User
can :reset_password, User
end
end
destroy in sessions controller
def destroy
authorize! :log_out, User
logout
redirect_to root_url, notice: I18n.t('users.log_out')
end
Can anyone point me on how to solve this .... been stuck here for a while ...
cheers

so after investigating further the correct way is
config.logout_link_path = :user_session_path
But sadly ActiveAdmin don't support urls with ids at logout path at the moment.
see this thread from the activeadmin owner

Related

Additional functionality on the End node

There is a mixin,
class AaTaskRelationMixin(object):
aa_task_comlete_function = None
that will be mixed to a flow. I want all flows in the end (when End node is activated) call a function in the attribute aa_task_complete_function
Found a simpler solution.
class AaTaskRelationMixin(object):
aa_task_comlete_function = None
aa_task_comlete = flow.Handler(
handler=this.aa_task_comlete_function,
).Next(this.end)
end = flow.End()

Store and access elements between pages navigation

I'm new to watir and page objects.
I have defined two pages, SearchPage and ReportsPage; On SearchPage I have button reports, I clicked on that and ReportPage was opened, I want to be able to use an element value from SearchPage on ReportsPage for making some assertions.
How can I store a value from page SearchPage and use it on ReportPage?
I have SearchPage defined like that:
class SearchPage < Browser
URL = "http://localhost:3000/"
def open
#browser.goto URL
self
end
def reports_link
#browser.link(href: '/reports')
end
def name_field
#browser.div(class: 'M0Z8m _1_jJ7')
end
And ReportsPage:
class ReportPage < Browser
URL = "http://localhost:3000/reports"
def report_value
#browser.element(class: '_1CV_I')
end
end
And Browser page defined like that:
class Browser
def initialize(browser)
#browser = browser
end
end
I click on reports link like this on a step :
Given (/^I navigate to application$/) do
#searchPage = SearchgPage.new(#browser);
#searchPage.open; sleep 1
end
When (/^I click on reports$/) do
#search_page.reports_link.click
ReportPage was loaded and on Then step I'll need value of field name_field from SearchPAge. How can I access that value because with #search_page is not working as it is expected, as that page is not loaded any more.

Replace all in a specific folder

In my Test Plan I have two folders. One with all my active test cases and one with all my archived test cases. I need to replace a lot of 'Affected Module' from one value to another, however - I don't want the folder with archived to be affected by this.
So, is there a way of doing search and replace only on a specific folder (and all the sub-folders) in HP ALM?
As far as I know the search and replace function in grid view replaces all instances of the value so I can't use that directly.
Here is a simple OTA code that updates the field ts_user_04 for all the test case in folder Subject\Automated and its sub-folder from whatever value to Quoting.
Please, change the column name as per your requirement. You can easily find the DB column for any field in HP ALM by going to the Management tab if you have access to it. Even otherwise you can get all the mapping by using OTA. (I hope you have the necessary access)
Inorder to run the OTA code, you need to install ALM Connectivity add-in which you can get it from the tools section in your ALM home page
Public TDconnection
Public reqPath
Public testPath
'Call the main Function
updateAllTests
Public Function login()
Dim almURL, almUserName, almPassword, domain, project
almURL = "https://.saas.hp.com/qcbin/"
almUserName = ""
almPassword = ""
domain = ""
project = ""
testPath = "Subject\Automated" ' Change it as per your folder structure
Set TDconnection = CreateObject("tdapiole80.tdconnection")
TDconnection.ReleaseConnection
TDconnection.InitConnectionEx almURL
TDconnection.login almUserName, almPassword
TDconnection.Connect domain, project
End Function
Public Function updateAllTests()
login
Set TreeMgr = TDconnection.TreeManager
Set TestTree = TreeMgr.NodeByPath(testPath)
If Err.Number = 0 Then
Set comm = TDconnection.Command
comm.CommandText = "update test set ts_user_04='Quoting' where ts_test_id in (select ts_test_id from test, all_lists where ts_subject in (select al_item_id from all_lists where al_absolute_path like (select al_absolute_path from all_lists where al_item_id=" & TestTree.NodeID & ") || '%' ) and ts_subject = al_item_id)"
comm.Execute
End If
logout
MsgBox "Flag Update successful", vbInformation
End Function
Public Function logout()
TDconnection.Disconnect
TDconnection.logout
TDconnection.ReleaseConnection
Set TDconnection = Nothing
End Function

How to use modules to split very long code in active admin?

Activeadmin registers a page on a single file, in which it has all the logic: Index, Show, Edit, etc.
I would like to split, let's say, task.rb into task_index.rb, task_show.rb, task_edit.rb, etc.
So, how should you do that?
NOTE: I know that making an ActiveAdmin.register block in each file (it appends if Task exists) will do the work, but this question aims for a general approach rather than solving this specific inquiry.
-- admin/task.rb
#encoding: utf-8
ActiveAdmin.register Task do
[Lot's of actions]
member_action....
member_action....
member_action....
batch_action....
[Index stuff]
filter....
scope....
scope....
scope....
index do
column...
column...
column...
column...
end
[Edit stuff]
form do |f|
f.input....
f.input....
f.input....
f.input....
f.input....
end
[etc etc etc]
end
----------------
I'm thinking of modules, but I can't figure out how to.
That is how I do this
module source
module ResourceDSL
module ActsAsClone
def acts_as_clone
controller do
def new
instance_variable_name = active_admin_config.resource_class.to_s.underscore
resource = active_admin_config.resource_class.find(params[:id]) rescue nil
attrs = resource.nil? ? {} : resource.attributes
resource = active_admin_config.resource_class.new(attrs)
instance_variable_set("##{instance_variable_name}", resource)
end
end
action_item :only => [:show, :edit] do
if can? :create, resource and (!resource.respond_to?(:live?) or resource.live?)
link_to "Copy", :action => :new, :id => resource.id
end
end
end
end
end
including to ActiveAdmin::ResourceDSL
ActiveAdmin::ResourceDSL.send :include, ResourceDSL::ActsAsClone
And then you can
ActiveAdmin.register Account do
menu :parent => "Billing", :priority => 10
acts_as_clone
end

DatabaseCleaner strategy transaction is not working

In My env.rb
Before do
DatabaseCleaner.strategy = :transaction
end
Also created a hook in my shared_steps.rb
Before('#database_cleaner_before') do
DatabaseCleaner.start
end
After('#database_cleaner_after') do
DatabaseCleaner.clean
end
In My feature file
#database_cleaner_after #database_cleaner_before
Scenario: I can sign up with a new valid "Email" and "Username"
When I enter a new valid "Email"
And I enter a new "Username"
And I enter a "Password"
And I click on the "Sign up" button
Then I should see a message with word "Signed Up" and "Successfully"
I am using gem:
Capybara 2.0.2
cucumber 1.2.1
database_cleaner 0.9.1
selenium-webdriver 2.30.0
cucumber-rails 1.3.0
Rails 3.1.0
In my database.rb
require 'active_record'
class ActiveRecord::Base
mattr_accessor :shared_connection
##shared_connection = nil
def self.connection
##shared_connection || retrieve_connection
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
DatabaseCleaner.strategy = :trancation is working fine (delete all record from database) but DatabaseCleaner.strategy = :transaction is not rolling back my database record why?. Am I missing somethings?

Resources