Hi Enrico. Thanks for checking out my post. I was using Radiant 0.6.9 for that project, so what I'm about to say won't be exactly what you need. But it might point you in a useful direction.
First of all, I wasn't creating the user in the login step. I used fixtures... then I started using Scenarios (not Cucumber scenarios, but another plugin that provides a sort of enhanced version of fixtures, which was used in Radiant 0.6.9). For Radiant 0.7 you'll want to use Dataset, the successor to Scenarios. Presently in my_extension/features/support/env.rb I have this code: require 'scenarios' [ '../../../../radiant/spec/scenarios', '../../spec/scenarios' ].each do |path| Scenarios::load_paths.unshift(File.expand_path(path, File.dirname(__FILE__))) end Scenarios::load :features That loads Radiant's scenarios (including the Users scenario), and my own. It assumes you have the extension inside a Radiant project, and you've copied Radiant into your project with 'rake radiant:freeze:gems' or 'rake radiant:freeze:edge'. I think I used Radiant's Users scenario because they've already done the fiddling to make users that are valid and can be logged in. For 0.7 it may be as simple as replacing 'scenarios' with 'dataset' (for the require and the module) or 'datasets' (the spec subdirectory). But it may not. For login in my Cucumber features, I have my_extension/features/step_definitions/session_steps.rb: Given /I am logged in as "(\w+)"/ do |name| visit '/admin/login' fill_in 'Username', :with => name.downcase fill_in 'Password', :with => 'password' click_button 'Login' end # Log in as a user with no particular role Given /I am logged in\s*$/ do Given 'I am logged in as "Existing"' end ... so that when describing features I can use # for any kind of user Given I am logged in # for special users Given I am logged in as "Admin" Given I am logged in as "Developer" Hope this helps. For more hints, my code is actually on github, although the extension itself is embarrassingly unfinished: http://github.com/eostrom/radiant-locations-extension --Erik On Wed, Mar 11, 2009 at 10:51 PM, Enrico Teotti <enrico.teo...@gmail.com>wrote: > Nice post Erik. I am wondering how did you get around the admin login? > I'm using this: > u = User.create! :name => 'Administrator', :login => 'admin', > :password => 'radiant', :password_confirmation => 'radiant' > visit("/admin/login") > fill_in("Username", "admin") > fill_in("Password", "radiant") > click_button "Login" > > but the outcome is always "Invalid username or password.". > > Cheers, > Enrico > > > 2009/2/14 Erik Ostrom <e...@echographia.com>: > > I'm doing what it says in the subject line, and I thought I'd post some > > notes and links. For those who don't know, Cucumber (http://cukes.info/) > is > > a BDD tool, successor to RSpec's story runner, that lets you describe > > desired behavior ("features") in something that looks like human > language, > > and then write the code that defines the behavior ("steps") in Ruby. > Webrat > > (http://github.com/brynary/webrat/tree/master) is an acceptance testing > tool > > that lets you write steps that emulate browser interaction - clicking > links, > > filling in forms - without the overhead of actually firing up a browser. > > You all know what Radiant is. > > > > (I'm working with Radiant 0.6.9, unfortunately, because I want my > extension > > to support an existing site. But I suspect the basic steps will apply to > > 0.7.) > > > > > > > > The basic setup went pretty quickly. The instructions for using Cucumber > > with Rails (http://wiki.github.com/aslakhellesoy/cucumber/ruby-on-rails) > go, > > roughly: > > > > - install a bunch of gems > > - create a Rails project (I already had a Radiant project) > > - run the cucumber generator > > > > In my case, script/generate didn't know about Cucumber, I guess because > > Radiant looks for generators in other places. So I created a new Rails > > project, ran the generator there, and copied the files that looked useful > > into my Radiant extension. I'm reconstructing this from the git commit - > it > > looks like the files were: > > > > - features/step_definitions/webrat_steps.rb > > - features/support/paths.rb > > - features/support/env.rb > > > > I modified env.rb in two ways: > > > > - The path to config/environment is three steps higher (../../../). > > - Load fixtures from spec/ (see > > http://wiki.github.com/aslakhellesoy/cucumber/fixtures). > > > > That was pretty much it - I'm now able to start writing features and > steps. > > > > > > > > There was one major hitch. I wrote a step definition that goes like > this: > > > > When /^I visit the "(.+)" admin page$/ do |page| > > visit page_edit_path(Page.find_by_title(page)) > > end > > > > ... and a feature that goes like this, in part: > > > > When I visit the "Anno Domini" admin page > > And I fill in "Address" with "366 So. First Street, San Jose, CA 95113" > > And I press "Save and Continue Editing" > > > > You can guess what that does. On the last step, when the form was > > submitted, I got the error "Couldn't find Page without an ID". The edit > > form, in the test environment only, was being created with > > action="/admin/page/edit" (note the missing page ID) instead of > > "/admin/pages/edit/3". > > > > Turns out that in the test environment, Radiant adds its own test > fixtures > > to the extension paths. If you're configured to load all extensions, > that > > will include BasicExtension, which sets up a default route that gets in > the > > way of page_edit_path, and probably a lot of other paths. > > > > For anyone else traveling this path, the way I got around this was to > ensure > > my extension was the only one loaded, by putting this line in > > config/environment.rb in my project: > > > > config.extensions = [ :locations ] if config.environment == 'test' > > > > There may be a better way, but this is probably good enough. Looking > > forward, I see that in 0.7, the route that caused the trouble is > commented > > out. > > > > > > > > Hope this is useful. When the extension is a little more functional, I > plan > > to put it up on Github, so there'll be some sample code. Meantime, Aslak > > Hellesoy's Ba extension (http://github.com/aslakhellesoy/ba/tree/master) > is > > I think a little behind current practices, but it's where I got most of > my > > ideas. > > > > --Erik Ostrom > > e...@echographia.com > > _______________________________________________ > > Radiant mailing list > > Post: Radiant@radiantcms.org > > Search: http://radiantcms.org/mailing-list/search/ > > Site: http://lists.radiantcms.org/mailman/listinfo/radiant > > > > > > -- > Enrico Teotti > IT consultant, accessible web sites and web applications > Sydney, NSW, Australia > enrico.teo...@gmail.com > mobile (IT) +393286590765 > mobile (AU) +00610416748450 > > http://www.teotti.com > _______________________________________________ > Radiant mailing list > Post: Radiant@radiantcms.org > Search: http://radiantcms.org/mailing-list/search/ > Site: http://lists.radiantcms.org/mailman/listinfo/radiant > _______________________________________________ Radiant mailing list Post: Radiant@radiantcms.org Search: http://radiantcms.org/mailing-list/search/ Site: http://lists.radiantcms.org/mailman/listinfo/radiant