diff --git a/app/controllers/ad_controller.rb b/app/controllers/ad_controller.rb index e7c1ade..99feb68 100644 --- a/app/controllers/ad_controller.rb +++ b/app/controllers/ad_controller.rb @@ -15,26 +15,26 @@ def new def create @ad = Ad.new(ad_params) if @ad.save # 広告登録成功時 - flash[:notice] = 'Ad registered!' + flash[:notice] = '広告を登録しました!' redirect_to(ad_index_path) else - render('ad/new') + render('new') end end def update @ad = Ad.find(params[:id]) if @ad.update_attributes(ad_params) - flash[:notice] = 'Ad updated!' + flash[:notice] = '広告を更新しました!' redirect_to(ad_index_path) else - render('ad/edit') + render('edit') end end def destroy Ad.find(params[:id]).destroy - flash[:notice] = 'Ad deleted!' + flash[:notice] = '広告を削除しました!' redirect_to(ad_index_path) end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb deleted file mode 100644 index 32fe70b..0000000 --- a/app/jobs/application_job.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true -class ApplicationJob < ActiveJob::Base -end diff --git a/app/views/ad/_errorlog.html.erb b/app/views/ad/_errorlog.html.erb index 4e97c9f..8c7200b 100644 --- a/app/views/ad/_errorlog.html.erb +++ b/app/views/ad/_errorlog.html.erb @@ -1,5 +1,5 @@ <% if @ad.errors.any? %> <% @ad.errors.full_messages.each do |error| %> <%# formが空白だった場合にエラーを表示 %> -
  • <%= error %>
  • +
  • <%= error %>
  • <% end %> <% end %> diff --git a/app/views/ad/edit.html.erb b/app/views/ad/edit.html.erb index 8e25f42..f554292 100644 --- a/app/views/ad/edit.html.erb +++ b/app/views/ad/edit.html.erb @@ -1,14 +1,14 @@ <%= render partial: "errorlog" %> <%= form_for(@ad ,url: ad_path(@ad),html: {method: "patch",class: "form-group"}) do |f| %> <%##入稿フォーム %> -
    -

    text

    +
    +

    テキスト

    <%= f.text_area :text,value: @ad.text,class: "form-control" %> -

    price

    +

    単価

    <%= f.number_field :price,value: @ad.price %> -

    advertiser_id

    +

    広告主ID

    <%= f.number_field :advertiser_id,value: @ad.advertiser_id %> -

    image

    +

    イメージ

    <%= f.file_field :image,value: @ad.image,class: "form-control-file" %> - <%= f.submit class: "btn btn-primary",value: "更新" %> + <%= f.submit class: "btn btn-primary h2",value: "更新" %>
    <% end %> diff --git a/app/views/ad/index.html.erb b/app/views/ad/index.html.erb index 7296a3d..068e86c 100644 --- a/app/views/ad/index.html.erb +++ b/app/views/ad/index.html.erb @@ -1,27 +1,39 @@
    -
    <%# 広告を一つ一つ表示 %> - <% @ads.each do |ad| %> -
  • - ad_id :<%= ad.id %> -
  • -
  • - text :<%= ad.text %> -
  • -
  • - price :<%= ad.price %> -
  • -
  • - <%= image_tag ad.image.to_s %> -
  • -
    - <%= link_to("Edit", edit_ad_path(ad)) %> -
    -
    - <%= link_to("Delete", ad_path(ad) ,method: :delete) %> -
    - <% end %> -
    - <%= link_to("New", new_ad_path) %> -
    + + + + + + + + + + + + + + + + <% @ads.each do |ad| %> + + + + + + + + <% end %> + +
    広告ID広告主IDテキスト単価イメージ画像操作
    <%= ad.id %><%= ad.advertiser_id %><%= ad.text %><%= ad.price %><%= image_tag ad.image.to_s %>

    + <%= link_to("変更", edit_ad_path(ad)) %> +

    +

    + <%= link_to("削除", ad_path(ad) ,method: :delete) %> +

    +
    diff --git a/app/views/ad/new.html.erb b/app/views/ad/new.html.erb index a841e3b..fd331f4 100644 --- a/app/views/ad/new.html.erb +++ b/app/views/ad/new.html.erb @@ -1,14 +1,14 @@ <%= render partial: "errorlog" %> <%= form_for(@ad ,url: ad_index_path,html: {method: "post",class: "form-group"}) do |f| %> <%##入稿フォーム %> -
    -

    text

    +
    +

    テキスト

    <%= f.text_area :text,value: @ad.text,class: "form-control" %> -

    price

    +

    単価

    <%= f.number_field :price,value: @ad.price %> -

    advertiser_id

    +

    広告主ID

    <%= f.number_field :advertiser_id,value: @ad.advertiser_id %> -

    image

    +

    イメージ

    <%= f.file_field :image,value: @ad.image,class: "form-control-file" %> - <%= f.submit class: "btn btn-primary",value: "入稿" %> + <%= f.submit class: "btn btn-primary h2",value: "入稿" %>
    <% end %> 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/schema.rb b/db/schema.rb index d6923dc..f887c36 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_06_04_073026) do +ActiveRecord::Schema.define(version: 2019_05_28_085221) do create_table 'ads', force: :cascade do |t| t.integer 'advertiser_id', default: 0, null: false t.string 'image', default: '', null: false @@ -19,8 +19,5 @@ 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' end end diff --git a/spec/controllers/ad_controller_spec.rb b/spec/controllers/ad_controller_spec.rb index f8471fd..4cc4a3d 100644 --- a/spec/controllers/ad_controller_spec.rb +++ b/spec/controllers/ad_controller_spec.rb @@ -58,8 +58,7 @@ 'price' => nil, 'advertiser_id' => nil, 'image' => nil - }, - id: @ad.id } + }, id: @ad.id } expect(response).to render_template :edit end @@ -89,15 +88,14 @@ 'price' => 1010101, 'advertiser_id' => 1010101, 'image' => Rack::Test::UploadedFile.new(File.join(Rails.root, 'spec/fixture/image.jpg')) - }, - id: @ad.id } + }, id: @ad.id } expect(response).to redirect_to(ad_index_path) end end 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 @@ -122,8 +120,7 @@ 'price' => nil, 'advertiser_id' => nil, 'image' => nil - }, - id: @ad.id } + }, id: @ad.id } expect(response).to render_template :edit end end diff --git a/spec/features/path_spec.rb b/spec/features/path_spec.rb index aab875b..763b951 100644 --- a/spec/features/path_spec.rb +++ b/spec/features/path_spec.rb @@ -42,7 +42,7 @@ end it 'new valid?' do - click_link('New') + click_link('新規作成') expect(current_path).to eq new_ad_path end end @@ -50,7 +50,7 @@ describe 'Buttons' do context 'after new ad created' do before do - visit 'ad/new' + visit new_ad_path fill_in 'ad_text', with: 'TextForm' fill_in 'ad_price', with: '1000' fill_in 'ad_advertiser_id', with: '1' @@ -64,11 +64,11 @@ context 'on Index Page' do it 'edit clickable' do - click_link('Edit') + click_link('変更') end it 'Delete clickable and its action workable' do - expect { click_link 'Delete' }.to change { Ad.count }.by(-1) + expect { click_link '削除' }.to change { Ad.count }.by(-1) end end end diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb deleted file mode 100644 index 7ff7b4d..0000000 --- a/test/application_system_test_case.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true -require 'test_helper' - -class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - driven_by :selenium, using: :chrome, screen_size: [1400, 1400] -end diff --git a/test/controllers/.keep b/test/controllers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/controllers/ad_controller_test.rb b/test/controllers/ad_controller_test.rb deleted file mode 100644 index 31b53d3..0000000 --- a/test/controllers/ad_controller_test.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true -require 'test_helper' - -class AdControllerTest < ActionDispatch::IntegrationTest - test 'should get index' do - get ad_index_url - assert_response :success - end - - test 'should get show' do - get ad_show_url - assert_response :success - end - - test 'should get edit' do - get ad_edit_url - assert_response :success - end - - test 'should get new' do - get ad_new_url - assert_response :success - end - - test 'should get create' do - get ad_create_url - assert_response :success - end - - test 'should get edit' do - get ad_edit_url - assert_response :success - end - - test 'should get destroy' do - get ad_destroy_url - assert_response :success - end - -end diff --git a/test/fixtures/.keep b/test/fixtures/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/ads.yml b/test/fixtures/ads.yml deleted file mode 100644 index 3d12954..0000000 --- a/test/fixtures/ads.yml +++ /dev/null @@ -1,13 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html - -one: - advertiser_id: 1 - image: MyString - price: MyString - text: MyString - -two: - advertiser_id: 1 - image: MyString - price: MyString - text: MyString diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/helpers/.keep b/test/helpers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/integration/.keep b/test/integration/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/mailers/.keep b/test/mailers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/models/.keep b/test/models/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/models/ad_test.rb b/test/models/ad_test.rb deleted file mode 100644 index c4220fc..0000000 --- a/test/models/ad_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true -require 'test_helper' - -class AdTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/system/.keep b/test/system/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index 58af444..0000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true -ENV['RAILS_ENV'] ||= 'test' -require_relative '../config/environment' -require 'rails/test_help' - -class ActiveSupport::TestCase - # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. - fixtures :all - - # Add more helper methods to be used by all tests here... -end