Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. require 'rails_helper'
  2.  
  3. RSpec.describe "UserPages", type: :request do
  4. subject { page }
  5.  
  6. context "signup page" do
  7. before { visit signup_path }
  8. it { is_expected.to have_content('Sign up') }
  9. it { is_expected.to have_title('Sign up') }
  10.  
  11. context "invalid registration" do
  12. before do
  13. click_button "new account"
  14. end
  15.  
  16. it { expect{ page }.not_to change(User, :count) }
  17. it { is_expected.to have_content("4 errors") }
  18. end
  19.  
  20. context "valid registration" do
  21. let!(:new_user) { User.new(email: "email@gmail.com", password: "ruby_lang", password_confirmation: "ruby_lang") }
  22. before do
  23. fill_in "Email", with: new_user.email
  24. fill_in "Password", with: new_user.password
  25. fill_in "Password confirmation", with: new_user.password_confirmation
  26. end
  27. it { expect{ click_button "new account" }.to change(User, :count).by(1) }
  28.  
  29. context "after valid registration/sign_in" do
  30. before { click_button "new account" }
  31. it { is_expected.to have_title(new_user.email) }
  32.  
  33. context "edit" do
  34. let!(:user) { create :user }
  35. let!(:user_email) { user.email }
  36. before do
  37. valid_signin(user)
  38. visit edit_user_path(user)
  39. end
  40. it { is_expected.to have_title("Edit #{user.email}") }
  41. it { is_expected.to have_button("Save changes") }
  42. xit { expect(page).to have_css("input", value: "#{user.email}") }
  43. it { is_expected.to have_selector("input[placeholder='Change email']") }
  44. it { is_expected.to have_selector("input[placeholder='Change password']") }
  45. it { is_expected.to have_selector("input[placeholder='Password confirmation']") }
  46.  
  47. context "valid" do
  48. before do
  49. fill_in "Change email", with: "good_email@gmail.com"
  50. fill_in "Change password", with: "gendalf"
  51. fill_in "Password confirmation", with: "gendalf"
  52. click_button "Save changes"
  53. end
  54. it { is_expected.to have_title("Home") }
  55. it { is_expected.to have_content("User updated") }
  56. it { expect(User.exists?(email: "good_email@gmail.com")).to be(true) }
  57. it { expect(User.exists?(email: "#{user.email}")).to be(false) }
  58. end
  59.  
  60. context "invalid" do
  61. before { click_button "Save changes" }
  62. it { is_expected.to have_selector(".alert-error") }
  63. it { is_expected.to have_title("Edit #{user.email}")}
  64. end
  65. end
  66.  
  67. context "create project" do
  68. let!(:user) { User.create!(email: "shmendalf@gmail.com", password: "ruby_lang", password_confirmation: "ruby_lang") }
  69. before do
  70. valid_signin(user)
  71. visit user_path(user)
  72. end
  73.  
  74. context "success" do
  75. before { fill_in "Create project", with: "my second project" }
  76. it { expect{ click_button "new project" }.to change(user.projects, :count).by(1) }
  77. it { expect{ click_button "new project" }.to change(Project, :count).by(1) }
  78.  
  79. context "show success message" do
  80. before { click_button "new project" }
  81. it { is_expected.to have_content("project created") }
  82. end
  83. end
  84.  
  85. context "show unsuccess message" do
  86. before { click_button "new project" }
  87. it { expect{ click_button "new project" }.to change(user.projects, :count).by(0) }
  88. it { expect{ click_button "new project" }.to change(Project, :count).by(0) }
  89. it { is_expected.to have_content("project not created") }
  90. end
  91. end
  92. end
  93. end
  94. end
  95.  
  96. context "after sign in" do
  97. let!(:usr) { create :user }
  98. let!(:prj) { create :project, user: usr }
  99. before { valid_signin(usr) }
  100.  
  101. context "update project" do
  102. before { visit user_path(usr) }
  103.  
  104. context "valid" do
  105. before do
  106. fill_in "Update project", with: "Dance"
  107. click_button "Save"
  108. end
  109. it { is_expected.to have_content("Dance") }
  110. it { expect( usr.projects.find(prj.id).name).to eq("Dance") }
  111. it { expect( Project.find_by_name("My first project")).to be(nil) }
  112. end
  113.  
  114. context "invalid" do
  115. before do
  116. fill_in "Update project", with: ""
  117. click_button "Save"
  118. end
  119. it { is_expected.to have_content("Project not updated") }
  120. end
  121. end
  122.  
  123. context "delete" do
  124. before { visit user_path(usr) }
  125. it do
  126. expect{ click_link "delete" }.to change(usr.projects, :count).by(-1)
  127. is_expected.to have_content("Project deleted.")
  128. end
  129. end
  130. end
  131. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement