From b57d7ff3fc4c2efe1135095b049b18a285ed4fc5 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Tue, 4 Jun 2019 15:54:20 +0900 Subject: [PATCH 01/27] make api routes --- .DS_Store | Bin 6148 -> 8196 bytes config/routes.rb | 2 ++ media_site.htm | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 media_site.htm diff --git a/.DS_Store b/.DS_Store index 175ed525891086f1553508160a7b349e48caab08..78f3bb919b4f86c47e977a336806dfbd4de96963 100644 GIT binary patch literal 8196 zcmeHM!EVz)5S>jzYO4iuKr}}mK;lqUi9n4ILJA=j>H!H61P4H=orKn{Ye$LG2trUU zd;}ahAn_@D0UyE#z?AW8yURaUrmz$#!BunJfOtO8bne?tMhv$;5Dy!X|tZLI=Uf&Wqg zem;1pj7^OTh4RsXMy3G35{6|#Uw-@pJstoyH7*ol1Vt!QpfVLY#Sl7o5Xv0$P0e2@ zROTe4XRM<=3!R||oq7mQ(n&NG+SV#y6N&R#(Zuz6X&m+kpuBh%#{Fd4N+xlCEZ6C%3D+5>sIsg}*zEw3g}C{;GzO-)-ljv~ zNq!%Kqs`iG;CA(Szi1Dn)e%;}3FPfKZgDLWcNumQoG3@pGq{NLY_4%vIP@5vkKvh5 zd_`|Q^W0i4_`7tE+Vl{(jmZ0X?*i)NEJ}!Hi1m$KvJyGo8h9xpA1NjBtIGI4W#TVM zjbUN%IQA^B$Y)?a5M)$YR+&z*!x(1>|M?YVJXtRPm=-uip!yNo_dly)i&fzK6eud! zRnGr+&;I-W`EAg8whCAU{ 'ad_api#view' + get '/click' => 'ad_api#click' resources :ad # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/media_site.htm b/media_site.htm new file mode 100644 index 0000000..43a7aec --- /dev/null +++ b/media_site.htm @@ -0,0 +1,58 @@ + + + + 媒体TEST + + + + +
+ +
+ + + From 9fc95ea370c83f4cd5418a0ea3cf6f2f839b02c3 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Tue, 4 Jun 2019 17:42:53 +0900 Subject: [PATCH 02/27] add imp,click counter on api_controller --- app/controllers/ad_api_controller.rb | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 app/controllers/ad_api_controller.rb diff --git a/app/controllers/ad_api_controller.rb b/app/controllers/ad_api_controller.rb new file mode 100644 index 0000000..e683c6f --- /dev/null +++ b/app/controllers/ad_api_controller.rb @@ -0,0 +1,43 @@ + +class AdApiController < ApplicationController + def view + array=[] + + target_ids = Ad.pluck(:id).sample( params[:count].to_i) + ads=Ad.find(target_ids) + ads.each do |ad| + + if ad.imp ==nil + ad.imp = 1 + else + ad.imp += 1 + end + ad.save + + puts ad.imp + + array.push( + { img_url: ad.image, + body: ad.text, + ad_id: ad.id } + ) + end + render json: array + end + + def click + ad=Ad.find( params[:ad_id]) + + if ad.click ==nil + ad.click = 1 + else + ad.click += 1 + end + ad.save + + ad.price = params[:price] + ad.save + puts 'ad saved!' + + end +end From 159cd364d76d164bac9480cd63acf6236075c586 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Tue, 4 Jun 2019 18:40:10 +0900 Subject: [PATCH 03/27] add errorlog if ad.id was matched nothing --- app/controllers/ad_api_controller.rb | 44 +++++++++++++++++++++------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/app/controllers/ad_api_controller.rb b/app/controllers/ad_api_controller.rb index e683c6f..10dd020 100644 --- a/app/controllers/ad_api_controller.rb +++ b/app/controllers/ad_api_controller.rb @@ -1,7 +1,7 @@ class AdApiController < ApplicationController def view - array=[] + array=[] target_ids = Ad.pluck(:id).sample( params[:count].to_i) ads=Ad.find(target_ids) @@ -26,18 +26,40 @@ def view end def click - ad=Ad.find( params[:ad_id]) - - if ad.click ==nil - ad.click = 1 + if ad=Ad.find_by( id: params[:ad_id]) + + if ad.click ==nil + ad.click = 1 + else + ad.click += 1 + end + ad.save + + ad.price = params[:price] + ad.save + puts 'ad saved!' + else - ad.click += 1 + ad = Ad.new(id: 500,adspot_id: 500) + if ad.click ==nil + ad.click = 1 + else + ad.click += 1 + end + ad.save + + + render status: 500, json: { status: 500, message: 'Ad was not existed! ' } end - ad.save - - ad.price = params[:price] - ad.save - puts 'ad saved!' + end + + private + def count_p + end + + end + + From ac3f8262f5d7a75ae507cb2466d16f54d9eb9ad3 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Fri, 14 Jun 2019 14:15:54 +0900 Subject: [PATCH 04/27] fix Db tables --- app/controllers/ad_api_controller.rb | 42 ++++++------------ app/models/repo.rb | 2 + db/migrate/20190528085221_create_ads.rb | 4 +- ...20190604073026_add_report_column_to_ads.rb | 8 ---- db/migrate/20190614041856_create_repos.rb | 15 +++++++ db/schema.rb | 33 +++++++++----- public/uploads/ad/image/1/bg_topicon_p04.png | Bin 0 -> 2600 bytes public/uploads/ad/image/2/bg_topicon_p04.png | Bin 0 -> 2600 bytes spec/factories/repos.rb | 9 ++++ spec/models/repo_spec.rb | 5 +++ 10 files changed, 68 insertions(+), 50 deletions(-) create mode 100644 app/models/repo.rb delete mode 100644 db/migrate/20190604073026_add_report_column_to_ads.rb create mode 100644 db/migrate/20190614041856_create_repos.rb create mode 100644 public/uploads/ad/image/1/bg_topicon_p04.png create mode 100644 public/uploads/ad/image/2/bg_topicon_p04.png create mode 100644 spec/factories/repos.rb create mode 100644 spec/models/repo_spec.rb diff --git a/app/controllers/ad_api_controller.rb b/app/controllers/ad_api_controller.rb index 10dd020..01571a1 100644 --- a/app/controllers/ad_api_controller.rb +++ b/app/controllers/ad_api_controller.rb @@ -7,14 +7,14 @@ def view ads=Ad.find(target_ids) ads.each do |ad| - if ad.imp ==nil - ad.imp = 1 - else - ad.imp += 1 + repo = Repo.find_by(ad_id: ad.id, adspot_id: params[:adspot_id]) + unless repo + repo = Repo.new(ad_id: ad.id,adspot_id: params[:adspot_id]) end - ad.save - puts ad.imp + repo.imp += 1 + repo.save + p repo.imp array.push( { img_url: ad.image, @@ -26,29 +26,17 @@ def view end def click - if ad=Ad.find_by( id: params[:ad_id]) - if ad.click ==nil - ad.click = 1 - else - ad.click += 1 - end - ad.save - - ad.price = params[:price] - ad.save - puts 'ad saved!' + if repo = Repo.find_by(ad_id: params[:ad_id], adspot_id: params[:adspot_id]) - else - ad = Ad.new(id: 500,adspot_id: 500) - if ad.click ==nil - ad.click = 1 - else - ad.click += 1 - end - ad.save + repo.click += 1 + repo.totalcost += Ad.find( params[:ad_id]).price + repo.save + p repo.click + p repo.totalcost + else render status: 500, json: { status: 500, message: 'Ad was not existed! ' } end end @@ -56,10 +44,8 @@ def click private def count_p - + end end - - diff --git a/app/models/repo.rb b/app/models/repo.rb new file mode 100644 index 0000000..07720ce --- /dev/null +++ b/app/models/repo.rb @@ -0,0 +1,2 @@ +class Repo < ApplicationRecord +end diff --git a/db/migrate/20190528085221_create_ads.rb b/db/migrate/20190528085221_create_ads.rb index d76d3d3..03e4ae9 100644 --- a/db/migrate/20190528085221_create_ads.rb +++ b/db/migrate/20190528085221_create_ads.rb @@ -2,9 +2,9 @@ class CreateAds < ActiveRecord::Migration[5.2] def change create_table :ads do |t| - t.integer :advertiser_id, null: false, default: 0 # 広告主ID + t.integer :advertiser_id, null: false # 広告主ID t.string :image, null: false, default: '' # 広告の画像URL - t.integer :price, null: false, default: 0 # 広告の価格 + t.integer :price, null: false # 広告の価格 t.string :text, null: false, default: '' # 広告の説明文 t.timestamps diff --git a/db/migrate/20190604073026_add_report_column_to_ads.rb b/db/migrate/20190604073026_add_report_column_to_ads.rb deleted file mode 100644 index bf8d75f..0000000 --- a/db/migrate/20190604073026_add_report_column_to_ads.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true -class AddReportColumnToAds < ActiveRecord::Migration[5.2] - def change - add_column :ads, :click, :integer - add_column :ads, :imp, :integer - add_column :ads, :cv, :integer - end -end diff --git a/db/migrate/20190614041856_create_repos.rb b/db/migrate/20190614041856_create_repos.rb new file mode 100644 index 0000000..3f99bc4 --- /dev/null +++ b/db/migrate/20190614041856_create_repos.rb @@ -0,0 +1,15 @@ +class CreateRepos < ActiveRecord::Migration[5.2] + def change + create_table :repos do |t| + t.integer :click, null: false, default: 0 + t.integer :imp, null: false, default: 0 + t.integer :cv, null: false, default: 0 + t.integer :ad_id,null: false + t.integer :totalcost, null: false, default: 0 + t.integer :adspot_id, null: false + + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index d6923dc..76a2e3c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,4 +1,3 @@ -# frozen_string_literal: true # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -11,16 +10,26 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_06_04_073026) do - create_table 'ads', force: :cascade do |t| - t.integer 'advertiser_id', default: 0, null: false - t.string 'image', default: '', null: false - t.integer 'price', default: 0, null: false - t.string 'text', default: '', null: false - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.integer 'click' - t.integer 'imp' - t.integer 'cv' +ActiveRecord::Schema.define(version: 2019_06_14_041856) do + + create_table "ads", force: :cascade do |t| + t.integer "advertiser_id", null: false + t.string "image", default: "", null: false + t.integer "price", null: false + t.string "text", default: "", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "repos", force: :cascade do |t| + t.integer "click", default: 0, null: false + t.integer "imp", default: 0, null: false + t.integer "cv", default: 0, null: false + t.integer "ad_id", null: false + t.integer "totalcost", default: 0, null: false + t.integer "adspot_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end + end diff --git a/public/uploads/ad/image/1/bg_topicon_p04.png b/public/uploads/ad/image/1/bg_topicon_p04.png new file mode 100644 index 0000000000000000000000000000000000000000..a773d0aa5aa53897b21b28db2551f6fe036e8b1d GIT binary patch literal 2600 zcmV+@3fJ|CP)00004b3#c}2nYxW zddbVG7wVRUJ4ZXi@?ZDjy4GA=nT zGBXHu2i*Vw0338hSaefwW^{L9a%BKPWN%_+AVz6&Wp{6KYjYq&Q#En5<2C>Q34uvO zK~#90?VUSp8^;!ge>%JpK!A_|GDTGIQAsIm374vDD5fj9O5^~kLL*F*SXG?%rcvWw zu4ucGVWySjR8l26Ok9ZpEfq4;P*kBN6kvh41f+&3&WyO+_mbS*+2wq|0@85F9qd2n z%$YN@I}wD4LaBEXz#=Q&MtGIj zU-?`eE8alxMj*WK%#9a8g8OaRPPqUzfKAc517U?PlzK&w;P?Ek$=G-cY5<#lR|F7H zcqaHd>_^{0qXl5y?*<@@@P$%u6~G3FWS~^7`6>@(k1kcrps`MR*peZ(?%Xx?NfTie8KWxbQdJz7VHS>TLkn zhZJ3pG=P0}k37M3i!YRV8PJ$^!R>2>g!cee%WIJnH-6j`i)Rsg9a3~BEC8spd*>Ri z312Ano&eZJ@Um_qFauzl-9uM!#nl%|y-fh$x$)Z*$gA>Nq&Ti0b0w;0L$w`D?%3Qd z-h%r5k%xR^7oLe;f$Y!S;yr-;sN#<`xRauL!UBK_yVoN#vhY%LPZ^u|ASY>X*~Z2s}xDC7L0qI#B9+8*|zlCkp8$=v?X!#S3F zuR~_!MBxI!qTSs7D8soONYO=N215jUj)Z5^hBAT|j|Hbwy0%?CTST$%v_=w7xo@?Y z!%-j45(ag6u!!RIWBu|+&)vQ<5t{~b8Q_aKV19P+v(s~+)&zcU0PT)9^>IiG)ZZJX zb-D0Sn?JaY30OIk%L0WvKr*iXc`8B2%57lp5ZF5KwthB9gS4_7=2`afY&C4?7e*HD z0#8u2pYX?pZC}vg+f*Z|!%qWvA!B%YC5L9xPABfgkT{ zgT9ALLI!*rFd5$)T0DD}Ez|*BF01X+PtSp;ziCAWNZ6;p0Uyq^pFOzkP8~-e%{0`- z%+;@ty()r{%V^8We*)c0^Y6XT$!2^$t1T0Nb)ye-g`Wg#2Y^p?to>NWn$@&B+CD#( z7+bZ*iJ{dSS-kGaVMFca_1wD=rw-2bnWA2yMtGK*4Rs{X5pWFd2KShz1L#?N(en`Bu2ih{D1dkxhKxNQ+!cPpfrZ(x4N>CbB&+?OT;ORHo2)=to2^_&0(DpiW z$6SHv?~xljFZY4}sq*cq1eNh=Sb+L;y>UN4DP60vzW{v2H2w$-rfet5+BwH(z}}I5 zzMfCRno(^4yNB-7%>`CLZzLIT^%E&PK-s#zBj?|%odD%`W3P^zTx+bf_`LV^5Qp-g zWc_9fF*w~TVHaXpk>`Izf$OAA=%V>_k`_(aNy7rvpVyke@|^L~tKCDg^Z@kfddxg} zj{NJ#sBnw7T(J=()YGTkD-v|?$X;5u+8}XXd_P#ebnJ>x0KUCL2e)h^L2D;{;f>BoC&{|`d3yX`9BT)d)=@UL3vB-$ zn+6`-qE#?X;a-4Gv+f=aCUj~|vh>&#H4-JcEL~R}2Po-Yl4ntW*JoxPJ;%)`0^GlU zK1)`v7ln5(ftM8$@4p#xx4EqT?QyX`@`T6?_ZV5E$WW zO_~A?a=$7Pff0UV&!6k&vOt=pf&b}f8(!-?n0E|8z(|b$VB?Oi8;#2_Ml2jPT05dH0GMz=ty$U)#yraiQ(@+tmhe(4?`vQ&Jtx9*|Z) z2~_wWO5sP|s8%98*BUEx^%d{yp+%tRH;h#HAJ-Powy1pLLuDl1@J6`}srt>9(%pxb z0d1x5lY_DFEPeaR)9OgP;FWs!Nxk>gZ+cS~iHB^e3v~CEEtGn7$X%nu!u#@C`z`XFMdnWgaMwMZSnv$0f1 z;swu`W~SJ&cz~kA)=1TnctHy`M`N~xXL;V@@b!^+L{XiSH{xF>%3gB$TdBkV0000< KMNUMnLSTZoN%7nO literal 0 HcmV?d00001 diff --git a/public/uploads/ad/image/2/bg_topicon_p04.png b/public/uploads/ad/image/2/bg_topicon_p04.png new file mode 100644 index 0000000000000000000000000000000000000000..a773d0aa5aa53897b21b28db2551f6fe036e8b1d GIT binary patch literal 2600 zcmV+@3fJ|CP)00004b3#c}2nYxW zddbVG7wVRUJ4ZXi@?ZDjy4GA=nT zGBXHu2i*Vw0338hSaefwW^{L9a%BKPWN%_+AVz6&Wp{6KYjYq&Q#En5<2C>Q34uvO zK~#90?VUSp8^;!ge>%JpK!A_|GDTGIQAsIm374vDD5fj9O5^~kLL*F*SXG?%rcvWw zu4ucGVWySjR8l26Ok9ZpEfq4;P*kBN6kvh41f+&3&WyO+_mbS*+2wq|0@85F9qd2n z%$YN@I}wD4LaBEXz#=Q&MtGIj zU-?`eE8alxMj*WK%#9a8g8OaRPPqUzfKAc517U?PlzK&w;P?Ek$=G-cY5<#lR|F7H zcqaHd>_^{0qXl5y?*<@@@P$%u6~G3FWS~^7`6>@(k1kcrps`MR*peZ(?%Xx?NfTie8KWxbQdJz7VHS>TLkn zhZJ3pG=P0}k37M3i!YRV8PJ$^!R>2>g!cee%WIJnH-6j`i)Rsg9a3~BEC8spd*>Ri z312Ano&eZJ@Um_qFauzl-9uM!#nl%|y-fh$x$)Z*$gA>Nq&Ti0b0w;0L$w`D?%3Qd z-h%r5k%xR^7oLe;f$Y!S;yr-;sN#<`xRauL!UBK_yVoN#vhY%LPZ^u|ASY>X*~Z2s}xDC7L0qI#B9+8*|zlCkp8$=v?X!#S3F zuR~_!MBxI!qTSs7D8soONYO=N215jUj)Z5^hBAT|j|Hbwy0%?CTST$%v_=w7xo@?Y z!%-j45(ag6u!!RIWBu|+&)vQ<5t{~b8Q_aKV19P+v(s~+)&zcU0PT)9^>IiG)ZZJX zb-D0Sn?JaY30OIk%L0WvKr*iXc`8B2%57lp5ZF5KwthB9gS4_7=2`afY&C4?7e*HD z0#8u2pYX?pZC}vg+f*Z|!%qWvA!B%YC5L9xPABfgkT{ zgT9ALLI!*rFd5$)T0DD}Ez|*BF01X+PtSp;ziCAWNZ6;p0Uyq^pFOzkP8~-e%{0`- z%+;@ty()r{%V^8We*)c0^Y6XT$!2^$t1T0Nb)ye-g`Wg#2Y^p?to>NWn$@&B+CD#( z7+bZ*iJ{dSS-kGaVMFca_1wD=rw-2bnWA2yMtGK*4Rs{X5pWFd2KShz1L#?N(en`Bu2ih{D1dkxhKxNQ+!cPpfrZ(x4N>CbB&+?OT;ORHo2)=to2^_&0(DpiW z$6SHv?~xljFZY4}sq*cq1eNh=Sb+L;y>UN4DP60vzW{v2H2w$-rfet5+BwH(z}}I5 zzMfCRno(^4yNB-7%>`CLZzLIT^%E&PK-s#zBj?|%odD%`W3P^zTx+bf_`LV^5Qp-g zWc_9fF*w~TVHaXpk>`Izf$OAA=%V>_k`_(aNy7rvpVyke@|^L~tKCDg^Z@kfddxg} zj{NJ#sBnw7T(J=()YGTkD-v|?$X;5u+8}XXd_P#ebnJ>x0KUCL2e)h^L2D;{;f>BoC&{|`d3yX`9BT)d)=@UL3vB-$ zn+6`-qE#?X;a-4Gv+f=aCUj~|vh>&#H4-JcEL~R}2Po-Yl4ntW*JoxPJ;%)`0^GlU zK1)`v7ln5(ftM8$@4p#xx4EqT?QyX`@`T6?_ZV5E$WW zO_~A?a=$7Pff0UV&!6k&vOt=pf&b}f8(!-?n0E|8z(|b$VB?Oi8;#2_Ml2jPT05dH0GMz=ty$U)#yraiQ(@+tmhe(4?`vQ&Jtx9*|Z) z2~_wWO5sP|s8%98*BUEx^%d{yp+%tRH;h#HAJ-Powy1pLLuDl1@J6`}srt>9(%pxb z0d1x5lY_DFEPeaR)9OgP;FWs!Nxk>gZ+cS~iHB^e3v~CEEtGn7$X%nu!u#@C`z`XFMdnWgaMwMZSnv$0f1 z;swu`W~SJ&cz~kA)=1TnctHy`M`N~xXL;V@@b!^+L{XiSH{xF>%3gB$TdBkV0000< KMNUMnLSTZoN%7nO literal 0 HcmV?d00001 diff --git a/spec/factories/repos.rb b/spec/factories/repos.rb new file mode 100644 index 0000000..9cf342e --- /dev/null +++ b/spec/factories/repos.rb @@ -0,0 +1,9 @@ +FactoryBot.define do + factory :repo do + click { 1 } + imp { 1 } + cv { 1 } + totalcost { 1 } + adspot_id { 1 } + end +end diff --git a/spec/models/repo_spec.rb b/spec/models/repo_spec.rb new file mode 100644 index 0000000..d4fa8e4 --- /dev/null +++ b/spec/models/repo_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Repo, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From a543d8673ded5ec5b2a2041f1c33b4a5ab427318 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Tue, 4 Jun 2019 15:54:41 +0900 Subject: [PATCH 05/27] add api html.erb --- app/assets/javascripts/ad_api.coffee | 3 +++ app/assets/stylesheets/ad_api.scss | 3 +++ app/helpers/ad_api_helper.rb | 2 ++ app/views/ad_api/click.html.erb | 2 ++ app/views/ad_api/view.html.erb | 2 ++ spec/controllers/ad_api_controller_spec.rb | 19 +++++++++++++++++++ spec/helpers/ad_api_helper_spec.rb | 15 +++++++++++++++ spec/views/ad_api/click.html.erb_spec.rb | 5 +++++ spec/views/ad_api/view.html.erb_spec.rb | 5 +++++ 9 files changed, 56 insertions(+) create mode 100644 app/assets/javascripts/ad_api.coffee create mode 100644 app/assets/stylesheets/ad_api.scss create mode 100644 app/helpers/ad_api_helper.rb create mode 100644 app/views/ad_api/click.html.erb create mode 100644 app/views/ad_api/view.html.erb create mode 100644 spec/controllers/ad_api_controller_spec.rb create mode 100644 spec/helpers/ad_api_helper_spec.rb create mode 100644 spec/views/ad_api/click.html.erb_spec.rb create mode 100644 spec/views/ad_api/view.html.erb_spec.rb diff --git a/app/assets/javascripts/ad_api.coffee b/app/assets/javascripts/ad_api.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/ad_api.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/ad_api.scss b/app/assets/stylesheets/ad_api.scss new file mode 100644 index 0000000..b15c608 --- /dev/null +++ b/app/assets/stylesheets/ad_api.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Ad_API controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/helpers/ad_api_helper.rb b/app/helpers/ad_api_helper.rb new file mode 100644 index 0000000..096a98d --- /dev/null +++ b/app/helpers/ad_api_helper.rb @@ -0,0 +1,2 @@ +module AdApiHelper +end diff --git a/app/views/ad_api/click.html.erb b/app/views/ad_api/click.html.erb new file mode 100644 index 0000000..e3e77a6 --- /dev/null +++ b/app/views/ad_api/click.html.erb @@ -0,0 +1,2 @@ +

AdApi#click

+

Find me in app/views/ad_api/click.html.erb

diff --git a/app/views/ad_api/view.html.erb b/app/views/ad_api/view.html.erb new file mode 100644 index 0000000..b5fd078 --- /dev/null +++ b/app/views/ad_api/view.html.erb @@ -0,0 +1,2 @@ +

AdApi#view

+

Find me in app/views/ad_api/view.html.erb

diff --git a/spec/controllers/ad_api_controller_spec.rb b/spec/controllers/ad_api_controller_spec.rb new file mode 100644 index 0000000..da4c1cc --- /dev/null +++ b/spec/controllers/ad_api_controller_spec.rb @@ -0,0 +1,19 @@ +require 'rails_helper' + +RSpec.describe AdApiController, type: :controller do + + describe "GET #view" do + it "returns http success" do + get :view + expect(response).to have_http_status(:success) + end + end + + describe "GET #click" do + it "returns http success" do + get :click + expect(response).to have_http_status(:success) + end + end + +end diff --git a/spec/helpers/ad_api_helper_spec.rb b/spec/helpers/ad_api_helper_spec.rb new file mode 100644 index 0000000..7883bff --- /dev/null +++ b/spec/helpers/ad_api_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the AdApiHelper. For example: +# +# describe AdApiHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe AdApiHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/ad_api/click.html.erb_spec.rb b/spec/views/ad_api/click.html.erb_spec.rb new file mode 100644 index 0000000..3e20e0b --- /dev/null +++ b/spec/views/ad_api/click.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe "ad_api/click.html.erb", type: :view do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/ad_api/view.html.erb_spec.rb b/spec/views/ad_api/view.html.erb_spec.rb new file mode 100644 index 0000000..e144bd6 --- /dev/null +++ b/spec/views/ad_api/view.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe "ad_api/view.html.erb", type: :view do + pending "add some examples to (or delete) #{__FILE__}" +end From adfd2cad35475b7775b37d59ba1a77346273686e Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Fri, 21 Jun 2019 15:28:50 +0900 Subject: [PATCH 06/27] fix ad_api --- app/controllers/ad_api_controller.rb | 50 ++++++++++------------------ app/views/ad/index.html.erb | 6 ++-- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/app/controllers/ad_api_controller.rb b/app/controllers/ad_api_controller.rb index 01571a1..04e9de6 100644 --- a/app/controllers/ad_api_controller.rb +++ b/app/controllers/ad_api_controller.rb @@ -1,51 +1,37 @@ +# frozen_string_literal: true class AdApiController < ApplicationController def view - array=[] + array = [] + reports = [] - target_ids = Ad.pluck(:id).sample( params[:count].to_i) - ads=Ad.find(target_ids) + target_ids = Ad.pluck(:id).sample(params[:count].to_i) + ads = Ad.find(target_ids) ads.each do |ad| - - repo = Repo.find_by(ad_id: ad.id, adspot_id: params[:adspot_id]) - unless repo - repo = Repo.new(ad_id: ad.id,adspot_id: params[:adspot_id]) + report = Report.find_by(ad_id: ad.id, adspot_id: params[:adspot_id]) + unless report + report = Report.new(ad_id: ad.id, adspot_id: params[:adspot_id]) end - repo.imp += 1 - repo.save - p repo.imp + report.imp += 1 + reports.push(report) array.push( - { img_url: ad.image, - body: ad.text, - ad_id: ad.id } + img_url: ad.image, + body: ad.text, + ad_id: ad.id ) end + Report.import(reports) render json: array end def click + report = Report.find_by(ad_id: params[:ad_id], adspot_id: params[:adspot_id]) - if repo = Repo.find_by(ad_id: params[:ad_id], adspot_id: params[:adspot_id]) - - repo.click += 1 - repo.totalcost += Ad.find( params[:ad_id]).price - repo.save - - p repo.click - p repo.totalcost - - else - render status: 500, json: { status: 500, message: 'Ad was not existed! ' } - end - end - - - private - def count_p - + report.click += 1 + report.totalcost += Ad.find(params[:ad_id]).price + report.save end - end diff --git a/app/views/ad/index.html.erb b/app/views/ad/index.html.erb index 7296a3d..e322ba3 100644 --- a/app/views/ad/index.html.erb +++ b/app/views/ad/index.html.erb @@ -14,14 +14,14 @@ <%= image_tag ad.image.to_s %>
- <%= link_to("Edit", edit_ad_path(ad)) %> + <%= link_to("変更", edit_ad_path(ad)) %>
- <%= link_to("Delete", ad_path(ad) ,method: :delete) %> + <%= link_to("削除", ad_path(ad) ,method: :delete) %>
<% end %>
- <%= link_to("New", new_ad_path) %> + <%= link_to("新規作成", new_ad_path) %>
From 0fa59bcfed842afc2af545eac25f9071c391f4b9 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Fri, 21 Jun 2019 15:32:56 +0900 Subject: [PATCH 07/27] fix model name --- Gemfile | 1 + Gemfile.lock | 19 +++++++----- app/helpers/ad_api_helper.rb | 1 + app/models/repo.rb | 2 -- db/migrate/20190614041856_create_repos.rb | 11 ++++--- db/schema.rb | 35 +++++++++++----------- spec/controllers/ad_api_controller_spec.rb | 12 ++++---- spec/controllers/ad_controller_spec.rb | 2 +- spec/factories/repos.rb | 3 +- spec/helpers/ad_api_helper_spec.rb | 1 + spec/models/repo_spec.rb | 3 +- spec/views/ad_api/click.html.erb_spec.rb | 3 +- spec/views/ad_api/view.html.erb_spec.rb | 3 +- 13 files changed, 52 insertions(+), 44 deletions(-) delete mode 100644 app/models/repo.rb diff --git a/Gemfile b/Gemfile index 98767cc..78d2eea 100644 --- a/Gemfile +++ b/Gemfile @@ -70,3 +70,4 @@ gem 'carrierwave' gem 'sassc' gem 'rubocop', '~> 0.47.1' gem 'htmlbeautifier' +gem 'activerecord-import' diff --git a/Gemfile.lock b/Gemfile.lock index 1fa33bf..9c2cc67 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -33,6 +33,8 @@ GEM activemodel (= 5.2.3) activesupport (= 5.2.3) arel (>= 9.0) + activerecord-import (1.0.2) + activerecord (>= 3.2) activestorage (5.2.3) actionpack (= 5.2.3) activerecord (= 5.2.3) @@ -102,7 +104,7 @@ GEM io-like (0.3.0) jbuilder (2.9.1) activesupport (>= 4.2.0) - jquery-rails (4.3.3) + jquery-rails (4.3.5) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) @@ -125,7 +127,7 @@ GEM mini_mime (1.0.1) mini_portile2 (2.4.0) minitest (5.11.3) - msgpack (1.2.10) + msgpack (1.3.0) nio4r (2.3.1) nokogiri (1.10.3) mini_portile2 (~> 2.4.0) @@ -173,12 +175,12 @@ GEM rb-inotify (0.10.0) ffi (~> 1.0) regexp_parser (1.5.1) - rspec-core (3.8.0) + rspec-core (3.8.1) rspec-support (~> 3.8.0) - rspec-expectations (3.8.3) + rspec-expectations (3.8.4) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) + rspec-mocks (3.8.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.8.0) rspec-rails (3.8.2) @@ -189,7 +191,7 @@ GEM rspec-expectations (~> 3.8.0) rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) - rspec-support (3.8.0) + rspec-support (3.8.2) rubocop (0.47.1) parser (>= 2.3.3.1, < 3.0) powerpack (~> 0.1) @@ -245,9 +247,9 @@ GEM activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) - websocket-driver (0.7.0) + websocket-driver (0.7.1) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) + websocket-extensions (0.1.4) xpath (3.2.0) nokogiri (~> 1.8) @@ -255,6 +257,7 @@ PLATFORMS ruby DEPENDENCIES + activerecord-import bootsnap (>= 1.1.0) bootstrap byebug diff --git a/app/helpers/ad_api_helper.rb b/app/helpers/ad_api_helper.rb index 096a98d..b9fd8b9 100644 --- a/app/helpers/ad_api_helper.rb +++ b/app/helpers/ad_api_helper.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true module AdApiHelper end diff --git a/app/models/repo.rb b/app/models/repo.rb deleted file mode 100644 index 07720ce..0000000 --- a/app/models/repo.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Repo < ApplicationRecord -end diff --git a/db/migrate/20190614041856_create_repos.rb b/db/migrate/20190614041856_create_repos.rb index 3f99bc4..d9d9f00 100644 --- a/db/migrate/20190614041856_create_repos.rb +++ b/db/migrate/20190614041856_create_repos.rb @@ -1,14 +1,13 @@ +# frozen_string_literal: true class CreateRepos < ActiveRecord::Migration[5.2] def change - create_table :repos do |t| + create_table :reports do |t| + t.integer :ad_id, null: false + t.integer :adspot_id, null: false t.integer :click, null: false, default: 0 t.integer :imp, null: false, default: 0 t.integer :cv, null: false, default: 0 - t.integer :ad_id,null: false - t.integer :totalcost, null: false, default: 0 - t.integer :adspot_id, null: false - - + t.integer :price, null: false, default: 0 t.timestamps end end diff --git a/db/schema.rb b/db/schema.rb index 76a2e3c..b9db627 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -11,25 +12,23 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2019_06_14_041856) do - - create_table "ads", force: :cascade do |t| - t.integer "advertiser_id", null: false - t.string "image", default: "", null: false - t.integer "price", null: false - t.string "text", default: "", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'ads', force: :cascade do |t| + t.integer 'advertiser_id', null: false + t.string 'image', default: '', null: false + t.integer 'price', null: false + t.string 'text', default: '', null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - create_table "repos", force: :cascade do |t| - t.integer "click", default: 0, null: false - t.integer "imp", default: 0, null: false - t.integer "cv", default: 0, null: false - t.integer "ad_id", null: false - t.integer "totalcost", default: 0, null: false - t.integer "adspot_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'reports', force: :cascade do |t| + t.integer 'ad_id', null: false + t.integer 'adspot_id', null: false + t.integer 'click', default: 0, null: false + t.integer 'imp', default: 0, null: false + t.integer 'cv', default: 0, null: false + t.integer 'price', default: 0, null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - end diff --git a/spec/controllers/ad_api_controller_spec.rb b/spec/controllers/ad_api_controller_spec.rb index da4c1cc..9f3ef18 100644 --- a/spec/controllers/ad_api_controller_spec.rb +++ b/spec/controllers/ad_api_controller_spec.rb @@ -1,19 +1,21 @@ +# frozen_string_literal: true require 'rails_helper' RSpec.describe AdApiController, type: :controller do + befoere do - describe "GET #view" do - it "returns http success" do + end + describe 'GET #view' do + it 'returns http success' do get :view expect(response).to have_http_status(:success) end end - describe "GET #click" do - it "returns http success" do + describe 'GET #click' do + it 'returns http success' do get :click expect(response).to have_http_status(:success) end end - end diff --git a/spec/controllers/ad_controller_spec.rb b/spec/controllers/ad_controller_spec.rb index f8471fd..59b89a3 100644 --- a/spec/controllers/ad_controller_spec.rb +++ b/spec/controllers/ad_controller_spec.rb @@ -97,7 +97,7 @@ context 'when something empty' do it 'without text should be rendered' do - patch :update, params: { ad: { 'text' =>nil }, id: @ad.id } + patch :update, params: { ad: { 'text' => nil }, id: @ad.id } expect(response).to render_template :edit end diff --git a/spec/factories/repos.rb b/spec/factories/repos.rb index 9cf342e..9edb725 100644 --- a/spec/factories/repos.rb +++ b/spec/factories/repos.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true FactoryBot.define do - factory :repo do + factory :report do click { 1 } imp { 1 } cv { 1 } diff --git a/spec/helpers/ad_api_helper_spec.rb b/spec/helpers/ad_api_helper_spec.rb index 7883bff..20cc2b8 100644 --- a/spec/helpers/ad_api_helper_spec.rb +++ b/spec/helpers/ad_api_helper_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'rails_helper' # Specs in this file have access to a helper object that includes diff --git a/spec/models/repo_spec.rb b/spec/models/repo_spec.rb index d4fa8e4..78f2552 100644 --- a/spec/models/repo_spec.rb +++ b/spec/models/repo_spec.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true require 'rails_helper' -RSpec.describe Repo, type: :model do +RSpec.describe Report, type: :model do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/views/ad_api/click.html.erb_spec.rb b/spec/views/ad_api/click.html.erb_spec.rb index 3e20e0b..f260b75 100644 --- a/spec/views/ad_api/click.html.erb_spec.rb +++ b/spec/views/ad_api/click.html.erb_spec.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true require 'rails_helper' -RSpec.describe "ad_api/click.html.erb", type: :view do +RSpec.describe 'ad_api/click.html.erb', type: :view do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/views/ad_api/view.html.erb_spec.rb b/spec/views/ad_api/view.html.erb_spec.rb index e144bd6..a58d59a 100644 --- a/spec/views/ad_api/view.html.erb_spec.rb +++ b/spec/views/ad_api/view.html.erb_spec.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true require 'rails_helper' -RSpec.describe "ad_api/view.html.erb", type: :view do +RSpec.describe 'ad_api/view.html.erb', type: :view do pending "add some examples to (or delete) #{__FILE__}" end From 592f6e11b4b603fc5af67056087286a3bd26fc0b Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Fri, 21 Jun 2019 15:37:29 +0900 Subject: [PATCH 08/27] fix db --- app/models/report.rb | 2 ++ db/migrate/20190614041856_create_repos.rb | 2 +- db/schema.rb | 35 ++++++++++++----------- 3 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 app/models/report.rb diff --git a/app/models/report.rb b/app/models/report.rb new file mode 100644 index 0000000..07720ce --- /dev/null +++ b/app/models/report.rb @@ -0,0 +1,2 @@ +class Repo < ApplicationRecord +end diff --git a/db/migrate/20190614041856_create_repos.rb b/db/migrate/20190614041856_create_repos.rb index d9d9f00..254bf9c 100644 --- a/db/migrate/20190614041856_create_repos.rb +++ b/db/migrate/20190614041856_create_repos.rb @@ -7,7 +7,7 @@ def change t.integer :click, null: false, default: 0 t.integer :imp, null: false, default: 0 t.integer :cv, null: false, default: 0 - t.integer :price, null: false, default: 0 + t.integer :totalprice, null: false, default: 0 t.timestamps end end diff --git a/db/schema.rb b/db/schema.rb index b9db627..3ccc041 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,4 +1,3 @@ -# frozen_string_literal: true # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -12,23 +11,25 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2019_06_14_041856) do - create_table 'ads', force: :cascade do |t| - t.integer 'advertiser_id', null: false - t.string 'image', default: '', null: false - t.integer 'price', null: false - t.string 'text', default: '', null: false - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false + + create_table "ads", force: :cascade do |t| + t.integer "advertiser_id", null: false + t.string "image", default: "", null: false + t.integer "price", null: false + t.string "text", default: "", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table 'reports', force: :cascade do |t| - t.integer 'ad_id', null: false - t.integer 'adspot_id', null: false - t.integer 'click', default: 0, null: false - t.integer 'imp', default: 0, null: false - t.integer 'cv', default: 0, null: false - t.integer 'price', default: 0, null: false - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false + create_table "reports", force: :cascade do |t| + t.integer "ad_id", null: false + t.integer "adspot_id", null: false + t.integer "click", default: 0, null: false + t.integer "imp", default: 0, null: false + t.integer "cv", default: 0, null: false + t.integer "totalprice", default: 0, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end + end From fc6c62b77aa3dfdb0e9c6257409e7ecc6e15226d Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Fri, 21 Jun 2019 15:47:42 +0900 Subject: [PATCH 09/27] fix model name --- app/models/report.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/report.rb b/app/models/report.rb index 07720ce..1dfff22 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -1,2 +1,2 @@ -class Repo < ApplicationRecord +class Report < ApplicationRecord end From 3675ac0131e722cfc83ce0f4098d62d3a9fe3ae9 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Fri, 21 Jun 2019 16:49:33 +0900 Subject: [PATCH 10/27] autocorrected by rubocop --- app/models/report.rb | 1 + db/migrate/20190528085221_create_ads.rb | 2 +- db/schema.rb | 35 +++++++++++----------- spec/controllers/ad_api_controller_spec.rb | 1 - 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/models/report.rb b/app/models/report.rb index 1dfff22..eb2599f 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -1,2 +1,3 @@ +# frozen_string_literal: true class Report < ApplicationRecord end diff --git a/db/migrate/20190528085221_create_ads.rb b/db/migrate/20190528085221_create_ads.rb index 03e4ae9..88774df 100644 --- a/db/migrate/20190528085221_create_ads.rb +++ b/db/migrate/20190528085221_create_ads.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -class CreateAds < ActiveRecord::Migration[5.2] +class CreateAds < ActiveRecord::Migration[5.2] # Reportテーブルのtotalpriceにpriceを加算する為に使用 def change create_table :ads do |t| t.integer :advertiser_id, null: false # 広告主ID diff --git a/db/schema.rb b/db/schema.rb index 3ccc041..844ffdc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -11,25 +12,23 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2019_06_14_041856) do - - create_table "ads", force: :cascade do |t| - t.integer "advertiser_id", null: false - t.string "image", default: "", null: false - t.integer "price", null: false - t.string "text", default: "", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'ads', force: :cascade do |t| # reportsテーブルのtotalpriceにpriceを加算する為に使用 + t.integer 'advertiser_id', null: false + t.string 'image', default: '', null: false + t.integer 'price', null: false + t.string 'text', default: '', null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - create_table "reports", force: :cascade do |t| - t.integer "ad_id", null: false - t.integer "adspot_id", null: false - t.integer "click", default: 0, null: false - t.integer "imp", default: 0, null: false - t.integer "cv", default: 0, null: false - t.integer "totalprice", default: 0, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'reports', force: :cascade do |t| + t.integer 'ad_id', null: false + t.integer 'adspot_id', null: false + t.integer 'click', default: 0, null: false + t.integer 'imp', default: 0, null: false + t.integer 'cv', default: 0, null: false + t.integer 'totalprice', default: 0, null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - end diff --git a/spec/controllers/ad_api_controller_spec.rb b/spec/controllers/ad_api_controller_spec.rb index 9f3ef18..7b11e33 100644 --- a/spec/controllers/ad_api_controller_spec.rb +++ b/spec/controllers/ad_api_controller_spec.rb @@ -3,7 +3,6 @@ RSpec.describe AdApiController, type: :controller do befoere do - end describe 'GET #view' do it 'returns http success' do From 1de31b3379ff9c7f5fce34339f8fd9b102841923 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Fri, 21 Jun 2019 16:50:05 +0900 Subject: [PATCH 11/27] fix model saving --- app/controllers/ad_api_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/ad_api_controller.rb b/app/controllers/ad_api_controller.rb index 04e9de6..e740066 100644 --- a/app/controllers/ad_api_controller.rb +++ b/app/controllers/ad_api_controller.rb @@ -22,7 +22,7 @@ def view ad_id: ad.id ) end - Report.import(reports) + Report.import reports, on_duplicate_key_update: [:imp] render json: array end From 792c80fb9b690db6a5aee05cc406e2bd7039f65a Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Fri, 21 Jun 2019 17:02:39 +0900 Subject: [PATCH 12/27] add comment --- db/migrate/20190528085221_create_ads.rb | 2 +- db/schema.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20190528085221_create_ads.rb b/db/migrate/20190528085221_create_ads.rb index 88774df..27ae217 100644 --- a/db/migrate/20190528085221_create_ads.rb +++ b/db/migrate/20190528085221_create_ads.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -class CreateAds < ActiveRecord::Migration[5.2] # Reportテーブルのtotalpriceにpriceを加算する為に使用 +class CreateAds < ActiveRecord::Migration[5.2] # Reportテーブルのtotalpriceにpriceを加算する為に使用しているのでここでも使っています def change create_table :ads do |t| t.integer :advertiser_id, null: false # 広告主ID diff --git a/db/schema.rb b/db/schema.rb index 844ffdc..b12e7d2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,7 +12,7 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2019_06_14_041856) do - create_table 'ads', force: :cascade do |t| # reportsテーブルのtotalpriceにpriceを加算する為に使用 + create_table 'ads', force: :cascade do |t| # reportsテーブルのtotalpriceにpriceを加算する為に使用しているのでここでも使っています t.integer 'advertiser_id', null: false t.string 'image', default: '', null: false t.integer 'price', null: false From 9f42631112273f271a7b06aaeb88686c697468c8 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Fri, 21 Jun 2019 17:45:03 +0900 Subject: [PATCH 13/27] change totalprice to price --- app/controllers/ad_api_controller.rb | 10 +++++--- db/schema.rb | 37 ++++++++++++++-------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/app/controllers/ad_api_controller.rb b/app/controllers/ad_api_controller.rb index e740066..43f14b5 100644 --- a/app/controllers/ad_api_controller.rb +++ b/app/controllers/ad_api_controller.rb @@ -27,11 +27,13 @@ def view end def click - report = Report.find_by(ad_id: params[:ad_id], adspot_id: params[:adspot_id]) - - report.click += 1 - report.totalcost += Ad.find(params[:ad_id]).price + if report = Report.find_by(ad_id: params[:ad_id], adspot_id: params[:adspot_id]) + report.click += 1 + report.price += Ad.find(params[:ad_id]).price report.save + end + + end end diff --git a/db/schema.rb b/db/schema.rb index b12e7d2..f791cd7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,4 +1,3 @@ -# frozen_string_literal: true # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -11,24 +10,26 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_06_14_041856) do - create_table 'ads', force: :cascade do |t| # reportsテーブルのtotalpriceにpriceを加算する為に使用しているのでここでも使っています - t.integer 'advertiser_id', null: false - t.string 'image', default: '', null: false - t.integer 'price', null: false - t.string 'text', default: '', null: false - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false +ActiveRecord::Schema.define(version: 2019_06_21_084306) do + + create_table "ads", force: :cascade do |t| + t.integer "advertiser_id", null: false + t.string "image", default: "", null: false + t.integer "price", null: false + t.string "text", default: "", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table 'reports', force: :cascade do |t| - t.integer 'ad_id', null: false - t.integer 'adspot_id', null: false - t.integer 'click', default: 0, null: false - t.integer 'imp', default: 0, null: false - t.integer 'cv', default: 0, null: false - t.integer 'totalprice', default: 0, null: false - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false + create_table "reports", force: :cascade do |t| + t.integer "ad_id", null: false + t.integer "adspot_id", null: false + t.integer "click", default: 0, null: false + t.integer "imp", default: 0, null: false + t.integer "cv", default: 0, null: false + t.integer "price", default: 0, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end + end From a8952d5d180ae74a2ab1e430638401e013cdabdd Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Mon, 24 Jun 2019 10:52:23 +0900 Subject: [PATCH 14/27] fix db column type --- db/migrate/20190614041856_create_repos.rb | 3 ++- db/schema.rb | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/db/migrate/20190614041856_create_repos.rb b/db/migrate/20190614041856_create_repos.rb index 254bf9c..afcdf16 100644 --- a/db/migrate/20190614041856_create_repos.rb +++ b/db/migrate/20190614041856_create_repos.rb @@ -7,7 +7,8 @@ def change t.integer :click, null: false, default: 0 t.integer :imp, null: false, default: 0 t.integer :cv, null: false, default: 0 - t.integer :totalprice, null: false, default: 0 + t.integer :price, null: false, default: 0 + t.date :date,null: false,unique: true t.timestamps end end diff --git a/db/schema.rb b/db/schema.rb index f791cd7..9b77ba1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_06_21_084306) do +ActiveRecord::Schema.define(version: 2019_06_14_041856) do create_table "ads", force: :cascade do |t| t.integer "advertiser_id", null: false @@ -28,6 +28,7 @@ t.integer "imp", default: 0, null: false t.integer "cv", default: 0, null: false t.integer "price", default: 0, null: false + t.date "date", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end From 53645a0177fd2615dd9c8e456ff9537f8bdf3d1e Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Mon, 24 Jun 2019 11:20:32 +0900 Subject: [PATCH 15/27] add travel_to method for testing rspec --- spec/rails_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index e289dbf..b773da3 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -34,6 +34,7 @@ RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" + config.include ActiveSupport::Testing::TimeHelpers # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false From 7445b15742a8a37a8ef77c27fa7fd51d578849fb Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Mon, 24 Jun 2019 19:01:26 +0900 Subject: [PATCH 16/27] add view rspec --- app/controllers/ad_api_controller.rb | 15 +- spec/controllers/ad_api_controller_spec.rb | 170 ++++++++++++++++++++- spec/factories/ads.rb | 2 +- spec/factories/repos.rb | 10 -- 4 files changed, 171 insertions(+), 26 deletions(-) delete mode 100644 spec/factories/repos.rb diff --git a/app/controllers/ad_api_controller.rb b/app/controllers/ad_api_controller.rb index 43f14b5..bee16c1 100644 --- a/app/controllers/ad_api_controller.rb +++ b/app/controllers/ad_api_controller.rb @@ -8,9 +8,9 @@ def view target_ids = Ad.pluck(:id).sample(params[:count].to_i) ads = Ad.find(target_ids) ads.each do |ad| - report = Report.find_by(ad_id: ad.id, adspot_id: params[:adspot_id]) + report = Report.find_by(ad_id: ad.id, adspot_id: params[:adspot_id],date: Date.today) unless report - report = Report.new(ad_id: ad.id, adspot_id: params[:adspot_id]) + report = Report.new(ad_id: ad.id, adspot_id: params[:adspot_id], date: Date.today) end report.imp += 1 @@ -27,13 +27,14 @@ def view end def click - if report = Report.find_by(ad_id: params[:ad_id], adspot_id: params[:adspot_id]) - report.click += 1 + report = Report.find_by(ad_id: params[:ad_id], adspot_id: params[:adspot_id],date: Date.today) + unless report + report = Report.new(ad_id: params[:ad_id], adspot_id: params[:adspot_id], date: Date.today) + end + report.click += 1 report.price += Ad.find(params[:ad_id]).price report.save - end - - end end + diff --git a/spec/controllers/ad_api_controller_spec.rb b/spec/controllers/ad_api_controller_spec.rb index 7b11e33..c0b662a 100644 --- a/spec/controllers/ad_api_controller_spec.rb +++ b/spec/controllers/ad_api_controller_spec.rb @@ -2,19 +2,173 @@ require 'rails_helper' RSpec.describe AdApiController, type: :controller do - befoere do + before do + @ad1 =FactoryBot.create(:ad) end + describe 'GET #view' do - it 'returns http success' do - get :view + it 'returns http success with valid params' do + get :view,params: {adspot_id: 1,count: 1} expect(response).to have_http_status(:success) end - end - describe 'GET #click' do - it 'returns http success' do - get :click - expect(response).to have_http_status(:success) + describe "Report" do + it "an ad should be recorded" do + expect { get :view,params: {adspot_id: 1,count: 1} }.to change(Report, :count).by(1) + end + + it "record 'imp' should be increased" do + get :view,params: {adspot_id: 1,count: 1} + report = Report.find_by(ad_id: @ad1.id, adspot_id: 1, date: Date.today) + expect(report.imp).to eq 1 + end + + it "an ad shouldn't be recorded twice from the same adspot_id on the same day" do + get :view,params: {adspot_id: 100,count: 1} + expect { get :view,params: {adspot_id: 100,count: 1}}.to change(Report, :count).by(0) + end + + it "an ad should be recorded from other adspots" do + get :view,params: {adspot_id: 100,count: 1} + expect { get :view,params: {adspot_id: 101,count: 1}}.to change(Report, :count).from(1).to(2) + end + + it "ads should be recorded at the same time" do + ad2 =FactoryBot.create(:ad) + expect { get :view,params: {adspot_id: 101,count: 2}}.to change(Report, :count).from(0).to(2) + end + + it "an ad should be recorded on the other day" do + get :view,params: {adspot_id: 101,count: 1} + travel 1.day do + expect { get :view,params: {adspot_id: 101,count: 1}}.to change(Report, :count).from(1).to(2) + end + end + + + context "when many ads are requested" do + + it "all ads should be visible " do + @ad2 =FactoryBot.create(:ad) + @ad3 =FactoryBot.create(:ad) + get :view,params: {adspot_id: 1,count: 3} + jsons = JSON.parse(response.body) + + + ad1_ispresent = false + ad2_ispresent = false + ad3_ispresent = false + + jsons.each do |json| + if json['ad_id'] == @ad1.id + ad1_ispresent = true + elsif json['ad_id'] == @ad2.id + ad2_ispresent = true + elsif json['ad_id'] == @ad3.id + ad3_ispresent = true + end + end + expect(ad1_ispresent).to be_truthy + expect(ad2_ispresent).to be_truthy + expect(ad3_ispresent).to be_truthy + end + end + end +end + +describe 'GET #click' do + before do + @ad =FactoryBot.create(:ad) + get :view,params: {adspot_id: 1,count: 1} + # get :click,params: {ad_id: ad.id,adspot_id: 1} + # @report = Report.new(ad_id: params[:ad_id], adspot_id: params[:adspot_id], date: Date.today) + + end + + it 'returns http success' do + get :click,params: {ad_id: @ad.id,adspot_id: 1} + expect(response).to have_http_status(:success) end + + describe "Report" do + + it "an ad should be recorded " do + expect { get :click,params: {ad_id: @ad.id,adspot_id: 1} }.to change(Report, :count).by(0) + end + + + it "record 'imp' should be increased" do + get :view,params: {adspot_id: 1,count: 1} + expect { get :click,params: {ad_id: @ad.id,adspot_id: 1} }.to change(Report, :count).by(0) + expect(report.imp).to eq 1 + end + + # it "an ad shouldn't be recorded twice from the same adspot_id on the same day" do + # get :view,params: {adspot_id: 100,count: 1} + # expect { get :view,params: {adspot_id: 100,count: 1}}.to change(Report, :count).by(0) + # end + + # it "an ad should be recorded from other adspots" do + # get :view,params: {adspot_id: 100,count: 1} + # expect { get :view,params: {adspot_id: 101,count: 1}}.to change(Report, :count).from(1).to(2) + # end + + # it "ads should be recorded at the same time" do + # ad2 =FactoryBot.create(:ad) + # expect { get :view,params: {adspot_id: 101,count: 2}}.to change(Report, :count).from(0).to(2) + # end + + # it "an ad should be recorded on the other day" do + # get :view,params: {adspot_id: 101,count: 1} + # travel 1.day do + # expect { get :view,params: {adspot_id: 101,count: 1}}.to change(Report, :count).from(1).to(2) + # end + # end + end + end +end + +# it 'returns http success with valid params' do +# get :view,params: {adspot_id: 1,count: 1} +# expect(response).to have_http_status(:success) +# end + +# describe "Report" do +# it "an ad should be recorded" do +# expect { get :view,params: {adspot_id: 1,count: 1} }.to change(Report, :count).by(1) +# end + +# it "an ad should be recorded" do +# get :view,params: {adspot_id: 1,count: 1} +# report = Report.find_by(ad_id: @ad1.id, adspot_id: 1, date: Date.today) +# expect(report.imp).to eq 1 +# end + +# it "an ad shouldn't be recorded twice from the same adspot_id on the same day" do +# get :view,params: {adspot_id: 100,count: 1} +# expect { get :view,params: {adspot_id: 100,count: 1}}.to change(Report, :count).by(0) +# end + +# it "an ad should be recorded from other adspots" do +# get :view,params: {adspot_id: 100,count: 1} +# expect { get :view,params: {adspot_id: 101,count: 1}}.to change(Report, :count).from(1).to(2) +# end + +# it "ads should be recorded at the same time" do +# ad2 =FactoryBot.create(:ad) +# expect { get :view,params: {adspot_id: 101,count: 2}}.to change(Report, :count).from(0).to(2) +# end + +# it "an ad should be recorded on the other day" do +# get :view,params: {adspot_id: 101,count: 1} +# travel 1.day do +# expect { get :view,params: {adspot_id: 101,count: 1}}.to change(Report, :count).from(1).to(2) +# end +# end + + +# end +# end +# end diff --git a/spec/factories/ads.rb b/spec/factories/ads.rb index 7ed619b..747dd8f 100644 --- a/spec/factories/ads.rb +++ b/spec/factories/ads.rb @@ -3,7 +3,7 @@ factory :ad do advertiser_id { 1 } image { Rack::Test::UploadedFile.new(File.join(Rails.root, 'spec/fixture/image.jpg')) } - price { 222 } + price { 1 } text { 'Test Text' } end end diff --git a/spec/factories/repos.rb b/spec/factories/repos.rb deleted file mode 100644 index 9edb725..0000000 --- a/spec/factories/repos.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true -FactoryBot.define do - factory :report do - click { 1 } - imp { 1 } - cv { 1 } - totalcost { 1 } - adspot_id { 1 } - end -end From 69841ea53e643e63626581821bcaa3c176877e10 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Tue, 25 Jun 2019 18:13:32 +0900 Subject: [PATCH 17/27] add click rspec --- spec/controllers/ad_api_controller_spec.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spec/controllers/ad_api_controller_spec.rb b/spec/controllers/ad_api_controller_spec.rb index c0b662a..072b322 100644 --- a/spec/controllers/ad_api_controller_spec.rb +++ b/spec/controllers/ad_api_controller_spec.rb @@ -82,7 +82,7 @@ @ad =FactoryBot.create(:ad) get :view,params: {adspot_id: 1,count: 1} # get :click,params: {ad_id: ad.id,adspot_id: 1} - # @report = Report.new(ad_id: params[:ad_id], adspot_id: params[:adspot_id], date: Date.today) + #@report = Report.new(ad_id: params[:ad_id], adspot_id: params[:adspot_id], date: Date.today) end @@ -98,11 +98,10 @@ end - it "record 'imp' should be increased" do - get :view,params: {adspot_id: 1,count: 1} - expect { get :click,params: {ad_id: @ad.id,adspot_id: 1} }.to change(Report, :count).by(0) - expect(report.imp).to eq 1 - end + # it "record 'click' should be increased" do + # report = Report.find_by(ad_id: @ad.id, adspot_id: 1,date: Date.today) + # expect{get :click,params: {ad_id: @ad.id,adspot_id: 1}}.to change(report.click).by(0) + # end # it "an ad shouldn't be recorded twice from the same adspot_id on the same day" do # get :view,params: {adspot_id: 100,count: 1} From 26e04f9c7c8426d8331c1f900a98d3105cbe9406 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Thu, 27 Jun 2019 12:41:53 +0900 Subject: [PATCH 18/27] add_ media.site.htm --- public/media.site.htm | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 public/media.site.htm diff --git a/public/media.site.htm b/public/media.site.htm new file mode 100644 index 0000000..43a7aec --- /dev/null +++ b/public/media.site.htm @@ -0,0 +1,58 @@ + + + + 媒体TEST + + + + +
+ +
+ + + From 7296024ebab08f0e695decbeabb3a9792105dbbd Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Thu, 27 Jun 2019 16:56:50 +0900 Subject: [PATCH 19/27] change action name(view,click) --- app/controllers/ad_api_controller.rb | 4 ++-- config/routes.rb | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/ad_api_controller.rb b/app/controllers/ad_api_controller.rb index bee16c1..040ca52 100644 --- a/app/controllers/ad_api_controller.rb +++ b/app/controllers/ad_api_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class AdApiController < ApplicationController - def view + def view_make_report array = [] reports = [] @@ -26,7 +26,7 @@ def view render json: array end - def click + def click_make_report report = Report.find_by(ad_id: params[:ad_id], adspot_id: params[:adspot_id],date: Date.today) unless report report = Report.new(ad_id: params[:ad_id], adspot_id: params[:adspot_id], date: Date.today) diff --git a/config/routes.rb b/config/routes.rb index f0de26f..dd30d38 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true Rails.application.routes.draw do - get '/view' => 'ad_api#view' - get '/click' => 'ad_api#click' + get '/view' => 'ad_api#view_make_report' + get '/click' => 'ad_api#click_make_report' resources :ad - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end From 39d598f15cec15fd622b6896154d1093ed90420c Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Thu, 27 Jun 2019 16:57:01 +0900 Subject: [PATCH 20/27] add rspec --- spec/controllers/ad_api_controller_spec.rb | 190 ++++++--------------- 1 file changed, 55 insertions(+), 135 deletions(-) diff --git a/spec/controllers/ad_api_controller_spec.rb b/spec/controllers/ad_api_controller_spec.rb index 072b322..5c3ba56 100644 --- a/spec/controllers/ad_api_controller_spec.rb +++ b/spec/controllers/ad_api_controller_spec.rb @@ -3,171 +3,91 @@ RSpec.describe AdApiController, type: :controller do before do - @ad1 =FactoryBot.create(:ad) + @ad1 = FactoryBot.create(:ad) end - describe 'GET #view' do + describe 'GET #view_make_report' do it 'returns http success with valid params' do - get :view,params: {adspot_id: 1,count: 1} + get :view_make_report, params: { adspot_id: 1, count: 1 } expect(response).to have_http_status(:success) end - describe "Report" do - it "an ad should be recorded" do - expect { get :view,params: {adspot_id: 1,count: 1} }.to change(Report, :count).by(1) + describe 'Report' do + it 'an ad should be recorded' do + expect { get :view_make_report, params: { adspot_id: 1, count: 1 } }.to change(Report, :count).by(1) end it "record 'imp' should be increased" do - get :view,params: {adspot_id: 1,count: 1} - report = Report.find_by(ad_id: @ad1.id, adspot_id: 1, date: Date.today) + get :view_make_report, params: { adspot_id: 1, count: 1 } + report = Report.find_by(ad_id: @ad1.id, adspot_id: 1, date: Date.today) expect(report.imp).to eq 1 end it "an ad shouldn't be recorded twice from the same adspot_id on the same day" do - get :view,params: {adspot_id: 100,count: 1} - expect { get :view,params: {adspot_id: 100,count: 1}}.to change(Report, :count).by(0) + get :view_make_report, params: { adspot_id: 100, count: 1 } + expect { get :view_make_report, params: { adspot_id: 100, count: 1 } }.to change(Report, :count).by(0) end - it "an ad should be recorded from other adspots" do - get :view,params: {adspot_id: 100,count: 1} - expect { get :view,params: {adspot_id: 101,count: 1}}.to change(Report, :count).from(1).to(2) + it 'an ad should be recorded from other adspots' do + get :view_make_report, params: { adspot_id: 100, count: 1 } + expect { get :view_make_report, params: { adspot_id: 101, count: 1 } }.to change(Report, :count).from(1).to(2) end - it "ads should be recorded at the same time" do - ad2 =FactoryBot.create(:ad) - expect { get :view,params: {adspot_id: 101,count: 2}}.to change(Report, :count).from(0).to(2) + it 'ads should be recorded at the same time' do + ad2 = FactoryBot.create(:ad) + expect { get :view_make_report, params: { adspot_id: 101, count: 2 } }.to change(Report, :count).from(0).to(2) end - it "an ad should be recorded on the other day" do - get :view,params: {adspot_id: 101,count: 1} + it 'an ad should be recorded on the other day' do + get :view_make_report, params: { adspot_id: 101, count: 1 } travel 1.day do - expect { get :view,params: {adspot_id: 101,count: 1}}.to change(Report, :count).from(1).to(2) + expect { get :view_make_report, params: { adspot_id: 101, count: 1 } }.to change(Report, :count).from(1).to(2) end + end - end - - - context "when many ads are requested" do - - it "all ads should be visible " do - @ad2 =FactoryBot.create(:ad) - @ad3 =FactoryBot.create(:ad) - get :view,params: {adspot_id: 1,count: 3} - jsons = JSON.parse(response.body) - - - ad1_ispresent = false - ad2_ispresent = false - ad3_ispresent = false - - jsons.each do |json| - if json['ad_id'] == @ad1.id - ad1_ispresent = true - elsif json['ad_id'] == @ad2.id - ad2_ispresent = true - elsif json['ad_id'] == @ad3.id - ad3_ispresent = true + context 'when many ads are requested' do + it 'all ads should be visible ' do + @ad2 = FactoryBot.create(:ad) + @ad3 = FactoryBot.create(:ad) + get :view_make_report, params: { adspot_id: 1, count: 3 } + jsons = JSON.parse(response.body) + + ad1_ispresent = false + ad2_ispresent = false + ad3_ispresent = false + + jsons.each do |json| + if json['ad_id'] == @ad1.id + ad1_ispresent = true + elsif json['ad_id'] == @ad2.id + ad2_ispresent = true + elsif json['ad_id'] == @ad3.id + ad3_ispresent = true + end end + expect(ad1_ispresent).to be_truthy + expect(ad2_ispresent).to be_truthy + expect(ad3_ispresent).to be_truthy end - expect(ad1_ispresent).to be_truthy - expect(ad2_ispresent).to be_truthy - expect(ad3_ispresent).to be_truthy end end end -end - -describe 'GET #click' do - before do - @ad =FactoryBot.create(:ad) - get :view,params: {adspot_id: 1,count: 1} - # get :click,params: {ad_id: ad.id,adspot_id: 1} - #@report = Report.new(ad_id: params[:ad_id], adspot_id: params[:adspot_id], date: Date.today) - - end - it 'returns http success' do - get :click,params: {ad_id: @ad.id,adspot_id: 1} - expect(response).to have_http_status(:success) - end + describe 'GET #click_make_report' do + before do + @ad = FactoryBot.create(:ad) + get :view_make_report, params: { adspot_id: 1, count: 1 } + end - describe "Report" do + it 'returns http success' do + get :click_make_report, params: { ad_id: @ad.id, adspot_id: 1 } + expect(response).to have_http_status(:success) + end - it "an ad should be recorded " do - expect { get :click,params: {ad_id: @ad.id,adspot_id: 1} }.to change(Report, :count).by(0) + describe 'Report' do + it 'an ad should be recorded ' do + expect { get :click_make_report, params: { ad_id: @ad.id, adspot_id: 1 } }.to change(Report, :count).by(0) end - - - # it "record 'click' should be increased" do - # report = Report.find_by(ad_id: @ad.id, adspot_id: 1,date: Date.today) - # expect{get :click,params: {ad_id: @ad.id,adspot_id: 1}}.to change(report.click).by(0) - # end - - # it "an ad shouldn't be recorded twice from the same adspot_id on the same day" do - # get :view,params: {adspot_id: 100,count: 1} - # expect { get :view,params: {adspot_id: 100,count: 1}}.to change(Report, :count).by(0) - # end - - # it "an ad should be recorded from other adspots" do - # get :view,params: {adspot_id: 100,count: 1} - # expect { get :view,params: {adspot_id: 101,count: 1}}.to change(Report, :count).from(1).to(2) - # end - - # it "ads should be recorded at the same time" do - # ad2 =FactoryBot.create(:ad) - # expect { get :view,params: {adspot_id: 101,count: 2}}.to change(Report, :count).from(0).to(2) - # end - - # it "an ad should be recorded on the other day" do - # get :view,params: {adspot_id: 101,count: 1} - # travel 1.day do - # expect { get :view,params: {adspot_id: 101,count: 1}}.to change(Report, :count).from(1).to(2) - # end - # end end - -end + end end - -# it 'returns http success with valid params' do -# get :view,params: {adspot_id: 1,count: 1} -# expect(response).to have_http_status(:success) -# end - -# describe "Report" do -# it "an ad should be recorded" do -# expect { get :view,params: {adspot_id: 1,count: 1} }.to change(Report, :count).by(1) -# end - -# it "an ad should be recorded" do -# get :view,params: {adspot_id: 1,count: 1} -# report = Report.find_by(ad_id: @ad1.id, adspot_id: 1, date: Date.today) -# expect(report.imp).to eq 1 -# end - -# it "an ad shouldn't be recorded twice from the same adspot_id on the same day" do -# get :view,params: {adspot_id: 100,count: 1} -# expect { get :view,params: {adspot_id: 100,count: 1}}.to change(Report, :count).by(0) -# end - -# it "an ad should be recorded from other adspots" do -# get :view,params: {adspot_id: 100,count: 1} -# expect { get :view,params: {adspot_id: 101,count: 1}}.to change(Report, :count).from(1).to(2) -# end - -# it "ads should be recorded at the same time" do -# ad2 =FactoryBot.create(:ad) -# expect { get :view,params: {adspot_id: 101,count: 2}}.to change(Report, :count).from(0).to(2) -# end - -# it "an ad should be recorded on the other day" do -# get :view,params: {adspot_id: 101,count: 1} -# travel 1.day do -# expect { get :view,params: {adspot_id: 101,count: 1}}.to change(Report, :count).from(1).to(2) -# end -# end - - -# end -# end -# end From 299dc5a8a7b3bbedf510efd1cecae2cac34008ba Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Thu, 27 Jun 2019 16:57:19 +0900 Subject: [PATCH 21/27] rubocop --auto-correct --- db/migrate/20190614041856_create_repos.rb | 2 +- db/schema.rb | 37 +++++++++++------------ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/db/migrate/20190614041856_create_repos.rb b/db/migrate/20190614041856_create_repos.rb index afcdf16..3e1ddf2 100644 --- a/db/migrate/20190614041856_create_repos.rb +++ b/db/migrate/20190614041856_create_repos.rb @@ -8,7 +8,7 @@ def change t.integer :imp, null: false, default: 0 t.integer :cv, null: false, default: 0 t.integer :price, null: false, default: 0 - t.date :date,null: false,unique: true + t.date :date, null: false, unique: true t.timestamps end end diff --git a/db/schema.rb b/db/schema.rb index 9b77ba1..f78b812 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -11,26 +12,24 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2019_06_14_041856) do - - create_table "ads", force: :cascade do |t| - t.integer "advertiser_id", null: false - t.string "image", default: "", null: false - t.integer "price", null: false - t.string "text", default: "", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'ads', force: :cascade do |t| + t.integer 'advertiser_id', null: false + t.string 'image', default: '', null: false + t.integer 'price', null: false + t.string 'text', default: '', null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - create_table "reports", force: :cascade do |t| - t.integer "ad_id", null: false - t.integer "adspot_id", null: false - t.integer "click", default: 0, null: false - t.integer "imp", default: 0, null: false - t.integer "cv", default: 0, null: false - t.integer "price", default: 0, null: false - t.date "date", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'reports', force: :cascade do |t| + t.integer 'ad_id', null: false + t.integer 'adspot_id', null: false + t.integer 'click', default: 0, null: false + t.integer 'imp', default: 0, null: false + t.integer 'cv', default: 0, null: false + t.integer 'price', default: 0, null: false + t.date 'date', null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - end From c2c97343297ddf4f7b5314e2f5da079bf3379037 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Thu, 27 Jun 2019 16:58:42 +0900 Subject: [PATCH 22/27] change html name corresponding to action names --- app/views/ad_api/click_create_report.html.erb | 2 ++ app/views/ad_api/view_create_report.html.erb | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 app/views/ad_api/click_create_report.html.erb create mode 100644 app/views/ad_api/view_create_report.html.erb diff --git a/app/views/ad_api/click_create_report.html.erb b/app/views/ad_api/click_create_report.html.erb new file mode 100644 index 0000000..e3e77a6 --- /dev/null +++ b/app/views/ad_api/click_create_report.html.erb @@ -0,0 +1,2 @@ +

AdApi#click

+

Find me in app/views/ad_api/click.html.erb

diff --git a/app/views/ad_api/view_create_report.html.erb b/app/views/ad_api/view_create_report.html.erb new file mode 100644 index 0000000..b5fd078 --- /dev/null +++ b/app/views/ad_api/view_create_report.html.erb @@ -0,0 +1,2 @@ +

AdApi#view

+

Find me in app/views/ad_api/view.html.erb

From 0a6a8c202d1e82db371094d3c9809d9bb3bee215 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Thu, 27 Jun 2019 16:59:52 +0900 Subject: [PATCH 23/27] delete unused files --- app/views/ad_api/click.html.erb | 2 -- app/views/ad_api/view.html.erb | 2 -- 2 files changed, 4 deletions(-) delete mode 100644 app/views/ad_api/click.html.erb delete mode 100644 app/views/ad_api/view.html.erb diff --git a/app/views/ad_api/click.html.erb b/app/views/ad_api/click.html.erb deleted file mode 100644 index e3e77a6..0000000 --- a/app/views/ad_api/click.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

AdApi#click

-

Find me in app/views/ad_api/click.html.erb

diff --git a/app/views/ad_api/view.html.erb b/app/views/ad_api/view.html.erb deleted file mode 100644 index b5fd078..0000000 --- a/app/views/ad_api/view.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

AdApi#view

-

Find me in app/views/ad_api/view.html.erb

From 7b9e86a329a3d3b0b0675021145666477ac35523 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Thu, 27 Jun 2019 17:43:37 +0900 Subject: [PATCH 24/27] rename files --- app/controllers/ad_api_controller.rb | 2 +- ...{click_create_report.html.erb => click_make_report.html.erb} | 0 .../{view_create_report.html.erb => view_make_report.html.erb} | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename app/views/ad_api/{click_create_report.html.erb => click_make_report.html.erb} (100%) rename app/views/ad_api/{view_create_report.html.erb => view_make_report.html.erb} (100%) diff --git a/app/controllers/ad_api_controller.rb b/app/controllers/ad_api_controller.rb index 040ca52..74873a4 100644 --- a/app/controllers/ad_api_controller.rb +++ b/app/controllers/ad_api_controller.rb @@ -17,7 +17,7 @@ def view_make_report reports.push(report) array.push( - img_url: ad.image, + img_url: ad.image.url, body: ad.text, ad_id: ad.id ) diff --git a/app/views/ad_api/click_create_report.html.erb b/app/views/ad_api/click_make_report.html.erb similarity index 100% rename from app/views/ad_api/click_create_report.html.erb rename to app/views/ad_api/click_make_report.html.erb diff --git a/app/views/ad_api/view_create_report.html.erb b/app/views/ad_api/view_make_report.html.erb similarity index 100% rename from app/views/ad_api/view_create_report.html.erb rename to app/views/ad_api/view_make_report.html.erb From 11e2cc2c634898531ae570f2fb8db19d8b2ef261 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Thu, 27 Jun 2019 17:52:20 +0900 Subject: [PATCH 25/27] delete unused files --- media_site.htm | 58 -------------------------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 media_site.htm diff --git a/media_site.htm b/media_site.htm deleted file mode 100644 index 43a7aec..0000000 --- a/media_site.htm +++ /dev/null @@ -1,58 +0,0 @@ - - - - 媒体TEST - - - - -
- -
- - - From cf3dc25a9aac7368a25306d038e4d59a7b685665 Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Thu, 27 Jun 2019 17:54:25 +0900 Subject: [PATCH 26/27] delete comment --- db/migrate/20190528085221_create_ads.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190528085221_create_ads.rb b/db/migrate/20190528085221_create_ads.rb index 27ae217..03e4ae9 100644 --- a/db/migrate/20190528085221_create_ads.rb +++ b/db/migrate/20190528085221_create_ads.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -class CreateAds < ActiveRecord::Migration[5.2] # Reportテーブルのtotalpriceにpriceを加算する為に使用しているのでここでも使っています +class CreateAds < ActiveRecord::Migration[5.2] def change create_table :ads do |t| t.integer :advertiser_id, null: false # 広告主ID From 2e9eefdf0256cbbcc2e8ef05b088de9e3ac36b7b Mon Sep 17 00:00:00 2001 From: bbjjki4 Date: Fri, 28 Jun 2019 09:59:25 +0900 Subject: [PATCH 27/27] fix action names --- app/controllers/ad_api_controller.rb | 5 ++- ...make_report.html.erb => update_clicks.erb} | 0 config/routes.rb | 4 +-- public/uploads/ad/image/1/bg_topicon_p04.png | Bin 2600 -> 0 bytes spec/controllers/ad_api_controller_spec.rb | 32 +++++++++--------- 5 files changed, 20 insertions(+), 21 deletions(-) rename app/views/ad_api/{click_make_report.html.erb => update_clicks.erb} (100%) delete mode 100644 public/uploads/ad/image/1/bg_topicon_p04.png diff --git a/app/controllers/ad_api_controller.rb b/app/controllers/ad_api_controller.rb index 74873a4..20d6dba 100644 --- a/app/controllers/ad_api_controller.rb +++ b/app/controllers/ad_api_controller.rb @@ -1,7 +1,6 @@ - # frozen_string_literal: true class AdApiController < ApplicationController - def view_make_report + def get_ads array = [] reports = [] @@ -26,7 +25,7 @@ def view_make_report render json: array end - def click_make_report + def update_clicks report = Report.find_by(ad_id: params[:ad_id], adspot_id: params[:adspot_id],date: Date.today) unless report report = Report.new(ad_id: params[:ad_id], adspot_id: params[:adspot_id], date: Date.today) diff --git a/app/views/ad_api/click_make_report.html.erb b/app/views/ad_api/update_clicks.erb similarity index 100% rename from app/views/ad_api/click_make_report.html.erb rename to app/views/ad_api/update_clicks.erb diff --git a/config/routes.rb b/config/routes.rb index dd30d38..49eb81a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true Rails.application.routes.draw do - get '/view' => 'ad_api#view_make_report' - get '/click' => 'ad_api#click_make_report' + get '/view' => 'ad_api#get_ads' + get '/click' => 'ad_api#update_clicks' resources :ad end diff --git a/public/uploads/ad/image/1/bg_topicon_p04.png b/public/uploads/ad/image/1/bg_topicon_p04.png deleted file mode 100644 index a773d0aa5aa53897b21b28db2551f6fe036e8b1d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2600 zcmV+@3fJ|CP)00004b3#c}2nYxW zddbVG7wVRUJ4ZXi@?ZDjy4GA=nT zGBXHu2i*Vw0338hSaefwW^{L9a%BKPWN%_+AVz6&Wp{6KYjYq&Q#En5<2C>Q34uvO zK~#90?VUSp8^;!ge>%JpK!A_|GDTGIQAsIm374vDD5fj9O5^~kLL*F*SXG?%rcvWw zu4ucGVWySjR8l26Ok9ZpEfq4;P*kBN6kvh41f+&3&WyO+_mbS*+2wq|0@85F9qd2n z%$YN@I}wD4LaBEXz#=Q&MtGIj zU-?`eE8alxMj*WK%#9a8g8OaRPPqUzfKAc517U?PlzK&w;P?Ek$=G-cY5<#lR|F7H zcqaHd>_^{0qXl5y?*<@@@P$%u6~G3FWS~^7`6>@(k1kcrps`MR*peZ(?%Xx?NfTie8KWxbQdJz7VHS>TLkn zhZJ3pG=P0}k37M3i!YRV8PJ$^!R>2>g!cee%WIJnH-6j`i)Rsg9a3~BEC8spd*>Ri z312Ano&eZJ@Um_qFauzl-9uM!#nl%|y-fh$x$)Z*$gA>Nq&Ti0b0w;0L$w`D?%3Qd z-h%r5k%xR^7oLe;f$Y!S;yr-;sN#<`xRauL!UBK_yVoN#vhY%LPZ^u|ASY>X*~Z2s}xDC7L0qI#B9+8*|zlCkp8$=v?X!#S3F zuR~_!MBxI!qTSs7D8soONYO=N215jUj)Z5^hBAT|j|Hbwy0%?CTST$%v_=w7xo@?Y z!%-j45(ag6u!!RIWBu|+&)vQ<5t{~b8Q_aKV19P+v(s~+)&zcU0PT)9^>IiG)ZZJX zb-D0Sn?JaY30OIk%L0WvKr*iXc`8B2%57lp5ZF5KwthB9gS4_7=2`afY&C4?7e*HD z0#8u2pYX?pZC}vg+f*Z|!%qWvA!B%YC5L9xPABfgkT{ zgT9ALLI!*rFd5$)T0DD}Ez|*BF01X+PtSp;ziCAWNZ6;p0Uyq^pFOzkP8~-e%{0`- z%+;@ty()r{%V^8We*)c0^Y6XT$!2^$t1T0Nb)ye-g`Wg#2Y^p?to>NWn$@&B+CD#( z7+bZ*iJ{dSS-kGaVMFca_1wD=rw-2bnWA2yMtGK*4Rs{X5pWFd2KShz1L#?N(en`Bu2ih{D1dkxhKxNQ+!cPpfrZ(x4N>CbB&+?OT;ORHo2)=to2^_&0(DpiW z$6SHv?~xljFZY4}sq*cq1eNh=Sb+L;y>UN4DP60vzW{v2H2w$-rfet5+BwH(z}}I5 zzMfCRno(^4yNB-7%>`CLZzLIT^%E&PK-s#zBj?|%odD%`W3P^zTx+bf_`LV^5Qp-g zWc_9fF*w~TVHaXpk>`Izf$OAA=%V>_k`_(aNy7rvpVyke@|^L~tKCDg^Z@kfddxg} zj{NJ#sBnw7T(J=()YGTkD-v|?$X;5u+8}XXd_P#ebnJ>x0KUCL2e)h^L2D;{;f>BoC&{|`d3yX`9BT)d)=@UL3vB-$ zn+6`-qE#?X;a-4Gv+f=aCUj~|vh>&#H4-JcEL~R}2Po-Yl4ntW*JoxPJ;%)`0^GlU zK1)`v7ln5(ftM8$@4p#xx4EqT?QyX`@`T6?_ZV5E$WW zO_~A?a=$7Pff0UV&!6k&vOt=pf&b}f8(!-?n0E|8z(|b$VB?Oi8;#2_Ml2jPT05dH0GMz=ty$U)#yraiQ(@+tmhe(4?`vQ&Jtx9*|Z) z2~_wWO5sP|s8%98*BUEx^%d{yp+%tRH;h#HAJ-Powy1pLLuDl1@J6`}srt>9(%pxb z0d1x5lY_DFEPeaR)9OgP;FWs!Nxk>gZ+cS~iHB^e3v~CEEtGn7$X%nu!u#@C`z`XFMdnWgaMwMZSnv$0f1 z;swu`W~SJ&cz~kA)=1TnctHy`M`N~xXL;V@@b!^+L{XiSH{xF>%3gB$TdBkV0000< KMNUMnLSTZoN%7nO diff --git a/spec/controllers/ad_api_controller_spec.rb b/spec/controllers/ad_api_controller_spec.rb index 5c3ba56..310f5b0 100644 --- a/spec/controllers/ad_api_controller_spec.rb +++ b/spec/controllers/ad_api_controller_spec.rb @@ -6,42 +6,42 @@ @ad1 = FactoryBot.create(:ad) end - describe 'GET #view_make_report' do + describe 'GET #get_ads' do it 'returns http success with valid params' do - get :view_make_report, params: { adspot_id: 1, count: 1 } + get :get_ads, params: { adspot_id: 1, count: 1 } expect(response).to have_http_status(:success) end describe 'Report' do it 'an ad should be recorded' do - expect { get :view_make_report, params: { adspot_id: 1, count: 1 } }.to change(Report, :count).by(1) + expect { get :get_ads, params: { adspot_id: 1, count: 1 } }.to change(Report, :count).by(1) end it "record 'imp' should be increased" do - get :view_make_report, params: { adspot_id: 1, count: 1 } + get :get_ads, params: { adspot_id: 1, count: 1 } report = Report.find_by(ad_id: @ad1.id, adspot_id: 1, date: Date.today) expect(report.imp).to eq 1 end it "an ad shouldn't be recorded twice from the same adspot_id on the same day" do - get :view_make_report, params: { adspot_id: 100, count: 1 } - expect { get :view_make_report, params: { adspot_id: 100, count: 1 } }.to change(Report, :count).by(0) + get :get_ads, params: { adspot_id: 100, count: 1 } + expect { get :get_ads, params: { adspot_id: 100, count: 1 } }.to change(Report, :count).by(0) end it 'an ad should be recorded from other adspots' do - get :view_make_report, params: { adspot_id: 100, count: 1 } - expect { get :view_make_report, params: { adspot_id: 101, count: 1 } }.to change(Report, :count).from(1).to(2) + get :get_ads, params: { adspot_id: 100, count: 1 } + expect { get :get_ads, params: { adspot_id: 101, count: 1 } }.to change(Report, :count).from(1).to(2) end it 'ads should be recorded at the same time' do ad2 = FactoryBot.create(:ad) - expect { get :view_make_report, params: { adspot_id: 101, count: 2 } }.to change(Report, :count).from(0).to(2) + expect { get :get_ads, params: { adspot_id: 101, count: 2 } }.to change(Report, :count).from(0).to(2) end it 'an ad should be recorded on the other day' do - get :view_make_report, params: { adspot_id: 101, count: 1 } + get :get_ads, params: { adspot_id: 101, count: 1 } travel 1.day do - expect { get :view_make_report, params: { adspot_id: 101, count: 1 } }.to change(Report, :count).from(1).to(2) + expect { get :get_ads, params: { adspot_id: 101, count: 1 } }.to change(Report, :count).from(1).to(2) end end @@ -49,7 +49,7 @@ it 'all ads should be visible ' do @ad2 = FactoryBot.create(:ad) @ad3 = FactoryBot.create(:ad) - get :view_make_report, params: { adspot_id: 1, count: 3 } + get :get_ads, params: { adspot_id: 1, count: 3 } jsons = JSON.parse(response.body) ad1_ispresent = false @@ -73,20 +73,20 @@ end end - describe 'GET #click_make_report' do + describe 'GET #update_clicks' do before do @ad = FactoryBot.create(:ad) - get :view_make_report, params: { adspot_id: 1, count: 1 } + get :get_ads, params: { adspot_id: 1, count: 1 } end it 'returns http success' do - get :click_make_report, params: { ad_id: @ad.id, adspot_id: 1 } + get :update_clicks, params: { ad_id: @ad.id, adspot_id: 1 } expect(response).to have_http_status(:success) end describe 'Report' do it 'an ad should be recorded ' do - expect { get :click_make_report, params: { ad_id: @ad.id, adspot_id: 1 } }.to change(Report, :count).by(0) + expect { get :update_clicks, params: { ad_id: @ad.id, adspot_id: 1 } }.to change(Report, :count).by(0) end end end