Turns out that now that we have perms, we also seem to need to make sure we have certain data preloaded before tests run. Fixtures do this, factories do not (or at least we don't know how yet). As a possibly interim step, I have loaded up the data I know we need to run current tests.
This may need more fleshing out in future, but seems to be workable for now. --- src/spec/factories/user.rb | 10 ++-- src/spec/fixtures/base_portal_objects.yml | 9 ++++ src/spec/fixtures/hardware_profiles.yml | 72 +++++++++++++++++++++++++++++ src/spec/fixtures/images.yml | 12 +++++ src/spec/fixtures/permissions.yml | 10 ++++ src/spec/fixtures/privileges.yml | 39 +++++++++++++++ src/spec/fixtures/providers.yml | 6 ++ src/spec/fixtures/realms.yml | 10 ++++ src/spec/fixtures/roles.yml | 47 +++++++++++++++++++ src/spec/spec_helper.rb | 2 +- 10 files changed, 211 insertions(+), 6 deletions(-) create mode 100644 src/spec/fixtures/base_portal_objects.yml create mode 100644 src/spec/fixtures/hardware_profiles.yml create mode 100644 src/spec/fixtures/images.yml create mode 100644 src/spec/fixtures/permissions.yml create mode 100644 src/spec/fixtures/privileges.yml create mode 100644 src/spec/fixtures/providers.yml create mode 100644 src/spec/fixtures/realms.yml create mode 100644 src/spec/fixtures/roles.yml
diff --git a/src/spec/factories/user.rb b/src/spec/factories/user.rb index 637600c..a88b6fe 100644 --- a/src/spec/factories/user.rb +++ b/src/spec/factories/user.rb @@ -1,13 +1,13 @@ Factory.define :user do |u| u.login 'myuser' - u.email 'myuser@example.com' + u.sequence(:email) { |n| "myuser#{n}@example.com" } u.password 'secret' - u.password_confirmation 'secret' - #u.first_name 'John' - #u.last_name 'Smith' + u.password_confirmation {|p| p.password} + u.first_name 'John' + u.last_name 'Smith' end
Factory.define :tuser, :parent => :user do |u| u.login 'tuser' - u.email 'tuser@example.com' + u.sequence(:email) { |n| "tuser#{n}@example.com" } end diff --git a/src/spec/fixtures/base_portal_objects.yml b/src/spec/fixtures/base_portal_objects.yml new file mode 100644 index 0000000..7e9b357 --- /dev/null +++ b/src/spec/fixtures/base_portal_objects.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +# one: +# column: value +# +# two: +# column: value +base_portal_object: + name: general_permission_scope \ No newline at end of file diff --git a/src/spec/fixtures/hardware_profiles.yml b/src/spec/fixtures/hardware_profiles.yml new file mode 100644 index 0000000..7bdd345 --- /dev/null +++ b/src/spec/fixtures/hardware_profiles.yml @@ -0,0 +1,72 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +m1_small_backend: + external_key: m1-small + name: m1-small + memory: 1.7 + storage: 160 + architecture: i386 + provider: mock_provider +m1_large_backend: + external_key: m1-large + name: m1-large + memory: 7.5 + storage: 850 + architecture: x86_64 + provider: mock_provider +m1_xlarge_backend: + external_key: m1-xlarge + name: m1-xlarge + memory: 15 + storage: 1690 + architecture: x86_64 + provider: mock_provider +c1_medium_backend: + external_key: c1-medium + name: c1-medium + memory: 1.7 + storage: 350 + architecture: x86_64 + provider: mock_provider +c1_xlarge_backend: + external_key: c1-xlarge + name: c1-xlarge + memory: 7 + storage: 1690 + architecture: x86_64 + provider: mock_provider +m1_small_frontend: + external_key: m1-small + name: m1-small + memory: 1.7 + storage: 160 + architecture: i386 + provider_hardware_profiles: m1_small_backend +m1_large_frontend: + external_key: m1-large + name: m1-large + memory: 7.5 + storage: 850 + architecture: x86_64 + provider_hardware_profiles: m1_large_backend +m1_xlarge_frontend: + external_key: m1-xlarge + name: m1-xlarge + memory: 15 + storage: 1690 + architecture: x86_64 + provider_hardware_profiles: m1_xlarge_backend +c1_medium_frontend: + external_key: c1-medium + name: c1-medium + memory: 1.7 + storage: 350 + architecture: x86_64 + provider_hardware_profiles: c1_medium_backend +c1_xlarge_frontend: + external_key: c1-xlarge + name: c1-xlarge + memory: 7 + storage: 1690 + architecture: x86_64 + provider_hardware_profiles: c1_xlarge_backend diff --git a/src/spec/fixtures/images.yml b/src/spec/fixtures/images.yml new file mode 100644 index 0000000..bfa6bba --- /dev/null +++ b/src/spec/fixtures/images.yml @@ -0,0 +1,12 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +fedora_13_image_backend: + external_key: fedora_13 + name: fedora_13 + architecture: x86_64 + provider: mock_provider +fedora_13_image_frontend: + external_key: fedora_13 + name: fedora_13 + architecture: x86_64 + provider_images: fedora_13_image_backend diff --git a/src/spec/fixtures/permissions.yml b/src/spec/fixtures/permissions.yml new file mode 100644 index 0000000..b2d7bdd --- /dev/null +++ b/src/spec/fixtures/permissions.yml @@ -0,0 +1,10 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +admin_permission: + role: site_administrator + user: test_admin + permission_object: base_portal_object (BasePortalObject) +user_permission: + role: instance_creator_and_user + user: test_user + permission_object: test_pool (PortalPool) diff --git a/src/spec/fixtures/privileges.yml b/src/spec/fixtures/privileges.yml new file mode 100644 index 0000000..d1f44ab --- /dev/null +++ b/src/spec/fixtures/privileges.yml @@ -0,0 +1,39 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +# one: +# column: value +# +# two: +# column: value +set_perms: + name: set_perms +view_perms: + name: view_perms +instance_modify: + name: instance_modify +instance_control: + name: instance_control +instance_view: + name: instance_view +stats_view: + name: stats_view +account_modify: + name: account_modify +account_view: + name: account_view +pool_modify: + name: pool_modify +pool_view: + name: pool_view +quota_modify: + name: quota_modify +quota_view: + name: quota_view +provider_modify: + name: provider_modify +provider_view: + name: provider_view +user_modify: + name: user_modify +user_view: + name: user_view diff --git a/src/spec/fixtures/providers.yml b/src/spec/fixtures/providers.yml new file mode 100644 index 0000000..1669919 --- /dev/null +++ b/src/spec/fixtures/providers.yml @@ -0,0 +1,6 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +mock_provider: + name: mock + cloud_type: Mock + url: http://localhost:3001/api diff --git a/src/spec/fixtures/realms.yml b/src/spec/fixtures/realms.yml new file mode 100644 index 0000000..6259f6c --- /dev/null +++ b/src/spec/fixtures/realms.yml @@ -0,0 +1,10 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +us_realm: + external_key: us + name: United States + provider: mock_provider +eu_realm: + external_key: eu + name: Europe + provider: mock_provider diff --git a/src/spec/fixtures/roles.yml b/src/spec/fixtures/roles.yml new file mode 100644 index 0000000..2ac7e5f --- /dev/null +++ b/src/spec/fixtures/roles.yml @@ -0,0 +1,47 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +# one: +# column: value +# +# two: +# column: value +instance_controller: + name: Instance Controller + scope: PortalPool + privileges: instance_control, instance_view, pool_view +instance_controller_with_monitoring: + name: Instance Controller With Monitoring + scope: PortalPool + privileges: instance_control, instance_view, pool_view, stats_view +instance_creator_and_user: + name: Instance Creator and User + scope: PortalPool + privileges: instance_control, instance_view, pool_view, stats_view, instance_modify, quota_view, set_perms, view_perms +self_service_pool_user: + name: Self-service Pool User + scope: PortalPool + privileges: instance_control, instance_view, pool_view, stats_view, instance_modify, quota_view, set_perms, view_perms, account_modify +pool_creator: + name: Pool Creator + scope: Provider + privileges: provider_view, pool_modify, pool_view, quota_view +pool_administrator: + name: Pool Administrator + scope: Provider + privileges: provider_view, pool_modify, pool_view, quota_modify, quota_view, account_modify, account_view, stats_view, set_perms, view_perms +account_administrator: + name: Account Administrator + scope: CloudAccount + privileges: account_modify, account_view, stats_view, set_perms, view_perms +account_user: + name: Account User + scope: CloudAccount + privileges: account_view +provider_administrator: + name: Provider Administrator + scope: BasePortalObject + privileges: provider_modify, provider_view, stats_view +site_administrator: + name: Site Administrator + scope: BasePortalObject + privileges: provider_modify, provider_view, account_modify, account_view, user_modify, user_view, set_perms, view_perms, pool_modify, pool_view, quota_modify, quota_view, stats_view, instance_modify, instance_control, instance_view diff --git a/src/spec/spec_helper.rb b/src/spec/spec_helper.rb index 5181389..87a4609 100644 --- a/src/spec/spec_helper.rb +++ b/src/spec/spec_helper.rb @@ -31,7 +31,7 @@ Spec::Runner.configure do |config| # do so right here. Just uncomment the next line and replace the fixture # names with your fixtures. # - # config.global_fixtures = :table_a, :table_b + config.global_fixtures = :all # # If you declare global fixtures, be aware that they will be declared # for all of your examples, even those that don't use them.
These tests should now fail, next patch in series will make them pass again. They reflect where the design changes will be, so it should be easy to see much of what to look for in the next patch. --- src/features/authentication.feature | 22 +++++++++++++--------- src/features/step_definitions/authentication.rb | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/src/features/authentication.feature b/src/features/authentication.feature index add2c95..0dea3ac 100644 --- a/src/features/authentication.feature +++ b/src/features/authentication.feature @@ -3,16 +3,20 @@ Feature: User authentication As a user I must register and log in
+ @register Scenario: Register as new user Given I am on the homepage - When I follow "Register" + When I follow "Create one now" Then I should be on the new account page + And I should see "New Account" When I fill in the following: - | login | testuser | - | email | testuser@example.com | - | password | secret | - | password confirmation | secret | - And I press "Register" + | Choose a username | testuser | + | Choose a password | secret | + | Confirm password | secret | + | First name | Joe | + | Last name | Tester | + | Email | testuser@example.com | + And I press "Create Account" Then I should be on the account page And I should see "User registered!"
@@ -35,7 +39,7 @@ Feature: User authentication And I am on the homepage When I want to edit my profile And I follow "Edit" - Then I should see "Edit My Profile" + Then I should see "Edit my profile" When I fill in "email" with "changed@example.com" And I press "Update" Then I should be on the account page @@ -47,5 +51,5 @@ Feature: User authentication When I follow "Log out" Then I should be logged out And I should see "Logout successful!" - And I should see "Register" - And I should see "Login" + And I should see "Create one now." + And I should see "Please sign in" diff --git a/src/features/step_definitions/authentication.rb b/src/features/step_definitions/authentication.rb index e5917ce..92e7874 100644 --- a/src/features/step_definitions/authentication.rb +++ b/src/features/step_definitions/authentication.rb @@ -5,7 +5,7 @@ end def login(login, password) user visit path_to("the login page") - fill_in "Login", :with => login + fill_in "Username", :with => login fill_in "Password", :with => password click_button "Login" end
On 03/11/2010 05:28 PM, Jason Guiditta wrote:
These tests should now fail, next patch in series will make them pass again. They reflect where the design changes will be, so it should be easy to see much of what to look for in the next patch.
src/features/authentication.feature | 22 +++++++++++++--------- src/features/step_definitions/authentication.rb | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/src/features/authentication.feature b/src/features/authentication.feature index add2c95..0dea3ac 100644 --- a/src/features/authentication.feature +++ b/src/features/authentication.feature @@ -3,16 +3,20 @@ Feature: User authentication As a user I must register and log in
- @register Scenario: Register as new user Given I am on the homepage
- When I follow "Register"
- When I follow "Create one now" Then I should be on the new account page
- And I should see "New Account" When I fill in the following:
| login | testuser |
| email | testuser@example.com |
| password | secret |
| password confirmation | secret |
- And I press "Register"
| Choose a username | testuser |
| Choose a password | secret |
| Confirm password | secret |
| First name | Joe |
| Last name | Tester |
| Email | testuser@example.com |
- And I press "Create Account" Then I should be on the account page And I should see "User registered!"
This feature is failing for me. When I run rake features (with all patches in the set applied), I get
.......F-..........................
(::) failed steps (::)
expected the following element's content to include "User registered!": dCloud var $tabs, selected_tab; $(document).ready(function(){ $.ajaxSetup({error: function(xhr) {$.jGrowl(xhr.status + ' ' + xhr.statusText);}});
$('a[rel*=facebox]').livequery(function(){$(this).facebox();},function(){}); $('.dialog_tab_nav a').livequery(function(){ $(this).bind('click', function(){ $('.dialog_tab_nav li').removeClass('current'); $(this).parent().addClass('current'); $.ajax({ url: $(this).attr('href'), type: 'GET', data: {ajax:true}, dataType: 'html', success: function(data) { var wrapped_data = $(data).find('div').filter('[id=dialog-content-area]'); var my_parent = $(this).parent(); $('#dialog-content-area').html($(data)); $('#facebox').css('left', $(window).width() / 2 - ($('#facebox table').width() / 2)); }, error: function(xhr) {$.jGrowl(xhr.status + ' ' + xhr.statusText);} }); return false;})},function(){}); $('ul.instance_action_list li:first-child').addClass('first'); }); | Log in New Account Choose a username Change password Confirm password First name Last name Email Cancel (Spec::Expectations::ExpectationNotMetError) ./features/step_definitions/web_steps.rb:144:in `/^(?:|I )should see "([^"]*)"$/' features/authentication.feature:21:in `And I should see "User registered!"'
Failing Scenarios: cucumber features/authentication.feature:7 # Scenario: Register as new user
5 scenarios (1 failed, 4 passed) 35 steps (1 failed, 1 skipped, 33 passed) 0m2.477s rake aborted! Command failed with status (1): [/usr/bin/ruby -I "/home/mmorsi/.gem/ruby/1...]
(See full trace by running task with --trace)
-Mo
--- src/db/migrate/20090917192602_create_users.rb | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/src/db/migrate/20090917192602_create_users.rb b/src/db/migrate/20090917192602_create_users.rb index 5b9f76e..67706fb 100644 --- a/src/db/migrate/20090917192602_create_users.rb +++ b/src/db/migrate/20090917192602_create_users.rb @@ -29,6 +29,8 @@ class CreateUsers < ActiveRecord::Migration t.string :persistence_token, :null => false t.string :single_access_token, :null => false t.string :perishable_token, :null => false + t.string :first_name + t.string :last_name # Magic columns, just like ActiveRecord's created_at and updated_at. # These are automatically maintained by Authlogic if they are present. t.integer :login_count, :null => false, :default => 0
On 03/11/2010 05:28 PM, Jason Guiditta wrote:
src/db/migrate/20090917192602_create_users.rb | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/src/db/migrate/20090917192602_create_users.rb b/src/db/migrate/20090917192602_create_users.rb index 5b9f76e..67706fb 100644 --- a/src/db/migrate/20090917192602_create_users.rb +++ b/src/db/migrate/20090917192602_create_users.rb @@ -29,6 +29,8 @@ class CreateUsers< ActiveRecord::Migration t.string :persistence_token, :null => false t.string :single_access_token, :null => false t.string :perishable_token, :null => false
t.string :first_name
t.string :last_name # Magic columns, just like ActiveRecord's created_at and updated_at. # These are automatically maintained by Authlogic if they are present. t.integer :login_count, :null => false, :default => 0
NACK. Can you create a seperate new migration that alters the user table (adding the column on up, dropping it on remove).
Committed migrations shouldn't be edited, I had to blow away / recreate my db to get first_name / last_name.
-Mo
On 03/12/2010 04:03 PM, Mohammed Morsi wrote:
On 03/11/2010 05:28 PM, Jason Guiditta wrote:
src/db/migrate/20090917192602_create_users.rb | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/src/db/migrate/20090917192602_create_users.rb b/src/db/migrate/20090917192602_create_users.rb index 5b9f76e..67706fb 100644 --- a/src/db/migrate/20090917192602_create_users.rb +++ b/src/db/migrate/20090917192602_create_users.rb @@ -29,6 +29,8 @@ class CreateUsers< ActiveRecord::Migration t.string :persistence_token, :null => false t.string :single_access_token, :null => false t.string :perishable_token, :null => false
t.string :first_name
t.string :last_name # Magic columns, just like ActiveRecord's created_at and updated_at. # These are automatically maintained by Authlogic if they are present. t.integer :login_count, :null => false, :default => 0
NACK. Can you create a seperate new migration that alters the user table (adding the column on up, dropping it on remove).
Committed migrations shouldn't be edited, I had to blow away / recreate my db to get first_name / last_name.
-Mo
deltacloud-devel mailing list deltacloud-devel@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/deltacloud-devel
ACK. Since it doesn't seem that at this early point in the dev process, migrations consistency is high priority and it would just lead to clutter.
-Mo
This patch takes the first step in getting the design closer to what Jeremy has in his mockups.
There will be significant overall changes that will have an entire separate css patch later, so I ignored things like having the 'cancel' link lined up under the form buttons. However, form layout should be more consistent to support upcoming changes.
cucumber tests should now pass. --- src/app/views/user_sessions/new.html.erb | 32 +++++++++++++++---------- src/app/views/users/_form.erb | 36 +++++++++++++++++++++-------- src/app/views/users/edit.html.erb | 11 ++++----- src/app/views/users/new.html.erb | 9 ++++--- src/app/views/users/show.html.erb | 2 +- src/public/stylesheets/dcloud.css | 9 +++---- 6 files changed, 60 insertions(+), 39 deletions(-)
diff --git a/src/app/views/user_sessions/new.html.erb b/src/app/views/user_sessions/new.html.erb index ee7da51..92f384c 100644 --- a/src/app/views/user_sessions/new.html.erb +++ b/src/app/views/user_sessions/new.html.erb @@ -1,18 +1,24 @@ -<div class="dcloud_form"> - <h2>Login</h2> +<h2 class="greeting">Welcome to $aggregator. Please sign in.</h2>
+<div class="dcloud_form"> <% form_for @user_session, :url => user_session_path do |f| %> <%= f.error_messages %> - <%= f.label :login %><br /> - <%= f.text_field :login %><br /> - <br /> - <%= f.label :password %><br /> - <%= f.password_field :password %><br /> - <br /> - <%= f.check_box :remember_me %><%= f.label :remember_me %><br /> - <br /> - <%= f.submit "Login" %> + <ul> + <li> + <%= f.label :login, "Username" %> + <%= f.text_field :login %> + </li> + <li> + <%= f.label :password %> + <%= f.password_field :password %> + </li> + </ul> + <%= f.check_box :remember_me %><%= f.label :remember_me %> + <%= f.submit "Login", :class => "submit" %> <% end %> - <%= link_to 'Register', {:controller => 'users', :action => 'new'}, :class => 'actionlink' %> - + <div> + <%= link_to "Don't have an account? Create one now.", + {:controller => 'users', :action => 'new'}, + :class => 'actionlink' %> + </div> </div> diff --git a/src/app/views/users/_form.erb b/src/app/views/users/_form.erb index a278d9a..4fcd98c 100644 --- a/src/app/views/users/_form.erb +++ b/src/app/views/users/_form.erb @@ -1,10 +1,26 @@ -<%= form.label :login %><br /> -<%= form.text_field :login %><br /> -<%= form.label :email %><br /> -<%= form.text_field :email %><br /> -<br /> -<%= form.label :password, form.object.new_record? ? nil : "Change password" %><br /> -<%= form.password_field :password %><br /> -<br /> -<%= form.label :password_confirmation %><br /> -<%= form.password_field :password_confirmation %><br /> +<ul> + <li> + <%= form.label :login, "Choose a username" %> + <%= form.text_field :login %> + </li> + <li> + <%= form.label :password, form.object.new_record? ? "Choose a password" : "Change password" %> + <%= form.password_field :password %> + </li> + <li> + <%= form.label :password_confirmation, "Confirm password" %> + <%= form.password_field :password_confirmation %> + </li> + <li> + <%= form.label :first_name %> + <%= form.text_field :first_name %> + </li> + <li> + <%= form.label :last_name %> + <%= form.text_field :last_name %> + </li> + <li> + <%= form.label :email %> + <%= form.text_field :email %> + </li> +</ul> diff --git a/src/app/views/users/edit.html.erb b/src/app/views/users/edit.html.erb index 73fdedd..0d2de48 100644 --- a/src/app/views/users/edit.html.erb +++ b/src/app/views/users/edit.html.erb @@ -1,11 +1,10 @@ -<div class="dcloud_form"> - <h2>Edit My Profile</h2> +<h2 class="greeting">Edit my profile.</h2>
+<div class="dcloud_form"> <% form_for @user, :url => account_path do |f| %> <%= f.error_messages %> - <%= render :partial => "form", :object => f %> - <%= f.submit "Update" %> + <%= render :partial => "form", :object => f %> + <%= f.submit "Update", :class => "submit" %> <% end %> - - <br /><%= link_to "My Profile", account_path, :class => 'actionlink' %> + <br /><%= link_to "Cancel", account_path, :class => 'actionlink' %> </div> diff --git a/src/app/views/users/new.html.erb b/src/app/views/users/new.html.erb index d6a35e4..0027ef6 100644 --- a/src/app/views/users/new.html.erb +++ b/src/app/views/users/new.html.erb @@ -1,9 +1,10 @@ -<div class="dcloud_form"> - <h2>Register</h2> +<h2 class="greeting">New Account</h2>
+<div class="dcloud_form"> <% form_for @user, :url => account_path do |f| %> <%= f.error_messages %> - <%= render :partial => "form", :object => f %> - <%= f.submit "Register" %> + <%= render :partial => "form", :object => f %> + <%= f.submit "Create Account", :class => "submit" %> <% end %> + <%= link_to "Cancel", root_path, :class => 'actionlink' %> </div> diff --git a/src/app/views/users/show.html.erb b/src/app/views/users/show.html.erb index 632b630..a505552 100644 --- a/src/app/views/users/show.html.erb +++ b/src/app/views/users/show.html.erb @@ -1,7 +1,7 @@ <div class="dcloud_form"> <h2>User Profile for <%=h @user.login %></h2> <p> - <b>Login:</b> + <b>Username:</b> <%=h @user.login %> </p>
diff --git a/src/public/stylesheets/dcloud.css b/src/public/stylesheets/dcloud.css index e2f47aa..96cb95c 100644 --- a/src/public/stylesheets/dcloud.css +++ b/src/public/stylesheets/dcloud.css @@ -14,7 +14,7 @@ fieldset { padding: 18px 0 10px 10px; }
-fieldset ul li input { +ul li input { border:2px solid #becfe4; color:#333; display:block; @@ -63,7 +63,7 @@ input, select { -moz-border-radius: 10px; -webkit-border-radius: 10px; margin-top: 54px; - width: 500px ; + width: 550px ; margin-left: auto ; margin-right: auto ; padding: 36px; @@ -89,7 +89,7 @@ input, select { display: block; float: left; padding: 3px 0 24px 0; - width: 160px; + width: 175px; font-size: 1.4em; color: #616161; } @@ -120,7 +120,6 @@ input, select {
.dcloud_form .submit { float: right; - margin-top: 18px; display: inline; clear:both; } @@ -263,4 +262,4 @@ ul#providers li ul li a:hover {
.instance_action_list li.first { border-left: none; -} +} \ No newline at end of file
On 03/11/2010 05:28 PM, Jason Guiditta wrote:
This patch takes the first step in getting the design closer to what Jeremy has in his mockups.
There will be significant overall changes that will have an entire separate css patch later, so I ignored things like having the 'cancel' link lined up under the form buttons. However, form layout should be more consistent to support upcoming changes.
cucumber tests should now pass.
src/app/views/user_sessions/new.html.erb | 32 +++++++++++++++---------- src/app/views/users/_form.erb | 36 +++++++++++++++++++++-------- src/app/views/users/edit.html.erb | 11 ++++----- src/app/views/users/new.html.erb | 9 ++++--- src/app/views/users/show.html.erb | 2 +- src/public/stylesheets/dcloud.css | 9 +++---- 6 files changed, 60 insertions(+), 39 deletions(-)
diff --git a/src/app/views/user_sessions/new.html.erb b/src/app/views/user_sessions/new.html.erb index ee7da51..92f384c 100644 --- a/src/app/views/user_sessions/new.html.erb +++ b/src/app/views/user_sessions/new.html.erb @@ -1,18 +1,24 @@ -<div class="dcloud_form"> -<h2>Login</h2> +<h2 class="greeting">Welcome to $aggregator. Please sign in.</h2>
This entire patch looks good / works as expected but I was just wondering about the '$' before the word 'aggregator', it is pretty noticeably out of place in the UI. Other than that ACK.
-Mo
This registration service may be able to be abstracted/ resued in future patches. --- src/app/controllers/users_controller.rb | 3 +- src/app/services/registration_service.rb | 29 +++++++++++++ src/features/authentication.feature | 1 + src/features/step_definitions/authentication.rb | 5 ++ src/spec/controllers/users_controller_spec.rb | 49 +++++++++++++++++++--- src/spec/models/registration_service_spec.rb | 48 ++++++++++++++++++++++ 6 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 src/app/services/registration_service.rb create mode 100644 src/spec/models/registration_service_spec.rb
diff --git a/src/app/controllers/users_controller.rb b/src/app/controllers/users_controller.rb index 310edf6..6c6c021 100644 --- a/src/app/controllers/users_controller.rb +++ b/src/app/controllers/users_controller.rb @@ -29,7 +29,8 @@ class UsersController < ApplicationController
def create @user = User.new(params[:user]) - if @user.save + @registration = RegistrationService.new(@user) + if @registration.save flash[:notice] = "User registered!" redirect_back_or_default account_url else diff --git a/src/app/services/registration_service.rb b/src/app/services/registration_service.rb new file mode 100644 index 0000000..e8d2e65 --- /dev/null +++ b/src/app/services/registration_service.rb @@ -0,0 +1,29 @@ +class RegistrationService + + def initialize(user) + @user = user + end + + def save + return false unless valid? + begin + User.transaction do + @user.save! + PortalPool.transaction do + @portal_pool = PortalPool.create!({ :name => @user.login, :owner => @user}) + Permission.transaction do + Permission.create!({:user => @user, + :role => Role.find_by_name("Self-service Pool User"), + :permission_object => @portal_pool}) + end + end + end + rescue + false + end + end + + def valid? + @user.valid? + end +end \ No newline at end of file diff --git a/src/features/authentication.feature b/src/features/authentication.feature index 0dea3ac..78754b9 100644 --- a/src/features/authentication.feature +++ b/src/features/authentication.feature @@ -19,6 +19,7 @@ Feature: User authentication And I press "Create Account" Then I should be on the account page And I should see "User registered!" + And I should have one private pool named "testuser"
Scenario: Log in as registered user Given I am a registered user diff --git a/src/features/step_definitions/authentication.rb b/src/features/step_definitions/authentication.rb index 92e7874..7abcb83 100644 --- a/src/features/step_definitions/authentication.rb +++ b/src/features/step_definitions/authentication.rb @@ -35,3 +35,8 @@ end Then /^I should be logged out$/ do UserSession.find.should == nil end + +Then /^I should have one private pool named "([^"]*)"$/ do |login| + PortalPool.find_by_name(login).should_not be_nil + PortalPool.find_by_name(login).permissions.size.should == 1 +end diff --git a/src/spec/controllers/users_controller_spec.rb b/src/spec/controllers/users_controller_spec.rb index 1c18ba7..a74702a 100644 --- a/src/spec/controllers/users_controller_spec.rb +++ b/src/spec/controllers/users_controller_spec.rb @@ -15,13 +15,48 @@ describe UsersController do response.should be_success end
- it "should create user" do - lambda { - post :create, :user => { :login => "tuser2", :email => "tuser2@example.com", - :password => "testpass", - :password_confirmation => "testpass" } - }.should change{ User.count } - response.should redirect_to(account_path) + describe "#create" do + before(:each) do + + end + + context "user enters valid input" do + it "should create user" do + lambda { + post :create, :user => { :login => "tuser2", :email => "tuser2@example.com", + :password => "testpass", + :password_confirmation => "testpass" } + }.should change{ User.count } + p = PortalPool.find_by_name("tuser2") + p.should_not be_nil + assigns[:user].login.should == p.owner.login + p.name.should == "tuser2" + p.permissions.size.should == 1 + p.permissions.any? { + |perm| perm.role.name.eql?('Self-service Pool User') + }.should be_true + response.should redirect_to(account_path) + end + + it "fails to create pool" do + lambda { + post :create, :user => {} + }.should_not change{ User.count } + p = PortalPool.find_by_name("tuser2") + p.should be_nil + returned_user = assigns[:user] + returned_user.errors.empty?.should be_false + returned_user.should have(2).errors_on(:login) + returned_user.should have(2).errors_on(:email) + returned_user.should have(1).error_on(:password) + returned_user.should have(1).error_on(:password_confirmation) + #assigns[:user].errors.find_all {|attr,msg| + # ["login", "email", "password", "password_confirmation"]. + # include?(attr).should be_true + #} + response.should render_template('new') + end + end end
it "should show user" do diff --git a/src/spec/models/registration_service_spec.rb b/src/spec/models/registration_service_spec.rb new file mode 100644 index 0000000..eeea5c8 --- /dev/null +++ b/src/spec/models/registration_service_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe RegistrationService do + #fixtures :all + before(:each) do + @tuser = Factory :tuser + end + + it "should initialize a new instance given valid attributes" do + RegistrationService.new(@tuser) + end + + describe "#save" do + + context "adding valid user with no errors" do + it "should create user, portal_pool and self-service permission" do + user = User.new({:login => 'gooduser', + :email => 'guser@example.com', + :password => 'password', + :password_confirmation => 'password'}) + r = RegistrationService.new(user) + Rails::logger.info("ERRORS - Printing errors on user object:") + Rails::logger.info( + user.errors.each_full { |msg| "ERROR: #{msg}" } + ) + r.save.should be_true + end + end + + context "save fails" do + it "should return errors on user when user is missing required field" do + user = User.new(:login => 'baduser') + r = RegistrationService.new(user) + r.save.should be_false + user.errors.empty?.should be_false + #Rails::logger.info(msg) + user.errors.find_all {|attr,msg| + ["email", "password", "password_confirmation"].include?(attr).should be_true + } + end + + it "should return portal_pool errors if pool create fails" do + #TODO: implement this test. We should check this, but not sure of best + # way right now. + end + end + end +end
On 03/11/2010 05:28 PM, Jason Guiditta wrote:
This registration service may be able to be abstracted/ resued in future patches.
src/app/controllers/users_controller.rb | 3 +- src/app/services/registration_service.rb | 29 +++++++++++++ src/features/authentication.feature | 1 + src/features/step_definitions/authentication.rb | 5 ++ src/spec/controllers/users_controller_spec.rb | 49 +++++++++++++++++++--- src/spec/models/registration_service_spec.rb | 48 ++++++++++++++++++++++ 6 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 src/app/services/registration_service.rb create mode 100644 src/spec/models/registration_service_spec.rb
diff --git a/src/app/controllers/users_controller.rb b/src/app/controllers/users_controller.rb index 310edf6..6c6c021 100644 --- a/src/app/controllers/users_controller.rb +++ b/src/app/controllers/users_controller.rb @@ -29,7 +29,8 @@ class UsersController< ApplicationController
def create @user = User.new(params[:user])
- if @user.save
- @registration = RegistrationService.new(@user)
- if @registration.save flash[:notice] = "User registered!" redirect_back_or_default account_url else
diff --git a/src/app/services/registration_service.rb b/src/app/services/registration_service.rb new file mode 100644 index 0000000..e8d2e65 --- /dev/null +++ b/src/app/services/registration_service.rb @@ -0,0 +1,29 @@ +class RegistrationService
- def initialize(user)
- @user = user
- end
- def save
- return false unless valid?
- begin
- User.transaction do
@user.save!
PortalPool.transaction do
@portal_pool = PortalPool.create!({ :name => @user.login, :owner => @user})
Permission.transaction do
Permission.create!({:user => @user,
:role => Role.find_by_name("Self-service Pool User"),
:permission_object => @portal_pool})
end
end
- end
Are there supposed to be three transactions here? Don't you just need one saying editing these three tables atomically, if any one table fails, rollback all changes? Or am I misunderstanding how rails transactions work?
<snip>
diff --git a/src/spec/models/registration_service_spec.rb b/src/spec/models/registration_service_spec.rb new file mode 100644 index 0000000..eeea5c8 --- /dev/null +++ b/src/spec/models/registration_service_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper'
+describe RegistrationService do
- #fixtures :all
- before(:each) do
- @tuser = Factory :tuser
- end
- it "should initialize a new instance given valid attributes" do
- RegistrationService.new(@tuser)
- end
- describe "#save" do
- context "adding valid user with no errors" do
it "should create user, portal_pool and self-service permission" do
user = User.new({:login => 'gooduser',
:email => 'guser@example.com',
:password => 'password',
:password_confirmation => 'password'})
r = RegistrationService.new(user)
- Rails::logger.info("ERRORS - Printing errors on user object:")
- Rails::logger.info(
user.errors.each_full { |msg| "ERROR: #{msg}" }
)
r.save.should be_true
Is this logging code here intentionally or is it just leftover debugging artifacts?
-Mo
This patch looks good. ACK
Though wait on pushing as if just applied by itself will fail due to last_name and first_name not being present in the users table yet.
-Mo
On 03/11/2010 05:28 PM, Jason Guiditta wrote:
Turns out that now that we have perms, we also seem to need to make sure we have certain data preloaded before tests run. Fixtures do this, factories do not (or at least we don't know how yet). As a possibly interim step, I have loaded up the data I know we need to run current tests.
This may need more fleshing out in future, but seems to be workable for now.
src/spec/factories/user.rb | 10 ++-- src/spec/fixtures/base_portal_objects.yml | 9 ++++ src/spec/fixtures/hardware_profiles.yml | 72 +++++++++++++++++++++++++++++ src/spec/fixtures/images.yml | 12 +++++ src/spec/fixtures/permissions.yml | 10 ++++ src/spec/fixtures/privileges.yml | 39 +++++++++++++++ src/spec/fixtures/providers.yml | 6 ++ src/spec/fixtures/realms.yml | 10 ++++ src/spec/fixtures/roles.yml | 47 +++++++++++++++++++ src/spec/spec_helper.rb | 2 +- 10 files changed, 211 insertions(+), 6 deletions(-) create mode 100644 src/spec/fixtures/base_portal_objects.yml create mode 100644 src/spec/fixtures/hardware_profiles.yml create mode 100644 src/spec/fixtures/images.yml create mode 100644 src/spec/fixtures/permissions.yml create mode 100644 src/spec/fixtures/privileges.yml create mode 100644 src/spec/fixtures/providers.yml create mode 100644 src/spec/fixtures/realms.yml create mode 100644 src/spec/fixtures/roles.yml
diff --git a/src/spec/factories/user.rb b/src/spec/factories/user.rb index 637600c..a88b6fe 100644 --- a/src/spec/factories/user.rb +++ b/src/spec/factories/user.rb @@ -1,13 +1,13 @@ Factory.define :user do |u| u.login 'myuser'
- u.email 'myuser@example.com'
- u.sequence(:email) { |n| "myuser#{n}@example.com" } u.password 'secret'
- u.password_confirmation 'secret'
- #u.first_name 'John'
- #u.last_name 'Smith'
u.password_confirmation {|p| p.password}
u.first_name 'John'
u.last_name 'Smith' end
Factory.define :tuser, :parent => :user do |u| u.login 'tuser'
- u.email 'tuser@example.com'
- u.sequence(:email) { |n| "tuser#{n}@example.com" } end
diff --git a/src/spec/fixtures/base_portal_objects.yml b/src/spec/fixtures/base_portal_objects.yml new file mode 100644 index 0000000..7e9b357 --- /dev/null +++ b/src/spec/fixtures/base_portal_objects.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+# one: +# column: value +# +# two: +# column: value +base_portal_object:
- name: general_permission_scope
\ No newline at end of file diff --git a/src/spec/fixtures/hardware_profiles.yml b/src/spec/fixtures/hardware_profiles.yml new file mode 100644 index 0000000..7bdd345 --- /dev/null +++ b/src/spec/fixtures/hardware_profiles.yml @@ -0,0 +1,72 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+m1_small_backend:
- external_key: m1-small
- name: m1-small
- memory: 1.7
- storage: 160
- architecture: i386
- provider: mock_provider
+m1_large_backend:
- external_key: m1-large
- name: m1-large
- memory: 7.5
- storage: 850
- architecture: x86_64
- provider: mock_provider
+m1_xlarge_backend:
- external_key: m1-xlarge
- name: m1-xlarge
- memory: 15
- storage: 1690
- architecture: x86_64
- provider: mock_provider
+c1_medium_backend:
- external_key: c1-medium
- name: c1-medium
- memory: 1.7
- storage: 350
- architecture: x86_64
- provider: mock_provider
+c1_xlarge_backend:
- external_key: c1-xlarge
- name: c1-xlarge
- memory: 7
- storage: 1690
- architecture: x86_64
- provider: mock_provider
+m1_small_frontend:
- external_key: m1-small
- name: m1-small
- memory: 1.7
- storage: 160
- architecture: i386
- provider_hardware_profiles: m1_small_backend
+m1_large_frontend:
- external_key: m1-large
- name: m1-large
- memory: 7.5
- storage: 850
- architecture: x86_64
- provider_hardware_profiles: m1_large_backend
+m1_xlarge_frontend:
- external_key: m1-xlarge
- name: m1-xlarge
- memory: 15
- storage: 1690
- architecture: x86_64
- provider_hardware_profiles: m1_xlarge_backend
+c1_medium_frontend:
- external_key: c1-medium
- name: c1-medium
- memory: 1.7
- storage: 350
- architecture: x86_64
- provider_hardware_profiles: c1_medium_backend
+c1_xlarge_frontend:
- external_key: c1-xlarge
- name: c1-xlarge
- memory: 7
- storage: 1690
- architecture: x86_64
- provider_hardware_profiles: c1_xlarge_backend
diff --git a/src/spec/fixtures/images.yml b/src/spec/fixtures/images.yml new file mode 100644 index 0000000..bfa6bba --- /dev/null +++ b/src/spec/fixtures/images.yml @@ -0,0 +1,12 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+fedora_13_image_backend:
- external_key: fedora_13
- name: fedora_13
- architecture: x86_64
- provider: mock_provider
+fedora_13_image_frontend:
- external_key: fedora_13
- name: fedora_13
- architecture: x86_64
- provider_images: fedora_13_image_backend
diff --git a/src/spec/fixtures/permissions.yml b/src/spec/fixtures/permissions.yml new file mode 100644 index 0000000..b2d7bdd --- /dev/null +++ b/src/spec/fixtures/permissions.yml @@ -0,0 +1,10 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+admin_permission:
- role: site_administrator
- user: test_admin
- permission_object: base_portal_object (BasePortalObject)
+user_permission:
- role: instance_creator_and_user
- user: test_user
- permission_object: test_pool (PortalPool)
diff --git a/src/spec/fixtures/privileges.yml b/src/spec/fixtures/privileges.yml new file mode 100644 index 0000000..d1f44ab --- /dev/null +++ b/src/spec/fixtures/privileges.yml @@ -0,0 +1,39 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+# one: +# column: value +# +# two: +# column: value +set_perms:
- name: set_perms
+view_perms:
- name: view_perms
+instance_modify:
- name: instance_modify
+instance_control:
- name: instance_control
+instance_view:
- name: instance_view
+stats_view:
- name: stats_view
+account_modify:
- name: account_modify
+account_view:
- name: account_view
+pool_modify:
- name: pool_modify
+pool_view:
- name: pool_view
+quota_modify:
- name: quota_modify
+quota_view:
- name: quota_view
+provider_modify:
- name: provider_modify
+provider_view:
- name: provider_view
+user_modify:
- name: user_modify
+user_view:
- name: user_view
diff --git a/src/spec/fixtures/providers.yml b/src/spec/fixtures/providers.yml new file mode 100644 index 0000000..1669919 --- /dev/null +++ b/src/spec/fixtures/providers.yml @@ -0,0 +1,6 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+mock_provider:
- name: mock
- cloud_type: Mock
- url: http://localhost:3001/api
diff --git a/src/spec/fixtures/realms.yml b/src/spec/fixtures/realms.yml new file mode 100644 index 0000000..6259f6c --- /dev/null +++ b/src/spec/fixtures/realms.yml @@ -0,0 +1,10 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+us_realm:
- external_key: us
- name: United States
- provider: mock_provider
+eu_realm:
- external_key: eu
- name: Europe
- provider: mock_provider
diff --git a/src/spec/fixtures/roles.yml b/src/spec/fixtures/roles.yml new file mode 100644 index 0000000..2ac7e5f --- /dev/null +++ b/src/spec/fixtures/roles.yml @@ -0,0 +1,47 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+# one: +# column: value +# +# two: +# column: value +instance_controller:
- name: Instance Controller
- scope: PortalPool
- privileges: instance_control, instance_view, pool_view
+instance_controller_with_monitoring:
- name: Instance Controller With Monitoring
- scope: PortalPool
- privileges: instance_control, instance_view, pool_view, stats_view
+instance_creator_and_user:
- name: Instance Creator and User
- scope: PortalPool
- privileges: instance_control, instance_view, pool_view, stats_view, instance_modify, quota_view, set_perms, view_perms
+self_service_pool_user:
- name: Self-service Pool User
- scope: PortalPool
- privileges: instance_control, instance_view, pool_view, stats_view, instance_modify, quota_view, set_perms, view_perms, account_modify
+pool_creator:
- name: Pool Creator
- scope: Provider
- privileges: provider_view, pool_modify, pool_view, quota_view
+pool_administrator:
- name: Pool Administrator
- scope: Provider
- privileges: provider_view, pool_modify, pool_view, quota_modify, quota_view, account_modify, account_view, stats_view, set_perms, view_perms
+account_administrator:
- name: Account Administrator
- scope: CloudAccount
- privileges: account_modify, account_view, stats_view, set_perms, view_perms
+account_user:
- name: Account User
- scope: CloudAccount
- privileges: account_view
+provider_administrator:
- name: Provider Administrator
- scope: BasePortalObject
- privileges: provider_modify, provider_view, stats_view
+site_administrator:
- name: Site Administrator
- scope: BasePortalObject
- privileges: provider_modify, provider_view, account_modify, account_view, user_modify, user_view, set_perms, view_perms, pool_modify, pool_view, quota_modify, quota_view, stats_view, instance_modify, instance_control, instance_view
diff --git a/src/spec/spec_helper.rb b/src/spec/spec_helper.rb index 5181389..87a4609 100644 --- a/src/spec/spec_helper.rb +++ b/src/spec/spec_helper.rb @@ -31,7 +31,7 @@ Spec::Runner.configure do |config| # do so right here. Just uncomment the next line and replace the fixture # names with your fixtures. #
- # config.global_fixtures = :table_a, :table_b
- config.global_fixtures = :all # # If you declare global fixtures, be aware that they will be declared # for all of your examples, even those that don't use them.
deltacloud-devel@lists.fedorahosted.org