My blog has moved!
You should be automatically redirected in 5 seconds. If not, visit http://samueladesoga.wordpress.com and update your bookmarks.

Wednesday 22 December 2010

Rails3 'link_to' displays literal HTML on front end

In the last month, I have been working on a rails3 app and I ran across this interesting problem where I need to create a href link to a another page from my current page.

In my view i have written

<%= "Please click on this link #{link_to('here', new_house_path)}" %>

And interestingly this is displayed as

Please click on this link <a href="http://localhost:3000/houses/new">here</a>

on the front end.

Hours of frustration and google searches leads me to doing this:

<%= ("Please click on this link #{link_to('here', new_house_path)}").html_safe %>;

which then is displayed correctly on front end

Please click on this link here

if that isnt clear enough, the trick is you need to wrap the string with a 'html_safe' method

Off i go to learn more stuff .....

Tuesday 12 October 2010

Installing mysql on snow leopard

I have always struggled with install mysql on my snow leopard, as a result i have decided to keep a link on this blog for this:

http://www.icoretech.org/2009/08/install-mysql-and-mysql-ruby-gem-on-snow-leopard-64-bit/


Hopefully that link would be up for a very long time and i hope it is useful for someone else as well.

Friday 3 September 2010

A tester's reflection on kanban plus BDD

So i have just finished an engagement with a client where the development process used include
kanban and BDD. Kanban for us meant that we give priority to work on the right side of the board.
So as a tester, I would rather spent my time doing some manual testing on a story that is in the QA queue, than writing automated acceptance tests for a stroy in the queue for Accetance Tests.

Maybe it would be worth while to draw a representation of the way in which work flows through our kanban board

Analyis > Queue > Accetance Tests in Progress > Queue > Dev in progress > Queue > QA in progress > Smoke Test > Queue > UAT Deployment in progress > Queue > UAT in progress > Queue > Live Deployment in Progress > Deployed.

The good thing is that everyone in the team has a visibility of work up till deployment. For more information, read up kanban

The BDD framework used was Cucumber + Watir + Rspec, and developers would only start developing software when the tests have been written for the acceptance criteria. (Acceptance criteria is written by Analysts in a text editor in the cucumber format). The acceptance tests is jointly owned by developers and testers. If as a tester i am busy doing some other tasks further down in the work flow, the developers were happy to write the failing automated test for the acceptance criteria before development commences.

As a result of these good practices:

1. The team was always in good spirit and which improves the effectiveness
2. The number of defects raised was low, this was achievable because for a developer to move a story to the QA queue, the automated acceptance criteria must have been passing.
3. There wasnt a defect management system because testing is carried as close to the development time, and if the business believes the defect is critical to the functionality, the functionality of story does not progress further in the kanban board, but it is blocked until fixed and verified.

One downside is that because we wrote acceptance test for virtually every functionality that is testable, the acceptance test grew so quick that the time taken increased from about 20mins to about 1.40mins and this time kept growing. A side defect of this is that feedback time increased and as a result developers would not run the complete test suite before checking their code in. This was however managed by doing some exploratory manual testing around the functionality being developed.

All in all, it was a good experience for me and i just hope i get to work on more projects such as this.

Friday 25 June 2010

Watir: Search for elements on page using multiple attributes

I ran into a situation today where i wanted to scan through a page and return a table based on the table matching 3 attributes

Before:

browser.tables.find do |table|
table.class_name == 'my_class_name' and
table.cell(:class, 'class_1_name').text == 'some_text_1' and
table.cell(:class, 'class_2_name').text == 'some_text_2'
end

This was taking about 3minutes as there were about 86tables on this page under test. I was worried but the tables on this page was gonna increase with time which meant the time for this stage of the test was bound to increase.

In my search for how to search for a single table using multiple attributes:

I found this:

After:

browser.table(:class => 'my_class_name', :text => /#{'some_text_1}/, :text => /#{'some_text_2}/)

Believe it or not, i got my test time reduced to 3secs, awesome isnt it?

Enjoy!!!!!!

Friday 23 April 2010

Implement 'Select column_name from table_name where condition' in Active Record

I need an array from the data contained in a particular database column based on a condition, so i get the array of active record rows:

array_of_rows = TableName.find(:all, :conditions => {:column_name => ['col_data1','col_data2']})

Then use the array map! function to replace the active record objects with the column_name value
array_of_rows.map!{|item| item.column_name}

Doing some search got me:

array_of_rows = TableName .find(:all,:select=>'column_name' :conditions => {:column_name => ['col_data1','col_data2']}).map(&:column_name)

And i like this better, concise ....
update:

I've had to update the active record query above by removing the :select option

array_of_rows = TableName .find(:all, :conditions => {:column_name => ['col_data1','col_data2']}).map(&:column_name)

This is because if i have a method

def find_some_data
TableName .find(:all,:select=>'column_name' :conditions => {:column_name => ['col_data1','col_data2']})
end

I am able to do:

find_some_data.map(&:column_name)

but i cannot do

find_some_data.map(&:another_column_name)

throws: missing attribute: another_column_name (ActiveRecord::MissingAttributeError)

because i have only retrieved 'column_name' values from the table

In other to be able to create any array composed of data from any column_name, i have

def find_some_data
TableName .find(:all, :conditions => {:column_name => ['col_data1','col_data2']})
end

Tuesday 6 April 2010

Active Record find by Column Name

In recent days been doing a lot of ruby, which means i tend to use Active Record as well.

I had written some scripts where i was selecting records that matched a criteria such as:

@table1.table2s.select{|e| e.column_name == 1234}

but as i need to sort my result and also give some more conditions to filter the data, i need alternatives to this above query and i ended up with the two lines of code below:

@table1.table2s.find(:all, :conditions => {:column_name => 1234})
@table1.table2s.find_all_by_column_name(1234)

Please note that the two lines above does same thing, the second one is just a lil but shorter and more readable the the 1st one.

using the second one i can now do stuff like

@table1.table2s.find_all_by_column_name(1234, :order => "col_2 ASC")

which would order my results based on the column that i have specified and i could have ASC - ascending and DESC - descending.

I have learnt something else today .... Have you?

Saturday 27 March 2010

Fixing the annoying XP Antivirus 2009 OR 2010

This is not a post directly related to my blog but i am sure there are few people out there that might be facing same issues. In the last one week i had friends whose windows machines have been infected the XP Antivirus 2010, which seems to be a clone of XP Antivirus 2009. The symptoms include that you are get annoyings popups asking you to pay for an antivirus, i hope you have exposed yourself already.

There are so many ways to fix this problems.

The first one is a biased solution, which is ditch your windows machine and buy a macOsx or format your machine and install ubuntu. Well i guess that wouldnt be a popular option.

So i have an alternative:

1. Install Malwarebytes, it is quite a good tool to remove malware from your machine.
You would notice that it would detect quite a number of malware, make sure after the full scan, you remove all the infections detected.

You are also gonna notice that, .exe files would not work after you have deleted the threats discovered by Malwarebytes.

2. To fix .exe files not working, follow the steps described below.

Have the following text copied into a notepad :-

------Start --------Do not copy this line, copy starting next line ----------------

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.exe]
@="exefile"
"Content Type"="application/x-msdownload"

[HKEY_CLASSES_ROOT\.exe\PersistentHandler]
@="{098f2470-bae0-11cd-b579-08002b30bfeb}"

[HKEY_CLASSES_ROOT\exefile]
@="Application"
"EditFlags"=hex:38,07,00,00
"TileInfo"="prop:FileDescription;Company;FileVersion"
"InfoTip"="prop:FileDescription;Company;FileVersion;Create;Size"

[HKEY_CLASSES_ROOT\exefile\DefaultIcon]
@="%1"

[HKEY_CLASSES_ROOT\exefile\shell]

[HKEY_CLASSES_ROOT\exefile\shell\open]
"EditFlags"=hex:00,00,00,00

[HKEY_CLASSES_ROOT\exefile\shell\open\command]
@="\"%1\" %*"

[HKEY_CLASSES_ROOT\exefile\shell\runas]

[HKEY_CLASSES_ROOT\exefile\shell\runas\command]
@="\"%1\" %*"

[HKEY_CLASSES_ROOT\exefile\shellex]

[HKEY_CLASSES_ROOT\exefile\shellex\DropHandler]
@="{86C86720-42A0-1069-A2E8-08002B30309D}"

[HKEY_CLASSES_ROOT\exefile\shellex\PropertySheetHandlers]

[HKEY_CLASSES_ROOT\exefile\shellex\PropertySheetHandlers\PEAnalyser]
@="{09A63660-16F9-11d0-B1DF-004F56001CA7}"

[HKEY_CLASSES_ROOT\exefile\shellex\PropertySheetHandlers\PifProps]
@="{86F19A00-42A0-1069-A2E9-08002B30309D}"

[HKEY_CLASSES_ROOT\exefile\shellex\PropertySheetHandlers\ShimLayer Property Page]
@="{513D916F-2A8E-4F51-AEAB-0CBC76FB1AF8}"

-----------End--------------Do not copy this line. Copy till the end of previous line------------

Boot the computer in safe mode with networking

- Usually by tapping F8 when the computer boots up

Open My Computer, Click on tools and then folder options.

Select - "Show hidden files and folders"
- Uncheck "Hide protected operating system files"

Apply and then OK

For XP :-

5. Navigate to C:\Documents and Settings\%userprofile%\Local Settings\Application Data
Look for either of the following files :-

- av.exe
- msascui.exe

And delete these files .... Hopefully these should have been removed by the malwarebytes.

Now open the notepad file saved on your desktop earlier

Click on file-> save as

- Select file type as all files
- Name the file as fix.reg
- Encoding should be Unicode
Run that file, it will edit the registry accordingly

Now restart the computer in normal mode and everything should working fine.

Wednesday 10 March 2010

Blank cells in step tables in cucumber 0.3.11 is represented as nil

In my current job, I have been doing a lot of acceptance test using Cucumber, Watir and RSpec, obvious all in Ruby. I have been using Cucumber 0.6.x, in which blank cells in the step table are represented by empty string (""). This was okay for me until today when i had to use a previous version of Cucumber 0.3.11 due to reasons including compatibility with other projects in the CI build. And my tests start failing because blank cells are represented as nil.

There was fix put in the current release of cucumber to change blanks to be represented as empty and not as nil(for whatever reason, which i don't really care, as both nil and "" has got its own arguments.)

Some code to explain this, Assuming i have a step table as below:

Given that i have the following detail in my app
|Header1|Header2|Header3|Header4|
|Body1 |Body2 |Body3 | |

Notice that the last column of the second row is blank, this would be represented as nil in cucumber 0.3.11 while it is represented as empty string "" in cucumber 0.6.x

In my step definition file, I have fixed this by converting every nil value to empty ("")

Given /have the following detail/ do |table|
table.rows.each do |row|
row.map! {|value| convert_nil_to_empty_string(value)}
# do some other stuff with row as every nil object has been converted to empty string
# The map! method for Array, allow you to invoke the block for the array and it amends
# the existing array
end
end

The method which i call to convert nil to empty is below:

def convert_nil_to_empty_string(test_string)
if (test_string.nil?)
return ""
else
return test_string
end
end

There might have been a better way to do this but this surely worked for me in this scenario and the reason i decided to use a method was that the map! method would only allow me use the variable "value" only once in the block. I am sure there are some rubyist out there, that could advice me on some shorthand for this ....... Hope it helps you too

Wednesday 24 February 2010

selenium.open timeouts for strange reasons

Have you ever been in situations when your selenium RC test times out after the selenium.open command, the page is loaded but selenium just tells you that it has timed out after 30000ms.

I had same problem in Java today when i got the selenium RC 1.0.3 and i fixed the problem by setting the selenium timeout to be "0". so i have done

@BeforeClass
public void setUp(){
selenium = new DefaultSelenium("localHost", 4444, "*iexplore", url);
selenium.start();
selenium.setTimeout("0");
}

and then i have used a waitForPageToLoad in each of the selenium methods that needs to wait - open, click .....

selenium.open(url);
selenium.waitForPageToLoad("5000");

selenium.click("btnG");
selenium.waitForPageToLoad("5000");


Hopefully you find this useful.

Monday 11 January 2010

Regex for pipe "|" character

I was trying to split a string using a regex today and i had this problem

my string of format

A | B | C

My intent was to split this string using the Regex match for "|"

The regex that worked for me was "\\|" - escaping pipe and then escaping the slash the escapes the pipe