Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'faker'
- FactoryBot.define do
- factory :user do
- name { Faker::Name.name }
- email { Faker::Internet.email }
- password { Faker::Internet.password }
- end
- factory :budget do
- name { Faker::Name.name }
- user
- end
- factory :budget_entry do
- category { "Food" }
- name { Faker::Name.name}
- price { "$67.32" }
- date { Faker::Date.in_date_period(month:2)}
- budget
- user
- end
- end
- RSpec.describe "BudgetEntries", type: :request do
- describe "controller methods" do
- before(:each) do
- @user = create(:user)
- @budget = create(:budget, user_id: @user.id)
- end
- let(:budget_entries_params) do
- {
- budget_entry: {
- category: "Food",
- name: "cabbage",
- price: "3.50",
- budget_id: @budget.id
- }
- }
- end
- context "GET /index" do
- it "should return unauthorized if user is not logged in" do
- get api_v1_budget_entries_path
- expect(response).to have_http_status(401)
- end
- it "should return 200 if user is logged in" do
- headers = { 'Accept' => 'application/json' }
- auth_headers = Devise::JWT::TestHelpers.auth_headers(headers, @user)
- get api_v1_budget_entries_path, headers: auth_headers
- expect(response).to have_http_status(200)
- end
- end
- def index
- budget = Budget.where(id: params[:id])[0]
- budget_entries = BudgetEntry.where(budget_id: budget.id)
- ...
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement