Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From fccd0f3e2143089db53148cf2ebe1a8fa1c422da Mon Sep 17 00:00:00 2001
- From: Phan Le <ple@phan-laptop-2.au.lpint.net>
- Date: Wed, 23 Sep 2009 16:21:41 +1000
- Subject: [PATCH] Trying to add a status code to memberships
- ---
- app/models/membership.rb | 4 +
- app/models/membership_status.rb | 7 ++
- .../20090923052157_add_status_to_memberships.rb | 10 +++
- features/group_membership.feature | 19 ++-----
- features/group_message_comments.feature | 59 ++++++++++++++++++++
- features/group_registration.feature | 3 +-
- features/message_post.feature | 17 ++---
- features/step_definitions/membership_steps.rb | 7 ++-
- features/step_definitions/post_steps.rb | 16 +++--
- 9 files changed, 109 insertions(+), 33 deletions(-)
- create mode 100644 app/models/membership_status.rb
- create mode 100644 db/migrate/20090923052157_add_status_to_memberships.rb
- create mode 100644 features/group_message_comments.feature
- diff --git a/app/models/membership.rb b/app/models/membership.rb
- index e2fdfb7..7d4f632 100644
- --- a/app/models/membership.rb
- +++ b/app/models/membership.rb
- @@ -54,6 +54,10 @@ class Membership < ActiveRecord::Base
- }
- roles[role] || {}
- }
- +
- + def is_admin?
- + is_admin
- + end
- def is_only_admin?
- is_admin? && group.memberships.administrative.count == 1
- diff --git a/app/models/membership_status.rb b/app/models/membership_status.rb
- new file mode 100644
- index 0000000..c4224ab
- --- /dev/null
- +++ b/app/models/membership_status.rb
- @@ -0,0 +1,7 @@
- +class MembershipStatus
- + include Enumeration
- + value :ADMIN, "a", "Admin"
- + value :CONTRIBUTOR, "c", "Contributor"
- + value :MEMBER, "m", "Member"
- + value :BANNED, "b", "Banned"
- +end
- \ No newline at end of file
- diff --git a/db/migrate/20090923052157_add_status_to_memberships.rb b/db/migrate/20090923052157_add_status_to_memberships.rb
- new file mode 100644
- index 0000000..b1d6318
- --- /dev/null
- +++ b/db/migrate/20090923052157_add_status_to_memberships.rb
- @@ -0,0 +1,10 @@
- +class AddStatusToMemberships < ActiveRecord::Migration
- + def self.up
- + add_column :memberships, :status_code, :string, :limit => 1, :default => "m"
- + execute("UPDATE memberships SET status_code = 'a' WHERE is_admin = #{quote(true)}")
- + end
- +
- + def self.down
- + remove_column :memberships, :status_code
- + end
- +end
- diff --git a/features/group_membership.feature b/features/group_membership.feature
- index c586c9b..d5393b6 100644
- --- a/features/group_membership.feature
- +++ b/features/group_membership.feature
- @@ -8,29 +8,20 @@ Scenario: Join a group as an unauthenticated user
- When I visit the "test" group page
- And I follow "Join this group"
- - And I fill in "login" with "specialname"
- + And I fill in "login" with "francis"
- And I press "Submit"
- Then I should be on the "test" group page
- And I should see "Leave this group"
- + And "francis" should have a membership status of "member" in "test" group
- Scenario: Join a group as an authenticated user
- - Given I am logged in
- + Given I am logged in as "bill"
- - When I visit the "test" group page
- + When I visit the "test" group page
- And I follow "Join this group"
- Then I should be on the "test" group page
- And I should see "Leave this group"
- -
- -# TODO: how about leaving a group?!
- -
- -Scenario: View group members
- -
- - Given the "Fishing" group has 20 members
- -
- - When I visit the "Fishing" group members page
- -
- - Then I should see 21 members listed
- - #including the creator
- + And "bill" should have a membership status of "member" in "test" group
- diff --git a/features/group_message_comments.feature b/features/group_message_comments.feature
- new file mode 100644
- index 0000000..310a68a
- --- /dev/null
- +++ b/features/group_message_comments.feature
- @@ -0,0 +1,59 @@
- +Feature: Group messages page
- +
- + The Messages page displays a paginated list of posted messages.
- +
- + Scenario: Follow link from the group page
- +
- + Given "Bob" is a member of the "Fishing" group
- +
- + When I visit the "Fishing" group page
- + And I follow "Messages"
- +
- + Then I should be on the "Fishing" group messages page
- +
- + Scenario: Make a valid ajax comment on a message
- +
- + Given "Bob" is a member of the "Fishing" group
- + And the "Fishing" group has 10 messages with 1 comment by "Bob" each
- + And I am logged in as "Bob"
- +
- + When I visit the "Fishing" group messages page
- + And I make an ajax comment with "Fishing is for assholes" on the 5th message of the "Fishing" group
- +
- + Then the response code should be 201
- +
- + Scenario: Make an invalid ajax comment on a message
- +
- + Given "Bob" is a member of the "Fishing" group
- + And the "Fishing" group has 10 messages with 1 comment by "Bob" each
- + And I am logged in as "Bob"
- +
- + When I visit the "Fishing" group messages page
- + And I make an ajax comment with "" on the 5th message of the "Fishing" group
- +
- + Then the response code should be 412
- +
- + Scenario: Make a valid regular comment on a message
- +
- + Given "Bob" is a member of the "Fishing" group
- + And the "Fishing" group has 1 messages with 0 comment by "Bob" each
- + And I am logged in as "Bob"
- +
- + When I visit the 1st message page for the "Fishing" group
- + And I make a comment with "Fishing is for halfwits" on the 1st message of the "Fishing" group
- +
- + Then I should see my "Fishing is for halfwits" on the 1st message of the "Fishing" group
- +
- + Scenario: Make an invalid regular comment on a message
- +
- + Given "Bob" is a member of the "Fishing" group
- + And the "Fishing" group has 1 messages with 0 comment by "Bob" each
- + And I am logged in as "Bob"
- +
- + When I visit the 1st message page for the "Fishing" group
- + And I make a comment with "" on the 1st message of the "Fishing" group
- +
- + Then I should see an error "You need to put a comment before you can post it"
- +
- +
- +
- \ No newline at end of file
- diff --git a/features/group_registration.feature b/features/group_registration.feature
- index daf6489..536a5c8 100644
- --- a/features/group_registration.feature
- +++ b/features/group_registration.feature
- @@ -28,8 +28,9 @@ Scenario: Register new group as an authenticated user
- And I should see "Watching Fireworks"
- And I should see "My group description"
- And I should see "Bob"
- + And "Bob" should have a membership status of "administrator" in "Watching Fireworks" group
- -Scenario: Register new group as an authenticated user
- +Scenario: Register new group as an authenticated user with invalid configuration
- Given I am logged in as "Bob"
- And I am on "/groups"
- diff --git a/features/message_post.feature b/features/message_post.feature
- index a68478d..ee07bf2 100644
- --- a/features/message_post.feature
- +++ b/features/message_post.feature
- @@ -5,17 +5,8 @@ Feature: Post a message
- Scenario: Member successfully posts a message
- Given "Bob" is a member of the "Bob is a champ" group
- -
- When I am logged in as "Bob"
- - And I visit the "Bob is a champ" group page
- - And I fill in "message[title]" with "Bob went to see Bush"
- - And I fill in "message[content]" with "Bob visit Bush and dined with Bush at the White House"
- - And I press "Post Message"
- -
- - Then I should be on the "Bob is a champ" group page
- - And I should see "Bob went to see Bush"
- - And I should see "Bob visit Bush and dined with Bush at the White House"
- -
- + Then I can successfully post a message titled "Hi there" with content "posting ur message" to the "Bob is a champ" group
- Scenario: Member successfully posts an image
- @@ -33,4 +24,10 @@ Scenario: Member successfully posts an image
- And I should see "Bob visit Bush and dined with Bush at the White House"
- And I should see a 145 pixel wide version of "big_fish.jpg"
- +Scenario: "Post a message as a non-member logged in user"
- + Given there is a "zombies" group
- + And I am logged in as "louis"
- + Then I can successfully post a message titled "Hi there" with content "posting ur message" to the "zombies" group
- + And "louis" should have a membership status of "contributor" in "test" group
- +
- diff --git a/features/step_definitions/membership_steps.rb b/features/step_definitions/membership_steps.rb
- index 288af4c..34d0ca6 100644
- --- a/features/step_definitions/membership_steps.rb
- +++ b/features/step_definitions/membership_steps.rb
- @@ -68,4 +68,9 @@ Then /"(.+)" should (not)?\s?be banned from the "(.+)" group/ do |username, bann
- user = User.find_by_name(username)
- group = Group.find_by_name(group_name)
- group.membership_of(user).is_banned.should == (banned != "not")
- -end
- \ No newline at end of file
- +end
- +
- +Then /^"(.+)"should have a membership status of "(.+)" in "(.+)" group$/ do |user_name, membership_status, group_name|
- + group = Group.find_by_name(group_name)
- + group.membership.for_user(User[user_name]).status.should eql (membership_status)
- +end
- diff --git a/features/step_definitions/post_steps.rb b/features/step_definitions/post_steps.rb
- index 47aefd1..eee361c 100644
- --- a/features/step_definitions/post_steps.rb
- +++ b/features/step_definitions/post_steps.rb
- @@ -77,7 +77,6 @@ When /I visit the "(.+)" (message|photo) page for the "(.+)" group/ do |post_tit
- visit send("group_#{post_type}_path", group, post)
- end
- -
- Then /^I should be on the "(.*)" post page$/ do |title|
- post = Post.find_by_title(title)
- expected_path = url_for(
- @@ -90,12 +89,9 @@ Then /^I should be on the "(.*)" post page$/ do |title|
- end
- Then /^I should see my "(.+)" on the (\d+)\w{2} message of the "(.%
Add Comment
Please, Sign In to add comment