Loading ...
Sorry, an error occurred while loading the content.
 

Fabricator

Expand Messages
  • Denny Santoso
    Guys, saya lagi coba fabricators with rspec: describe GET show do it sets @video for authenticated user do user = User.create(email:
    Message 1 of 15 , Nov 11, 2013
      Guys, 
      saya lagi coba fabricators with rspec:

      describe "GET show" do   
          it "sets @video for authenticated user" do
            user = User.create(email: "dennysantoso.com@...", full_name: "Denny Santoso", password: "admin", password_confirmation: "admin")
            session[:user_id] = user.id
            video1 = Fabricate(:video)
            get :show, id: video1.id
            expect(assigns(:video)).to eq(video1)
          end

      dengan video_fabricator.rb isinya:
      Fabricator(:video) do
        title { Faker::Lorem.words(5) }
        description { Faker::Lorem.paragraph(2) }
      end

      waktu rspecnya dijalanin, muncul errornya:

      Failures:

        1) VideosController GET show sets @video for authenticated user
           Failure/Error: video1 = Fabricate(:video)
           ActiveRecord::StatementInvalid:
             TypeError: can't cast Array to string: INSERT INTO "videos" ("created_at", "description", "title", "updated_at") VALUES (?, ?, ?, ?)
           # ./spec/controllers/videos_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

      Finished in 0.26621 seconds
      3 examples, 1 failure

      dimana ya errornya?



    • Giovanni Sakti
      Saya belum pernah pakai gem fabricators/faker, tapi mungkin return-nya Faker::Lorem.words(5) adalah array? padahal seharusnya string.. mungkin bisa dicoba
      Message 2 of 15 , Nov 11, 2013
        Saya belum pernah pakai gem fabricators/faker,

        tapi mungkin return-nya Faker::Lorem.words(5) adalah array? padahal seharusnya string..
        mungkin bisa dicoba 

        title { Faker::Lorem.words(5).to_s }
        description { Faker::Lorem.paragraph(2).to_s }

        --
        Giovanni Sakti - http://www.mightygio.com
        Starqle Indonesia - http://www.starqle.com

        On Tuesday, 12 November 2013 at 11.04, Denny Santoso wrote:

         

        Guys, 

        saya lagi coba fabricators with rspec:

        describe "GET show" do   
            it "sets @video for authenticated user" do
              user = User.create(email: "dennysantoso.com@...", full_name: "Denny Santoso", password: "admin", password_confirmation: "admin")
              session[:user_id] = user.id
              video1 = Fabricate(:video)
              get :show, id: video1.id
              expect(assigns(:video)).to eq(video1)
            end

        dengan video_fabricator.rb isinya:
        Fabricator(:video) do
          title { Faker::Lorem.words(5) }
          description { Faker::Lorem.paragraph(2) }
        end

        waktu rspecnya dijalanin, muncul errornya:

        Failures:

          1) VideosController GET show sets @video for authenticated user
             Failure/Error: video1 = Fabricate(:video)
             ActiveRecord::StatementInvalid:
               TypeError: can't cast Array to string: INSERT INTO "videos" ("created_at", "description", "title", "updated_at") VALUES (?, ?, ?, ?)
             # ./spec/controllers/videos_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

        Finished in 0.26621 seconds
        3 examples, 1 failure

        dimana ya errornya?




      • Pavel Evstigneev
        Did you try FactoryGirl ? It works well with rails. Instead “ session[:user_id] = user.id “ better use: (in case of devise) # spec_helper.rb config.include
        Message 3 of 15 , Nov 11, 2013
          Did you try FactoryGirl ? It works well with rails.

          Instead “ session[:user_id] = user.id “ better use: (in case of devise)

            # spec_helper.rb
            config.include Devise::TestHelpers, :type => :controller

            # video_controller_spec.rb
            before do
              @...["devise.mapping"] = Devise.mappings[:user]
              @user = FactoryGirl.create(:user, :confirmed)
              sign_in @user
            end

          On Tuesday, November 12, 2013 at 11:04 AM, Denny Santoso wrote:

           

          Guys, 

          saya lagi coba fabricators with rspec:

          describe "GET show" do   
              it "sets @video for authenticated user" do
                user = User.create(email: "dennysantoso.com@...", full_name: "Denny Santoso", password: "admin", password_confirmation: "admin")
                session[:user_id] = user.id
                video1 = Fabricate(:video)
                get :show, id: video1.id
                expect(assigns(:video)).to eq(video1)
              end

          dengan video_fabricator.rb isinya:
          Fabricator(:video) do
            title { Faker::Lorem.words(5) }
            description { Faker::Lorem.paragraph(2) }
          end

          waktu rspecnya dijalanin, muncul errornya:

          Failures:

            1) VideosController GET show sets @video for authenticated user
               Failure/Error: video1 = Fabricate(:video)
               ActiveRecord::StatementInvalid:
                 TypeError: can't cast Array to string: INSERT INTO "videos" ("created_at", "description", "title", "updated_at") VALUES (?, ?, ?, ?)
               # ./spec/controllers/videos_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

          Finished in 0.26621 seconds
          3 examples, 1 failure

          dimana ya errornya?




        • Denny Santoso
          ah, yang working yang title dikasih to_s, kalau yang paragraph, tetap originalnya sih gpp Thanks mas Giovanni :) Regards, @DennySantoso LinkedIn:
          Message 4 of 15 , Nov 11, 2013
            ah, yang working yang title dikasih to_s, kalau yang paragraph, tetap originalnya sih gpp

            Thanks mas Giovanni :)


            On Nov 12, 2013, at 11:09 AM, Giovanni Sakti <giosakti@...> wrote:


            Saya belum pernah pakai gem fabricators/faker,

            tapi mungkin return-nya Faker::Lorem.words(5) adalah array? padahal seharusnya string..
            mungkin bisa dicoba 

            title { Faker::Lorem.words(5).to_s }
            description { Faker::Lorem.paragraph(2).to_s }

            --
            Giovanni Sakti - http://www.mightygio.com
            Starqle Indonesia - http://www.starqle.com

            On Tuesday, 12 November 2013 at 11.04, Denny Santoso wrote:

             

            Guys, 

            saya lagi coba fabricators with rspec:

            describe "GET show" do   
                it "sets @video for authenticated user" do
                  user = User.create(email: "dennysantoso.com@...", full_name: "Denny Santoso", password: "admin", password_confirmation: "admin")
                  session[:user_id] = user.id
                  video1 = Fabricate(:video)
                  get :show, id: video1.id
                  expect(assigns(:video)).to eq(video1)
                end

            dengan video_fabricator.rb isinya:
            Fabricator(:video) do
              title { Faker::Lorem.words(5) }
              description { Faker::Lorem.paragraph(2) }
            end

            waktu rspecnya dijalanin, muncul errornya:

            Failures:

              1) VideosController GET show sets @video for authenticated user
                 Failure/Error: video1 = Fabricate(:video)
                 ActiveRecord::StatementInvalid:
                   TypeError: can't cast Array to string: INSERT INTO "videos" ("created_at", "description", "title", "updated_at") VALUES (?, ?, ?, ?)
                 # ./spec/controllers/videos_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

            Finished in 0.26621 seconds
            3 examples, 1 failure

            dimana ya errornya?


            Regards,
            @DennySantoso

            LinkedIn: http://id.linkedin.com/in/dennysantoso




          • Achmad Gozali
            atau bisa juga diganti Faker::Lorem.words(5) nya dengan Faker::Lorem.sentence(2) Koh Denny SOL -- gozali
            Message 5 of 15 , Nov 11, 2013
              atau bisa juga diganti Faker::Lorem.words(5) nya dengan Faker::Lorem.sentence(2) Koh Denny

              SOL

              -- 
              gozali

              On Tuesday, November 12, 2013 at 11:13 AM, Denny Santoso wrote:

               

              ah, yang working yang title dikasih to_s, kalau yang paragraph, tetap originalnya sih gpp


              Thanks mas Giovanni :)


              On Nov 12, 2013, at 11:09 AM, Giovanni Sakti <giosakti@...> wrote:


              Saya belum pernah pakai gem fabricators/faker,

              tapi mungkin return-nya Faker::Lorem.words(5) adalah array? padahal seharusnya string..
              mungkin bisa dicoba 

              title { Faker::Lorem.words(5).to_s }
              description { Faker::Lorem.paragraph(2).to_s }

              --
              Giovanni Sakti - http://www.mightygio.com
              Starqle Indonesia - http://www.starqle.com

              On Tuesday, 12 November 2013 at 11.04, Denny Santoso wrote:

               

              Guys, 

              saya lagi coba fabricators with rspec:

              describe "GET show" do   
                  it "sets @video for authenticated user" do
                    user = User.create(email: "dennysantoso.com@...", full_name: "Denny Santoso", password: "admin", password_confirmation: "admin")
                    session[:user_id] = user.id
                    video1 = Fabricate(:video)
                    get :show, id: video1.id
                    expect(assigns(:video)).to eq(video1)
                  end

              dengan video_fabricator.rb isinya:
              Fabricator(:video) do
                title { Faker::Lorem.words(5) }
                description { Faker::Lorem.paragraph(2) }
              end

              waktu rspecnya dijalanin, muncul errornya:

              Failures:

                1) VideosController GET show sets @video for authenticated user
                   Failure/Error: video1 = Fabricate(:video)
                   ActiveRecord::StatementInvalid:
                     TypeError: can't cast Array to string: INSERT INTO "videos" ("created_at", "description", "title", "updated_at") VALUES (?, ?, ?, ?)
                   # ./spec/controllers/videos_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

              Finished in 0.26621 seconds
              3 examples, 1 failure

              dimana ya errornya?


              Regards,
              @DennySantoso

              LinkedIn: http://id.linkedin.com/in/dennysantoso





            • Giovanni Sakti
              agreed with what Pavel said, you may also try FactoryGirl.. however YMMV, FactoryGirl is older, has many stars and forks in github so (probably) has better
              Message 6 of 15 , Nov 11, 2013
                agreed with what Pavel said, you may also try FactoryGirl.. 

                however YMMV, 

                FactoryGirl is older, has many stars and forks in github so (probably) has better support..
                but.. from what I seen Fabricator is newer and more modern

                --
                Giovanni Sakti - http://www.mightygio.com
                Starqle Indonesia - http://www.starqle.com

                On Tuesday, 12 November 2013 at 11.10, Pavel Evstigneev wrote:

                 

                Did you try FactoryGirl ? It works well with rails.

                Instead “ session[:user_id] = user.id “ better use: (in case of devise)

                  # spec_helper.rb
                  config.include Devise::TestHelpers, :type => :controller

                  # video_controller_spec.rb
                  before do
                    @...["devise.mapping"] = Devise.mappings[:user]
                    @user = FactoryGirl.create(:user, :confirmed)
                    sign_in @user
                  end

                On Tuesday, November 12, 2013 at 11:04 AM, Denny Santoso wrote:

                 

                Guys, 

                saya lagi coba fabricators with rspec:

                describe "GET show" do   
                    it "sets @video for authenticated user" do
                      user = User.create(email: "dennysantoso.com@...", full_name: "Denny Santoso", password: "admin", password_confirmation: "admin")
                      session[:user_id] = user.id
                      video1 = Fabricate(:video)
                      get :show, id: video1.id
                      expect(assigns(:video)).to eq(video1)
                    end

                dengan video_fabricator.rb isinya:
                Fabricator(:video) do
                  title { Faker::Lorem.words(5) }
                  description { Faker::Lorem.paragraph(2) }
                end

                waktu rspecnya dijalanin, muncul errornya:

                Failures:

                  1) VideosController GET show sets @video for authenticated user
                     Failure/Error: video1 = Fabricate(:video)
                     ActiveRecord::StatementInvalid:
                       TypeError: can't cast Array to string: INSERT INTO "videos" ("created_at", "description", "title", "updated_at") VALUES (?, ?, ?, ?)
                     # ./spec/controllers/videos_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

                Finished in 0.26621 seconds
                3 examples, 1 failure

                dimana ya errornya?





              • Denny Santoso
                belum di ajarin nih di tutorialnya, masih materi controller rspec :) ga pake devise sih ini, manual from scratch semuanya :) Regards, @DennySantoso LinkedIn:
                Message 7 of 15 , Nov 11, 2013
                  belum di ajarin nih di tutorialnya, masih materi controller rspec :)

                  ga pake devise sih ini, manual from scratch semuanya :)


                  On Nov 12, 2013, at 11:10 AM, Pavel Evstigneev <pavel.evst@...> wrote:


                  Did you try FactoryGirl ? It works well with rails.

                  Instead “ session[:user_id] = user.id “ better use: (in case of devise)

                    # spec_helper.rb
                    config.include Devise::TestHelpers, :type => :controller

                    # video_controller_spec.rb
                    before do
                      @...["devise.mapping"] = Devise.mappings[:user]
                      @user = FactoryGirl.create(:user, :confirmed)
                      sign_in @user
                    end

                  On Tuesday, November 12, 2013 at 11:04 AM, Denny Santoso wrote:

                   

                  Guys, 

                  saya lagi coba fabricators with rspec:

                  describe "GET show" do   
                      it "sets @video for authenticated user" do
                        user = User.create(email: "dennysantoso.com@...", full_name: "Denny Santoso", password: "admin", password_confirmation: "admin")
                        session[:user_id] = user.id
                        video1 = Fabricate(:video)
                        get :show, id: video1.id
                        expect(assigns(:video)).to eq(video1)
                      end

                  dengan video_fabricator.rb isinya:
                  Fabricator(:video) do
                    title { Faker::Lorem.words(5) }
                    description { Faker::Lorem.paragraph(2) }
                  end

                  waktu rspecnya dijalanin, muncul errornya:

                  Failures:

                    1) VideosController GET show sets @video for authenticated user
                       Failure/Error: video1 = Fabricate(:video)
                       ActiveRecord::StatementInvalid:
                         TypeError: can't cast Array to string: INSERT INTO "videos" ("created_at", "description", "title", "updated_at") VALUES (?, ?, ?, ?)
                       # ./spec/controllers/videos_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

                  Finished in 0.26621 seconds
                  3 examples, 1 failure

                  dimana ya errornya?


                  Regards,
                  @DennySantoso

                  LinkedIn: http://id.linkedin.com/in/dennysantoso




                • Denny Santoso
                  ah, sip2, thx bro :) Regards, @DennySantoso LinkedIn: http://id.linkedin.com/in/dennysantoso www.DennySantoso.com
                  Message 8 of 15 , Nov 11, 2013
                    ah, sip2, thx bro :)


                    On Nov 12, 2013, at 11:18 AM, Achmad Gozali <hello@...> wrote:


                    atau bisa juga diganti Faker::Lorem.words(5) nya dengan Faker::Lorem.sentence(2) Koh Denny

                    SOL

                    -- 
                    gozali

                    On Tuesday, November 12, 2013 at 11:13 AM, Denny Santoso wrote:

                     

                    ah, yang working yang title dikasih to_s, kalau yang paragraph, tetap originalnya sih gpp


                    Thanks mas Giovanni :)

                    Regards,
                    @DennySantoso

                    LinkedIn: http://id.linkedin.com/in/dennysantoso
                    On Nov 12, 2013, at 11:09 AM, Giovanni Sakti <giosakti@...> wrote:


                    Saya belum pernah pakai gem fabricators/faker,

                    tapi mungkin return-nya Faker::Lorem.words(5) adalah array? padahal seharusnya string..
                    mungkin bisa dicoba 

                    title { Faker::Lorem.words(5).to_s }
                    description { Faker::Lorem.paragraph(2).to_s }

                    --
                    Giovanni Sakti - http://www.mightygio.com
                    Starqle Indonesia - http://www.starqle.com

                    On Tuesday, 12 November 2013 at 11.04, Denny Santoso wrote:

                    Guys, 

                    saya lagi coba fabricators with rspec:

                    describe "GET show" do   
                        it "sets @video for authenticated user" do
                          user = User.create(email: "dennysantoso.com@...", full_name: "Denny Santoso", password: "admin", password_confirmation: "admin")
                          session[:user_id] = user.id
                          video1 = Fabricate(:video)
                          get :show, id: video1.id
                          expect(assigns(:video)).to eq(video1)
                        end

                    dengan video_fabricator.rb isinya:
                    Fabricator(:video) do
                      title { Faker::Lorem.words(5) }
                      description { Faker::Lorem.paragraph(2) }
                    end

                    waktu rspecnya dijalanin, muncul errornya:

                    Failures:

                      1) VideosController GET show sets @video for authenticated user
                         Failure/Error: video1 = Fabricate(:video)
                         ActiveRecord::StatementInvalid:
                           TypeError: can't cast Array to string: INSERT INTO "videos" ("created_at", "description", "title", "updated_at") VALUES (?, ?, ?, ?)
                         # ./spec/controllers/videos_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

                    Finished in 0.26621 seconds
                    3 examples, 1 failure

                    dimana ya errornya?


                    Regards,
                    @DennySantoso

                    LinkedIn: http://id.linkedin.com/in/dennysantoso








                  • Denny Santoso
                    Next problem nih ketika masuk ke test searchnya: describe POST search do it sets @results for authenticated user do session[:user_id] = Fabricate(:user).id
                    Message 9 of 15 , Nov 11, 2013
                      Next problem nih ketika masuk ke test searchnya:

                      describe "POST search" do
                          it "sets @results for authenticated user" do
                            session[:user_id] = Fabricate(:user).id
                            futurama = Fabricate(:video, title: "Futurama")
                            post :search, search_term: "ura"
                            expect(assigns(:results)).to eq([futurama])
                          end
                      end

                      Muncul errornya:

                      Failures:

                        1) VideosController POST search sets @results for authenticated user
                           Failure/Error: expect(assigns(:results)).to eq([futurama])

                             

                             expected: [#<Video id: 1, title: "Futurama", description: "Delectus et vel voluptate qui aut. Rem illum adipis...", small_cover_url: nil, large_cover_url: nil, created_at: "2013-11-12 04:21:38", updated_at: "2013-11-12 04:21:38", category_id: nil>]
                                  got: nil

                             

                             (compared using ==)
                           # ./spec/controllers/videos_controller_spec.rb:24:in `block (3 levels) in <top (required)>'

                      Finished in 0.28727 seconds
                      4 examples, 1 failure


                      Note: tanpa test, searchnya berhasil jalan dengan baik padahal

                      videos_controllernya:

                      def search
                          @categories = Category.all
                          @videos = Video.search_by_title(params[:search_term])
                        end

                      dan di Video Modelnya

                      def self.search_by_title(search_term)
                          return [] if search_term.blank?
                          where("title like ?", "%#{search_term}%").order(created_at: :desc)
                        end



                      On Nov 12, 2013, at 11:18 AM, Achmad Gozali <hello@...> wrote:


                      atau bisa juga diganti Faker::Lorem.words(5) nya dengan Faker::Lorem.sentence(2) Koh Denny

                      SOL

                      -- 
                      gozali

                      On Tuesday, November 12, 2013 at 11:13 AM, Denny Santoso wrote:

                       

                      ah, yang working yang title dikasih to_s, kalau yang paragraph, tetap originalnya sih gpp


                      Thanks mas Giovanni :)

                      Regards,
                      @DennySantoso

                      LinkedIn: http://id.linkedin.com/in/dennysantoso
                      On Nov 12, 2013, at 11:09 AM, Giovanni Sakti <giosakti@...> wrote:


                      Saya belum pernah pakai gem fabricators/faker,

                      tapi mungkin return-nya Faker::Lorem.words(5) adalah array? padahal seharusnya string..
                      mungkin bisa dicoba 

                      title { Faker::Lorem.words(5).to_s }
                      description { Faker::Lorem.paragraph(2).to_s }

                      --
                      Giovanni Sakti - http://www.mightygio.com
                      Starqle Indonesia - http://www.starqle.com

                      On Tuesday, 12 November 2013 at 11.04, Denny Santoso wrote:

                      Guys, 

                      saya lagi coba fabricators with rspec:

                      describe "GET show" do   
                          it "sets @video for authenticated user" do
                            user = User.create(email: "dennysantoso.com@...", full_name: "Denny Santoso", password: "admin", password_confirmation: "admin")
                            session[:user_id] = user.id
                            video1 = Fabricate(:video)
                            get :show, id: video1.id
                            expect(assigns(:video)).to eq(video1)
                          end

                      dengan video_fabricator.rb isinya:
                      Fabricator(:video) do
                        title { Faker::Lorem.words(5) }
                        description { Faker::Lorem.paragraph(2) }
                      end

                      waktu rspecnya dijalanin, muncul errornya:

                      Failures:

                        1) VideosController GET show sets @video for authenticated user
                           Failure/Error: video1 = Fabricate(:video)
                           ActiveRecord::StatementInvalid:
                             TypeError: can't cast Array to string: INSERT INTO "videos" ("created_at", "description", "title", "updated_at") VALUES (?, ?, ?, ?)
                           # ./spec/controllers/videos_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

                      Finished in 0.26621 seconds
                      3 examples, 1 failure

                      dimana ya errornya?


                      Regards,
                      @DennySantoso

                      LinkedIn: http://id.linkedin.com/in/dennysantoso








                    • Giovanni Sakti
                      lagi2 kita beda nih, haha ini pakai test default rails ya? dari awal belajar saya terlanjur pakai rspec untuk test soalnya.. kalau assigns(:results) diganti
                      Message 10 of 15 , Nov 11, 2013
                        lagi2 kita beda nih, haha ini pakai test default rails ya? dari awal belajar saya terlanjur pakai rspec untuk test soalnya..

                        kalau assigns(:results) diganti assigns(:videos) bisa ngga?

                        --
                        Giovanni Sakti - http://www.mightygio.com
                        Starqle Indonesia - http://www.starqle.com

                        On Tuesday, 12 November 2013 at 11.24, Denny Santoso wrote:

                         

                        Next problem nih ketika masuk ke test searchnya:


                        describe "POST search" do
                            it "sets @results for authenticated user" do
                              session[:user_id] = Fabricate(:user).id
                              futurama = Fabricate(:video, title: "Futurama")
                              post :search, search_term: "ura"
                              expect(assigns(:results)).to eq([futurama])
                            end
                        end

                        Muncul errornya:

                        Failures:

                          1) VideosController POST search sets @results for authenticated user
                             Failure/Error: expect(assigns(:results)).to eq([futurama])

                               

                               expected: [#<Video id: 1, title: "Futurama", description: "Delectus et vel voluptate qui aut. Rem illum adipis...", small_cover_url: nil, large_cover_url: nil, created_at: "2013-11-12 04:21:38", updated_at: "2013-11-12 04:21:38", category_id: nil>]
                                    got: nil

                               

                               (compared using ==)
                             # ./spec/controllers/videos_controller_spec.rb:24:in `block (3 levels) in <top (required)>'

                        Finished in 0.28727 seconds
                        4 examples, 1 failure


                        Note: tanpa test, searchnya berhasil jalan dengan baik padahal

                        videos_controllernya:

                        def search
                            @categories = Category.all
                            @videos = Video.search_by_title(params[:search_term])
                          end

                        dan di Video Modelnya

                        def self.search_by_title(search_term)
                            return [] if search_term.blank?
                            where("title like ?", "%#{search_term}%").order(created_at: :desc)
                          end



                        On Nov 12, 2013, at 11:18 AM, Achmad Gozali <hello@...> wrote:


                        atau bisa juga diganti Faker::Lorem.words(5) nya dengan Faker::Lorem.sentence(2) Koh Denny

                        SOL

                        -- 
                        gozali

                        On Tuesday, November 12, 2013 at 11:13 AM, Denny Santoso wrote:

                         

                        ah, yang working yang title dikasih to_s, kalau yang paragraph, tetap originalnya sih gpp


                        Thanks mas Giovanni :)

                        Regards,
                        @DennySantoso

                        LinkedIn: http://id.linkedin.com/in/dennysantoso
                        On Nov 12, 2013, at 11:09 AM, Giovanni Sakti <giosakti@...> wrote:


                        Saya belum pernah pakai gem fabricators/faker,

                        tapi mungkin return-nya Faker::Lorem.words(5) adalah array? padahal seharusnya string..
                        mungkin bisa dicoba 

                        title { Faker::Lorem.words(5).to_s }
                        description { Faker::Lorem.paragraph(2).to_s }

                        --
                        Giovanni Sakti - http://www.mightygio.com
                        Starqle Indonesia - http://www.starqle.com

                        On Tuesday, 12 November 2013 at 11.04, Denny Santoso wrote:

                        Guys, 

                        saya lagi coba fabricators with rspec:

                        describe "GET show" do   
                            it "sets @video for authenticated user" do
                              user = User.create(email: "dennysantoso.com@...", full_name: "Denny Santoso", password: "admin", password_confirmation: "admin")
                              session[:user_id] = user.id
                              video1 = Fabricate(:video)
                              get :show, id: video1.id
                              expect(assigns(:video)).to eq(video1)
                            end

                        dengan video_fabricator.rb isinya:
                        Fabricator(:video) do
                          title { Faker::Lorem.words(5) }
                          description { Faker::Lorem.paragraph(2) }
                        end

                        waktu rspecnya dijalanin, muncul errornya:

                        Failures:

                          1) VideosController GET show sets @video for authenticated user
                             Failure/Error: video1 = Fabricate(:video)
                             ActiveRecord::StatementInvalid:
                               TypeError: can't cast Array to string: INSERT INTO "videos" ("created_at", "description", "title", "updated_at") VALUES (?, ?, ?, ?)
                             # ./spec/controllers/videos_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

                        Finished in 0.26621 seconds
                        3 examples, 1 failure

                        dimana ya errornya?


                        Regards,
                        @DennySantoso

                        LinkedIn: http://id.linkedin.com/in/dennysantoso









                      • Zidni Mubarock
                        mungkin Fabricate(:video à) nya gagal makanya nil, mungkin nggak lolos validasinya. btw. sorry aku lom pernah pake Fabricate biasa pake FactoryGirl. ...
                        Message 11 of 15 , Nov 11, 2013

                          mungkin Fabricate(:video …) nya gagal makanya nil, mungkin nggak lolos validasinya.

                          btw. sorry aku lom pernah pake Fabricate biasa pake FactoryGirl.



                          On Nov 12, 2013, at 11:24 AM, Denny Santoso <dennysantoso.com@...> wrote:

                          Next problem nih ketika masuk ke test searchnya:


                          describe "POST search" do
                              it "sets @results for authenticated user" do
                                session[:user_id] = Fabricate(:user).id
                                futurama = Fabricate(:video, title: "Futurama")
                                post :search, search_term: "ura"
                                expect(assigns(:results)).to eq([futurama])
                              end
                          end

                          Muncul errornya:

                          Failures:

                            1) VideosController POST search sets @results for authenticated user
                               Failure/Error: expect(assigns(:results)).to eq([futurama])

                                 

                                 expected: [#<Video id: 1, title: "Futurama", description: "Delectus et vel voluptate qui aut. Rem illum adipis...", small_cover_url: nil, large_cover_url: nil, created_at: "2013-11-12 04:21:38", updated_at: "2013-11-12 04:21:38", category_id: nil>]
                                      got: nil

                                 

                                 (compared using ==)
                               # ./spec/controllers/videos_controller_spec.rb:24:in `block (3 levels) in <top (required)>'

                          Finished in 0.28727 seconds
                          4 examples, 1 failure


                          Note: tanpa test, searchnya berhasil jalan dengan baik padahal

                          videos_controllernya:

                          def search
                              @categories = Category.all
                              @videos = Video.search_by_title(params[:search_term])
                            end

                          dan di Video Modelnya

                          def self.search_by_title(search_term)
                              return [] if search_term.blank?
                              where("title like ?", "%#{search_term}%").order(created_at: :desc)
                            end



                          On Nov 12, 2013, at 11:18 AM, Achmad Gozali <hello@...> wrote:


                          atau bisa juga diganti Faker::Lorem.words(5) nya dengan Faker::Lorem.sentence(2) Koh Denny

                          SOL

                          -- 
                          gozali

                          On Tuesday, November 12, 2013 at 11:13 AM, Denny Santoso wrote:

                          ah, yang working yang title dikasih to_s, kalau yang paragraph, tetap originalnya sih gpp


                          Thanks mas Giovanni :)

                          Regards,
                          @DennySantoso

                          LinkedIn: http://id.linkedin.com/in/dennysantoso
                          On Nov 12, 2013, at 11:09 AM, Giovanni Sakti <giosakti@...> wrote:


                          Saya belum pernah pakai gem fabricators/faker,

                          tapi mungkin return-nya Faker::Lorem.words(5) adalah array? padahal seharusnya string..
                          mungkin bisa dicoba 

                          title { Faker::Lorem.words(5).to_s }
                          description { Faker::Lorem.paragraph(2).to_s }

                          --
                          Giovanni Sakti - http://www.mightygio.com
                          Starqle Indonesia - http://www.starqle.com

                          On Tuesday, 12 November 2013 at 11.04, Denny Santoso wrote:

                          Guys, 

                          saya lagi coba fabricators with rspec:

                          describe "GET show" do   
                              it "sets @video for authenticated user" do
                                user = User.create(email: "dennysantoso.com@...", full_name: "Denny Santoso", password: "admin", password_confirmation: "admin")
                                session[:user_id] = user.id
                                video1 = Fabricate(:video)
                                get :show, id: video1.id
                                expect(assigns(:video)).to eq(video1)
                              end

                          dengan video_fabricator.rb isinya:
                          Fabricator(:video) do
                            title { Faker::Lorem.words(5) }
                            description { Faker::Lorem.paragraph(2) }
                          end

                          waktu rspecnya dijalanin, muncul errornya:

                          Failures:

                            1) VideosController GET show sets @video for authenticated user
                               Failure/Error: video1 = Fabricate(:video)
                               ActiveRecord::StatementInvalid:
                                 TypeError: can't cast Array to string: INSERT INTO "videos" ("created_at", "description", "title", "updated_at") VALUES (?, ?, ?, ?)
                               # ./spec/controllers/videos_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

                          Finished in 0.26621 seconds
                          3 examples, 1 failure

                          dimana ya errornya?


                          Regards,
                          @DennySantoso

                          LinkedIn: http://id.linkedin.com/in/dennysantoso










                        • Denny Santoso
                          ini pake rspec sihà.. hmmmm, bisa tuh diganti videos :P Regards, @DennySantoso LinkedIn: http://id.linkedin.com/in/dennysantoso www.DennySantoso.com ... ini
                          Message 12 of 15 , Nov 11, 2013
                            ini pake rspec sih…..
                            hmmmm, bisa tuh diganti videos :P


                            On Nov 12, 2013, at 11:33 AM, Giovanni Sakti <giosakti@...> wrote:


                            lagi2 kita beda nih, haha ini pakai test default rails ya? dari awal belajar saya terlanjur pakai rspec untuk test soalnya..

                            kalau assigns(:results) diganti assigns(:videos) bisa ngga?

                            --
                            Giovanni Sakti - http://www.mightygio.com
                            Starqle Indonesia - http://www.starqle.com

                            On Tuesday, 12 November 2013 at 11.24, Denny Santoso wrote:

                             

                            Next problem nih ketika masuk ke test searchnya:


                            describe "POST search" do
                                it "sets @results for authenticated user" do
                                  session[:user_id] = Fabricate(:user).id
                                  futurama = Fabricate(:video, title: "Futurama")
                                  post :search, search_term: "ura"
                                  expect(assigns(:results)).to eq([futurama])
                                end
                            end

                            Muncul errornya:

                            Failures:

                              1) VideosController POST search sets @results for authenticated user
                                 Failure/Error: expect(assigns(:results)).to eq([futurama])

                                   

                                   expected: [#<Video id: 1, title: "Futurama", description: "Delectus et vel voluptate qui aut. Rem illum adipis...", small_cover_url: nil, large_cover_url: nil, created_at: "2013-11-12 04:21:38", updated_at: "2013-11-12 04:21:38", category_id: nil>]
                                        got: nil

                                   

                                   (compared using ==)
                                 # ./spec/controllers/videos_controller_spec.rb:24:in `block (3 levels) in <top (required)>'

                            Finished in 0.28727 seconds
                            4 examples, 1 failure


                            Note: tanpa test, searchnya berhasil jalan dengan baik padahal

                            videos_controllernya:

                            def search
                                @categories = Category.all
                                @videos = Video.search_by_title(params[:search_term])
                              end

                            dan di Video Modelnya

                            def self.search_by_title(search_term)
                                return [] if search_term.blank?
                                where("title like ?", "%#{search_term}%").order(created_at: :desc)
                              end


                            Regards,
                            @DennySantoso

                            LinkedIn: http://id.linkedin.com/in/dennysantoso
                            On Nov 12, 2013, at 11:18 AM, Achmad Gozali <hello@...> wrote:


                            atau bisa juga diganti Faker::Lorem.words(5) nya dengan Faker::Lorem.sentence(2) Koh Denny

                            SOL

                            -- 
                            gozali

                            On Tuesday, November 12, 2013 at 11:13 AM, Denny Santoso wrote:

                            ah, yang working yang title dikasih to_s, kalau yang paragraph, tetap originalnya sih gpp


                            Thanks mas Giovanni :)

                            Regards,
                            @DennySantoso

                            LinkedIn: http://id.linkedin.com/in/dennysantoso
                            On Nov 12, 2013, at 11:09 AM, Giovanni Sakti <giosakti@...> wrote:


                            Saya belum pernah pakai gem fabricators/faker,

                            tapi mungkin return-nya Faker::Lorem.words(5) adalah array? padahal seharusnya string..
                            mungkin bisa dicoba 

                            title { Faker::Lorem.words(5).to_s }
                            description { Faker::Lorem.paragraph(2).to_s }

                            --
                            Giovanni Sakti - http://www.mightygio.com
                            Starqle Indonesia - http://www.starqle.com

                            On Tuesday, 12 November 2013 at 11.04, Denny Santoso wrote:

                            Guys, 

                            saya lagi coba fabricators with rspec:

                            describe "GET show" do   
                                it "sets @video for authenticated user" do
                                  user = User.create(email: "dennysantoso.com@...", full_name: "Denny Santoso", password: "admin", password_confirmation: "admin")
                                  session[:user_id] = user.id
                                  video1 = Fabricate(:video)
                                  get :show, id: video1.id
                                  expect(assigns(:video)).to eq(video1)
                                end

                            dengan video_fabricator.rb isinya:
                            Fabricator(:video) do
                              title { Faker::Lorem.words(5) }
                              description { Faker::Lorem.paragraph(2) }
                            end

                            waktu rspecnya dijalanin, muncul errornya:

                            Failures:

                              1) VideosController GET show sets @video for authenticated user
                                 Failure/Error: video1 = Fabricate(:video)
                                 ActiveRecord::StatementInvalid:
                                   TypeError: can't cast Array to string: INSERT INTO "videos" ("created_at", "description", "title", "updated_at") VALUES (?, ?, ?, ?)
                                 # ./spec/controllers/videos_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

                            Finished in 0.26621 seconds
                            3 examples, 1 failure

                            dimana ya errornya?


                            Regards,
                            @DennySantoso

                            LinkedIn: http://id.linkedin.com/in/dennysantoso












                          • Adi Nugroho
                            coba di fungsi expectnya diganti dengan expect(result).to eq([futurama])
                            Message 13 of 15 , Nov 11, 2013
                              coba di fungsi expectnya diganti dengan 

                              expect(result).to eq([futurama])

                              On Nov 12, 2013, at 11:24 AM, Denny Santoso <dennysantoso.com@...> wrote:

                               

                              Next problem nih ketika masuk ke test searchnya:


                              describe "POST search" do
                                  it "sets @results for authenticated user" do
                                    session[:user_id] = Fabricate(:user).id
                                    futurama = Fabricate(:video, title: "Futurama")
                                    post :search, search_term: "ura"
                                    expect(assigns(:results)).to eq([futurama])
                                  end
                              end

                              Muncul errornya:

                              Failures:

                                1) VideosController POST search sets @results for authenticated user
                                   Failure/Error: expect(assigns(:results)).to eq([futurama])

                                     

                                     expected: [#<Video id: 1, title: "Futurama", description: "Delectus et vel voluptate qui aut. Rem illum adipis...", small_cover_url: nil, large_cover_url: nil, created_at: "2013-11-12 04:21:38", updated_at: "2013-11-12 04:21:38", category_id: nil>]
                                          got: nil

                                     

                                     (compared using ==)
                                   # ./spec/controllers/videos_controller_spec.rb:24:in `block (3 levels) in <top (required)>'

                              Finished in 0.28727 seconds
                              4 examples, 1 failure


                              Note: tanpa test, searchnya berhasil jalan dengan baik padahal

                              videos_controllernya:

                              def search
                                  @categories = Category.all
                                  @videos = Video.search_by_title(params[:search_term])
                                end

                              dan di Video Modelnya

                              def self.search_by_title(search_term)
                                  return [] if search_term.blank?
                                  where("title like ?", "%#{search_term}%").order(created_at: :desc)
                                end



                              On Nov 12, 2013, at 11:18 AM, Achmad Gozali <hello@...> wrote:


                              atau bisa juga diganti Faker::Lorem.words(5) nya dengan Faker::Lorem.sentence(2) Koh Denny

                              SOL

                              -- 
                              gozali

                              On Tuesday, November 12, 2013 at 11:13 AM, Denny Santoso wrote:

                              ah, yang working yang title dikasih to_s, kalau yang paragraph, tetap originalnya sih gpp


                              Thanks mas Giovanni :)

                              Regards,
                              @DennySantoso

                              LinkedIn: http://id.linkedin.com/in/dennysantoso
                              On Nov 12, 2013, at 11:09 AM, Giovanni Sakti <giosakti@...> wrote:


                              Saya belum pernah pakai gem fabricators/faker,

                              tapi mungkin return-nya Faker::Lorem.words(5) adalah array? padahal seharusnya string..
                              mungkin bisa dicoba 

                              title { Faker::Lorem.words(5).to_s }
                              description { Faker::Lorem.paragraph(2).to_s }

                              --
                              Giovanni Sakti - http://www.mightygio.com
                              Starqle Indonesia - http://www.starqle.com

                              On Tuesday, 12 November 2013 at 11.04, Denny Santoso wrote:

                              Guys, 

                              saya lagi coba fabricators with rspec:

                              describe "GET show" do   
                                  it "sets @video for authenticated user" do
                                    user = User.create(email: "dennysantoso.com@...", full_name: "Denny Santoso", password: "admin", password_confirmation: "admin")
                                    session[:user_id] = user.id
                                    video1 = Fabricate(:video)
                                    get :show, id: video1.id
                                    expect(assigns(:video)).to eq(video1)
                                  end

                              dengan video_fabricator.rb isinya:
                              Fabricator(:video) do
                                title { Faker::Lorem.words(5) }
                                description { Faker::Lorem.paragraph(2) }
                              end

                              waktu rspecnya dijalanin, muncul errornya:

                              Failures:

                                1) VideosController GET show sets @video for authenticated user
                                   Failure/Error: video1 = Fabricate(:video)
                                   ActiveRecord::StatementInvalid:
                                     TypeError: can't cast Array to string: INSERT INTO "videos" ("created_at", "description", "title", "updated_at") VALUES (?, ?, ?, ?)
                                   # ./spec/controllers/videos_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

                              Finished in 0.26621 seconds
                              3 examples, 1 failure

                              dimana ya errornya?


                              Regards,
                              @DennySantoso

                              LinkedIn: http://id.linkedin.com/in/dennysantoso










                            • Sidharta Surya Kusnanto
                              Iya mungkin return method words nya itu array of string. Kalo gitu, harus di join arraynya biar jadi one long string.
                              Message 14 of 15 , Nov 11, 2013

                                Iya mungkin return method words nya itu array of string. Kalo gitu, harus di join arraynya biar jadi one long string.

                                On Nov 12, 2013 12:09 PM, "Giovanni Sakti" <giosakti@...> wrote:
                                 

                                Saya belum pernah pakai gem fabricators/faker,

                                tapi mungkin return-nya Faker::Lorem.words(5) adalah array? padahal seharusnya string..
                                mungkin bisa dicoba 

                                title { Faker::Lorem.words(5).to_s }
                                description { Faker::Lorem.paragraph(2).to_s }

                                --
                                Giovanni Sakti - http://www.mightygio.com
                                Starqle Indonesia - http://www.starqle.com

                                On Tuesday, 12 November 2013 at 11.04, Denny Santoso wrote:

                                 

                                Guys, 

                                saya lagi coba fabricators with rspec:

                                describe "GET show" do   
                                    it "sets @video for authenticated user" do
                                      user = User.create(email: "dennysantoso.com@...", full_name: "Denny Santoso", password: "admin", password_confirmation: "admin")
                                      session[:user_id] = user.id
                                      video1 = Fabricate(:video)
                                      get :show, id: video1.id
                                      expect(assigns(:video)).to eq(video1)
                                    end

                                dengan video_fabricator.rb isinya:
                                Fabricator(:video) do
                                  title { Faker::Lorem.words(5) }
                                  description { Faker::Lorem.paragraph(2) }
                                end

                                waktu rspecnya dijalanin, muncul errornya:

                                Failures:

                                  1) VideosController GET show sets @video for authenticated user
                                     Failure/Error: video1 = Fabricate(:video)
                                     ActiveRecord::StatementInvalid:
                                       TypeError: can't cast Array to string: INSERT INTO "videos" ("created_at", "description", "title", "updated_at") VALUES (?, ?, ?, ?)
                                     # ./spec/controllers/videos_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

                                Finished in 0.26621 seconds
                                3 examples, 1 failure

                                dimana ya errornya?




                              • Ronny Haryanto
                                ... Another one to add to the list is Machinist. I ve personally used it and am a happy customer. I also happen to work in the same company as the gem author
                                Message 15 of 15 , Nov 11, 2013
                                  On Tue, Nov 12, 2013 at 3:10 PM, Pavel Evstigneev <pavel.evst@...> wrote:
                                  Did you try FactoryGirl ? It works well with rails.

                                  Another one to add to the list is Machinist. I've personally used it and am a happy customer. I also happen to work in the same company as the gem author :)
                                   
                                  Instead “ session[:user_id] = user.id “ better use: (in case of devise)

                                    # spec_helper.rb
                                    config.include Devise::TestHelpers, :type => :controller

                                    # video_controller_spec.rb
                                    before do
                                      @...["devise.mapping"] = Devise.mappings[:user]
                                      @user = FactoryGirl.create(:user, :confirmed)
                                      sign_in @user
                                    end

                                  I tend to use this pattern when testing controller actions that require a user to be signed in.

                                  describe SomeController do
                                    describe 'GET show' do
                                      context 'when signed in' do
                                        let(:user) { FactoryGirl.create(:user, :confirmed) }
                                        before { sign_in user }

                                        it "does useful things for the user" do
                                          get :show
                                          expect ...
                                        end
                                      end

                                      context 'when signed out' do
                                        it "redirects to sign_in" do
                                          get :show
                                          expect(response).to redirect_to sign_in_path
                                        end
                                      end
                                    end
                                  end

                                  Ronny
                                Your message has been successfully submitted and would be delivered to recipients shortly.