Guest User

Untitled

a guest
Apr 16th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.49 KB | None | 0 0
  1. From fccd0f3e2143089db53148cf2ebe1a8fa1c422da Mon Sep 17 00:00:00 2001
  2. From: Phan Le <ple@phan-laptop-2.au.lpint.net>
  3. Date: Wed, 23 Sep 2009 16:21:41 +1000
  4. Subject: [PATCH] Trying to add a status code to memberships
  5.  
  6. ---
  7. app/models/membership.rb | 4 +
  8. app/models/membership_status.rb | 7 ++
  9. .../20090923052157_add_status_to_memberships.rb | 10 +++
  10. features/group_membership.feature | 19 ++-----
  11. features/group_message_comments.feature | 59 ++++++++++++++++++++
  12. features/group_registration.feature | 3 +-
  13. features/message_post.feature | 17 ++---
  14. features/step_definitions/membership_steps.rb | 7 ++-
  15. features/step_definitions/post_steps.rb | 16 +++--
  16. 9 files changed, 109 insertions(+), 33 deletions(-)
  17. create mode 100644 app/models/membership_status.rb
  18. create mode 100644 db/migrate/20090923052157_add_status_to_memberships.rb
  19. create mode 100644 features/group_message_comments.feature
  20.  
  21. diff --git a/app/models/membership.rb b/app/models/membership.rb
  22. index e2fdfb7..7d4f632 100644
  23. --- a/app/models/membership.rb
  24. +++ b/app/models/membership.rb
  25. @@ -54,6 +54,10 @@ class Membership < ActiveRecord::Base
  26. }
  27. roles[role] || {}
  28. }
  29. +
  30. + def is_admin?
  31. + is_admin
  32. + end
  33.  
  34. def is_only_admin?
  35. is_admin? && group.memberships.administrative.count == 1
  36. diff --git a/app/models/membership_status.rb b/app/models/membership_status.rb
  37. new file mode 100644
  38. index 0000000..c4224ab
  39. --- /dev/null
  40. +++ b/app/models/membership_status.rb
  41. @@ -0,0 +1,7 @@
  42. +class MembershipStatus
  43. + include Enumeration
  44. + value :ADMIN, "a", "Admin"
  45. + value :CONTRIBUTOR, "c", "Contributor"
  46. + value :MEMBER, "m", "Member"
  47. + value :BANNED, "b", "Banned"
  48. +end
  49. \ No newline at end of file
  50. diff --git a/db/migrate/20090923052157_add_status_to_memberships.rb b/db/migrate/20090923052157_add_status_to_memberships.rb
  51. new file mode 100644
  52. index 0000000..b1d6318
  53. --- /dev/null
  54. +++ b/db/migrate/20090923052157_add_status_to_memberships.rb
  55. @@ -0,0 +1,10 @@
  56. +class AddStatusToMemberships < ActiveRecord::Migration
  57. + def self.up
  58. + add_column :memberships, :status_code, :string, :limit => 1, :default => "m"
  59. + execute("UPDATE memberships SET status_code = 'a' WHERE is_admin = #{quote(true)}")
  60. + end
  61. +
  62. + def self.down
  63. + remove_column :memberships, :status_code
  64. + end
  65. +end
  66. diff --git a/features/group_membership.feature b/features/group_membership.feature
  67. index c586c9b..d5393b6 100644
  68. --- a/features/group_membership.feature
  69. +++ b/features/group_membership.feature
  70. @@ -8,29 +8,20 @@ Scenario: Join a group as an unauthenticated user
  71.  
  72. When I visit the "test" group page
  73. And I follow "Join this group"
  74. - And I fill in "login" with "specialname"
  75. + And I fill in "login" with "francis"
  76. And I press "Submit"
  77.  
  78. Then I should be on the "test" group page
  79. And I should see "Leave this group"
  80. + And "francis" should have a membership status of "member" in "test" group
  81.  
  82. Scenario: Join a group as an authenticated user
  83.  
  84. - Given I am logged in
  85. + Given I am logged in as "bill"
  86.  
  87. - When I visit the "test" group page
  88. + When I visit the "test" group page
  89. And I follow "Join this group"
  90.  
  91. Then I should be on the "test" group page
  92. And I should see "Leave this group"
  93. -
  94. -# TODO: how about leaving a group?!
  95. -
  96. -Scenario: View group members
  97. -
  98. - Given the "Fishing" group has 20 members
  99. -
  100. - When I visit the "Fishing" group members page
  101. -
  102. - Then I should see 21 members listed
  103. - #including the creator
  104. + And "bill" should have a membership status of "member" in "test" group
  105. diff --git a/features/group_message_comments.feature b/features/group_message_comments.feature
  106. new file mode 100644
  107. index 0000000..310a68a
  108. --- /dev/null
  109. +++ b/features/group_message_comments.feature
  110. @@ -0,0 +1,59 @@
  111. +Feature: Group messages page
  112. +
  113. + The Messages page displays a paginated list of posted messages.
  114. +
  115. + Scenario: Follow link from the group page
  116. +
  117. + Given "Bob" is a member of the "Fishing" group
  118. +
  119. + When I visit the "Fishing" group page
  120. + And I follow "Messages"
  121. +
  122. + Then I should be on the "Fishing" group messages page
  123. +
  124. + Scenario: Make a valid ajax comment on a message
  125. +
  126. + Given "Bob" is a member of the "Fishing" group
  127. + And the "Fishing" group has 10 messages with 1 comment by "Bob" each
  128. + And I am logged in as "Bob"
  129. +
  130. + When I visit the "Fishing" group messages page
  131. + And I make an ajax comment with "Fishing is for assholes" on the 5th message of the "Fishing" group
  132. +
  133. + Then the response code should be 201
  134. +
  135. + Scenario: Make an invalid ajax comment on a message
  136. +
  137. + Given "Bob" is a member of the "Fishing" group
  138. + And the "Fishing" group has 10 messages with 1 comment by "Bob" each
  139. + And I am logged in as "Bob"
  140. +
  141. + When I visit the "Fishing" group messages page
  142. + And I make an ajax comment with "" on the 5th message of the "Fishing" group
  143. +
  144. + Then the response code should be 412
  145. +
  146. + Scenario: Make a valid regular comment on a message
  147. +
  148. + Given "Bob" is a member of the "Fishing" group
  149. + And the "Fishing" group has 1 messages with 0 comment by "Bob" each
  150. + And I am logged in as "Bob"
  151. +
  152. + When I visit the 1st message page for the "Fishing" group
  153. + And I make a comment with "Fishing is for halfwits" on the 1st message of the "Fishing" group
  154. +
  155. + Then I should see my "Fishing is for halfwits" on the 1st message of the "Fishing" group
  156. +
  157. + Scenario: Make an invalid regular comment on a message
  158. +
  159. + Given "Bob" is a member of the "Fishing" group
  160. + And the "Fishing" group has 1 messages with 0 comment by "Bob" each
  161. + And I am logged in as "Bob"
  162. +
  163. + When I visit the 1st message page for the "Fishing" group
  164. + And I make a comment with "" on the 1st message of the "Fishing" group
  165. +
  166. + Then I should see an error "You need to put a comment before you can post it"
  167. +
  168. +
  169. +
  170. \ No newline at end of file
  171. diff --git a/features/group_registration.feature b/features/group_registration.feature
  172. index daf6489..536a5c8 100644
  173. --- a/features/group_registration.feature
  174. +++ b/features/group_registration.feature
  175. @@ -28,8 +28,9 @@ Scenario: Register new group as an authenticated user
  176. And I should see "Watching Fireworks"
  177. And I should see "My group description"
  178. And I should see "Bob"
  179. + And "Bob" should have a membership status of "administrator" in "Watching Fireworks" group
  180.  
  181. -Scenario: Register new group as an authenticated user
  182. +Scenario: Register new group as an authenticated user with invalid configuration
  183.  
  184. Given I am logged in as "Bob"
  185. And I am on "/groups"
  186. diff --git a/features/message_post.feature b/features/message_post.feature
  187. index a68478d..ee07bf2 100644
  188. --- a/features/message_post.feature
  189. +++ b/features/message_post.feature
  190. @@ -5,17 +5,8 @@ Feature: Post a message
  191. Scenario: Member successfully posts a message
  192.  
  193. Given "Bob" is a member of the "Bob is a champ" group
  194. -
  195. When I am logged in as "Bob"
  196. - And I visit the "Bob is a champ" group page
  197. - And I fill in "message[title]" with "Bob went to see Bush"
  198. - And I fill in "message[content]" with "Bob visit Bush and dined with Bush at the White House"
  199. - And I press "Post Message"
  200. -
  201. - Then I should be on the "Bob is a champ" group page
  202. - And I should see "Bob went to see Bush"
  203. - And I should see "Bob visit Bush and dined with Bush at the White House"
  204. -
  205. + Then I can successfully post a message titled "Hi there" with content "posting ur message" to the "Bob is a champ" group
  206.  
  207. Scenario: Member successfully posts an image
  208.  
  209. @@ -33,4 +24,10 @@ Scenario: Member successfully posts an image
  210. And I should see "Bob visit Bush and dined with Bush at the White House"
  211. And I should see a 145 pixel wide version of "big_fish.jpg"
  212.  
  213. +Scenario: "Post a message as a non-member logged in user"
  214. + Given there is a "zombies" group
  215. + And I am logged in as "louis"
  216. + Then I can successfully post a message titled "Hi there" with content "posting ur message" to the "zombies" group
  217. + And "louis" should have a membership status of "contributor" in "test" group
  218. +
  219.  
  220. diff --git a/features/step_definitions/membership_steps.rb b/features/step_definitions/membership_steps.rb
  221. index 288af4c..34d0ca6 100644
  222. --- a/features/step_definitions/membership_steps.rb
  223. +++ b/features/step_definitions/membership_steps.rb
  224. @@ -68,4 +68,9 @@ Then /"(.+)" should (not)?\s?be banned from the "(.+)" group/ do |username, bann
  225. user = User.find_by_name(username)
  226. group = Group.find_by_name(group_name)
  227. group.membership_of(user).is_banned.should == (banned != "not")
  228. -end
  229. \ No newline at end of file
  230. +end
  231. +
  232. +Then /^"(.+)"should have a membership status of "(.+)" in "(.+)" group$/ do |user_name, membership_status, group_name|
  233. + group = Group.find_by_name(group_name)
  234. + group.membership.for_user(User[user_name]).status.should eql (membership_status)
  235. +end
  236. diff --git a/features/step_definitions/post_steps.rb b/features/step_definitions/post_steps.rb
  237. index 47aefd1..eee361c 100644
  238. --- a/features/step_definitions/post_steps.rb
  239. +++ b/features/step_definitions/post_steps.rb
  240. @@ -77,7 +77,6 @@ When /I visit the "(.+)" (message|photo) page for the "(.+)" group/ do |post_tit
  241. visit send("group_#{post_type}_path", group, post)
  242. end
  243.  
  244. -
  245. Then /^I should be on the "(.*)" post page$/ do |title|
  246. post = Post.find_by_title(title)
  247. expected_path = url_for(
  248. @@ -90,12 +89,9 @@ Then /^I should be on the "(.*)" post page$/ do |title|
  249. end
  250.  
  251. Then /^I should see my "(.+)" on the (\d+)\w{2} message of the "(.%
Add Comment
Please, Sign In to add comment