From d2890636fd990c9b10462f6701e476d843274ba8 Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 20 Dec 2022 17:05:26 +0200 Subject: [PATCH] create members --- Gemfile | 2 + Gemfile.lock | 52 +++++++++++------- app/controllers/members_controller.rb | 58 +++++++++++++++++++++ app/helpers/members_helper.rb | 2 + app/models/member.rb | 2 + app/views/layouts/_footer.haml | 6 +-- app/views/layouts/_header.haml | 8 +-- app/views/members/_form.html.haml | 16 ++++++ app/views/members/edit.html.haml | 7 +++ app/views/members/index.html.haml | 23 ++++++++ app/views/members/new.html.haml | 5 ++ app/views/members/show.html.haml | 12 +++++ config/routes.rb | 1 + db/migrate/20221220150444_create_members.rb | 10 ++++ db/schema.rb | 24 +++++++++ test/controllers/members_controller_test.rb | 48 +++++++++++++++++ test/fixtures/members.yml | 9 ++++ test/models/member_test.rb | 7 +++ test/system/members_test.rb | 43 +++++++++++++++ 19 files changed, 308 insertions(+), 27 deletions(-) create mode 100644 app/controllers/members_controller.rb create mode 100644 app/helpers/members_helper.rb create mode 100644 app/models/member.rb create mode 100644 app/views/members/_form.html.haml create mode 100644 app/views/members/edit.html.haml create mode 100644 app/views/members/index.html.haml create mode 100644 app/views/members/new.html.haml create mode 100644 app/views/members/show.html.haml create mode 100644 db/migrate/20221220150444_create_members.rb create mode 100644 db/schema.rb create mode 100644 test/controllers/members_controller_test.rb create mode 100644 test/fixtures/members.yml create mode 100644 test/models/member_test.rb create mode 100644 test/system/members_test.rb diff --git a/Gemfile b/Gemfile index 7e923b9..021f392 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,8 @@ gem "sassc-rails" gem 'haml-rails' +gem "ruby2js" , path: "../ruby2js" + # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # gem "image_processing", "~> 1.2" diff --git a/Gemfile.lock b/Gemfile.lock index 6407d35..d5d6143 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,6 +8,14 @@ PATH mini_magick rails (>= 7.0.4) redcarpet + ruby2js (~> 5.0, >= 5.0.1) + +PATH + remote: ../ruby2js + specs: + ruby2js (5.0.1) + parser + regexp_parser (~> 2.1.1) GEM remote: https://rubygems.org/ @@ -81,8 +89,9 @@ GEM tzinfo (~> 2.0) addressable (2.8.1) public_suffix (>= 2.0.2, < 6.0) + ast (2.4.2) bindex (0.8.1) - bootsnap (1.14.0) + bootsnap (1.15.0) msgpack (~> 1.2) builder (3.2.4) capybara (3.38.0) @@ -94,18 +103,18 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - childprocess (4.1.0) coderay (1.1.3) concurrent-ruby (1.1.10) crass (1.0.6) - debug (1.6.3) - irb (>= 1.3.6) + date (3.3.2) + debug (1.7.0) + irb (>= 1.5.0) reline (>= 0.3.1) diff-lcs (1.5.0) erubi (1.11.0) ffi (1.15.5) formatador (1.1.0) - git (1.12.0) + git (1.13.0) addressable (~> 2.8) rchardet (~> 1.8) globalid (1.0.0) @@ -124,7 +133,7 @@ GEM guard (~> 2.1) guard-compat (~> 1.1) rspec (>= 2.99.0, < 4.0) - haml (6.0.12) + haml (6.1.1) temple (>= 0.8.2) thor tilt @@ -138,13 +147,13 @@ GEM importmap-rails (1.1.5) actionpack (>= 6.0.0) railties (>= 6.0.0) - io-console (0.5.11) - irb (1.5.0) + io-console (0.6.0) + irb (1.6.1) reline (>= 0.3.0) listen (3.7.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.19.0) + loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) lumberjack (1.2.8) @@ -164,21 +173,24 @@ GEM minitest (5.16.3) msgpack (1.6.0) nenv (0.3.0) - net-imap (0.3.1) + net-imap (0.3.2) + date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.0) + net-protocol (0.2.1) timeout net-smtp (0.3.3) net-protocol nio4r (2.5.8) - nokogiri (1.13.9-x86_64-linux) + nokogiri (1.13.10-x86_64-linux) racc (~> 1.4) notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) open4 (1.3.4) + parser (3.1.3.0) + ast (~> 2.4.1) passenger (6.0.15) rack rake (>= 0.8.1) @@ -210,8 +222,8 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.4.3) - loofah (~> 2.3) + rails-html-sanitizer (1.4.4) + loofah (~> 2.19, >= 2.19.1) railties (7.0.4) actionpack (= 7.0.4) activesupport (= 7.0.4) @@ -225,8 +237,8 @@ GEM ffi (~> 1.0) rchardet (1.8.0) redcarpet (3.5.1) - regexp_parser (2.6.1) - reline (0.3.1) + regexp_parser (2.1.1) + reline (0.3.2) io-console (~> 0.5) rexml (3.2.5) rspec (3.12.0) @@ -235,10 +247,10 @@ GEM rspec-mocks (~> 3.12.0) rspec-core (3.12.0) rspec-support (~> 3.12.0) - rspec-expectations (3.12.0) + rspec-expectations (3.12.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-mocks (3.12.0) + rspec-mocks (3.12.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.0) @@ -251,8 +263,7 @@ GEM sprockets (> 3.0) sprockets-rails tilt - selenium-webdriver (4.6.1) - childprocess (>= 0.5, < 5.0) + selenium-webdriver (4.7.1) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) @@ -305,6 +316,7 @@ DEPENDENCIES pg (~> 1.1) puma (~> 5.0) rails (~> 7.0.4) + ruby2js! sassc-rails selenium-webdriver sprockets-rails diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb new file mode 100644 index 0000000..56f0bb4 --- /dev/null +++ b/app/controllers/members_controller.rb @@ -0,0 +1,58 @@ +class MembersController < ApplicationController + before_action :set_member, only: %i[ show edit update destroy ] + + # GET /members + def index + @members = Member.all + end + + # GET /members/1 + def show + end + + # GET /members/new + def new + @member = Member.new + end + + # GET /members/1/edit + def edit + end + + # POST /members + def create + @member = Member.new(member_params) + + if @member.save + redirect_to @member, notice: "Member was successfully created." + else + render :new, status: :unprocessable_entity + end + end + + # PATCH/PUT /members/1 + def update + if @member.update(member_params) + redirect_to @member, notice: "Member was successfully updated." + else + render :edit, status: :unprocessable_entity + end + end + + # DELETE /members/1 + def destroy + @member.destroy + redirect_to members_url, notice: "Member was successfully destroyed." + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_member + @member = Member.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def member_params + params.require(:member).permit(:name, :public) + end +end diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb new file mode 100644 index 0000000..e3fa623 --- /dev/null +++ b/app/helpers/members_helper.rb @@ -0,0 +1,2 @@ +module MembersHelper +end diff --git a/app/models/member.rb b/app/models/member.rb new file mode 100644 index 0000000..8b44e8f --- /dev/null +++ b/app/models/member.rb @@ -0,0 +1,2 @@ +class Member < ApplicationRecord +end diff --git a/app/views/layouts/_footer.haml b/app/views/layouts/_footer.haml index 9aace5e..d5b0382 100644 --- a/app/views/layouts/_footer.haml +++ b/app/views/layouts/_footer.haml @@ -1,7 +1,7 @@ %footer.bg-white{"aria-label" => "Site Footer"} .max-w-screen-xl.px-4.py-16.mx-auto.sm:px-6.lg:px-8 .lg:flex.lg:items-start.lg:gap-8 - %a.inline-flex.items-center{"aria-label" => "Hub Feenix", :href => "/", :title => "Company"} + %a.inline-flex.items-center{"aria-label" => "Hub Feenix", :href => "/", :title => "Hub Feenix"} = image_tag("feenix_lintu" , class: "h-20") .grid.grid-cols-2.gap-8.mt-8.lg:mt-0.lg:grid-cols-5.lg:gap-y-16 .col-span-2 @@ -27,14 +27,14 @@ =main.capitalize .col-span-2.sm:col-span-1 %p.font-medium.text-gray-900 Hub Feenix - %nav.mt-6{"aria-label" => "Footer Navigation - Company"} + %nav.mt-6{"aria-label" => "Footer Navigation - Hub Feenix"} %ul.space-y-4.text-sm %li %a.text-gray-700.transition.hover:opacity-75{:href => "/about"} About .col-span-2.sm:col-span-1 %p.font-medium.text-gray-900 Event Spaces - %nav.mt-6{"aria-label" => "Footer Navigation - Company"} + %nav.mt-6{"aria-label" => "Footer Navigation - Hub Feenix"} %ul.space-y-4.text-sm %li %a.text-gray-700.transition.hover:opacity-75{:href => "/retreats"} diff --git a/app/views/layouts/_header.haml b/app/views/layouts/_header.haml index fbb9bbd..c69b4ab 100644 --- a/app/views/layouts/_header.haml +++ b/app/views/layouts/_header.haml @@ -1,6 +1,6 @@ %header.px-4.py-5.mx-auto.sm:max-w-xl.md:max-w-full.lg:max-w-screen-xl.md:px-24.lg:px-8 .relative.flex.items-center.justify-between - %a.inline-flex.items-center{"aria-label" => "Hub Feenix", :href => "/", :title => "Company"} + %a.inline-flex.items-center{"aria-label" => "Hub Feenix", :href => "/", :title => "Hub Feenix"} = image_tag("feenix_lintu" , class: "h-20") %span.ml-2.text-xl.font-bold.tracking-wide.text-gray-800.uppercase Hub Feenix %ul.flex.items-center.hidden.space-x-8.lg:flex @@ -8,14 +8,14 @@ %li %a.font-medium.tracking-wide.text-gray-700.transition-colors.duration-400.hover:text-cyan-800{"aria-label" => "Our product", :href => "/#{link}", :title => link.capitalize}= link.capitalize %li - = link_to "facebook.com" do + = link_to "https://www.facebook.com/hubfeenix" , :target => "_blank" do = image_tag("fb" , class: "h-10 rounded-md") %li %a.inline-flex.items-center.justify-center.h-12.px-6.font-medium.tracking-wide.text-white.transition.duration-200.rounded-lg.shadow-md.bg-green-800.hover:bg-blue-800.focus:shadow-outline.focus:outline-none{"aria-label" => "Sign up", :href => "/", :title => "Log in or Sign up"} Login .lg:hidden.flex.items-center.justify-between .mr-20 - = link_to "facebook.com" do + = link_to "https://www.facebook.com/hubfeenix" , :target => "_blank" do = image_tag("fb" , class: "h-10 rounded-md") %button.p-2.-mr-1.transition.duration-200.rounded.focus:outline-none.focus:shadow-outline.hover:bg-deep-purple-50.focus:bg-deep-purple-50{"aria-label" => "Open Menu", :title => "Open Menu" , onclick: "menu_on();"} %svg.w-5.text-gray-600{:viewbox => "0 0 24 24"} @@ -27,7 +27,7 @@ .p-5.bg-white.border.rounded.shadow-sm .flex.items-center.justify-between.mb-4 %div - %a.inline-flex.items-center{"aria-label" => "Company", :href => "/", :title => "Company"} + %a.inline-flex.items-center{"aria-label" => "Hub Feenix", :href => "/", :title => "Hub Feenix"} = image_tag("feenix_lintu" , class: "h-20") %span.ml-2.text-xl.font-bold.tracking-wide.text-gray-800.uppercase Hub Feenix %div diff --git a/app/views/members/_form.html.haml b/app/views/members/_form.html.haml new file mode 100644 index 0000000..ac9e0e2 --- /dev/null +++ b/app/views/members/_form.html.haml @@ -0,0 +1,16 @@ += form_for @member do |f| + - if @member.errors.any? + #error_explanation + %h2= "#{pluralize(@member.errors.count, "error")} prohibited this member from being saved:" + %ul + - @member.errors.full_messages.each do |message| + %li= message + + .field + = f.label :name + = f.text_field :name + .field + = f.label :public + = f.check_box :public + .actions + = f.submit 'Save' diff --git a/app/views/members/edit.html.haml b/app/views/members/edit.html.haml new file mode 100644 index 0000000..3a227b0 --- /dev/null +++ b/app/views/members/edit.html.haml @@ -0,0 +1,7 @@ +%h1 Editing member + += render 'form' + += link_to 'Show', @member +\| += link_to 'Back', members_path diff --git a/app/views/members/index.html.haml b/app/views/members/index.html.haml new file mode 100644 index 0000000..9f0463a --- /dev/null +++ b/app/views/members/index.html.haml @@ -0,0 +1,23 @@ +%h1 Listing members + +%table + %thead + %tr + %th Name + %th Public + %th + %th + %th + + %tbody + - @members.each do |member| + %tr + %td= member.name + %td= member.public + %td= link_to 'Show', member + %td= link_to 'Edit', edit_member_path(member) + %td= link_to 'Destroy', member, method: :delete, data: { confirm: 'Are you sure?' } + +%br + += link_to 'New Member', new_member_path diff --git a/app/views/members/new.html.haml b/app/views/members/new.html.haml new file mode 100644 index 0000000..a71d1ef --- /dev/null +++ b/app/views/members/new.html.haml @@ -0,0 +1,5 @@ +%h1 New member + += render 'form' + += link_to 'Back', members_path diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml new file mode 100644 index 0000000..1f22a3c --- /dev/null +++ b/app/views/members/show.html.haml @@ -0,0 +1,12 @@ +%p#notice= notice + +%p + %b Name: + = @member.name +%p + %b Public: + = @member.public + += link_to 'Edit', edit_member_path(@member) +\| += link_to 'Back', members_path diff --git a/config/routes.rb b/config/routes.rb index e3f4df7..9888d9e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :members mount Merged::Engine => "/merged" diff --git a/db/migrate/20221220150444_create_members.rb b/db/migrate/20221220150444_create_members.rb new file mode 100644 index 0000000..d6a217f --- /dev/null +++ b/db/migrate/20221220150444_create_members.rb @@ -0,0 +1,10 @@ +class CreateMembers < ActiveRecord::Migration[7.0] + def change + create_table :members do |t| + t.string :name + t.boolean :public + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..45630ff --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,24 @@ +# 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. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[7.0].define(version: 2022_12_20_150444) do + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "members", force: :cascade do |t| + t.string "name" + t.boolean "public" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/test/controllers/members_controller_test.rb b/test/controllers/members_controller_test.rb new file mode 100644 index 0000000..3e28d41 --- /dev/null +++ b/test/controllers/members_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class MembersControllerTest < ActionDispatch::IntegrationTest + setup do + @member = members(:one) + end + + test "should get index" do + get members_url + assert_response :success + end + + test "should get new" do + get new_member_url + assert_response :success + end + + test "should create member" do + assert_difference("Member.count") do + post members_url, params: { member: { name: @member.name, public: @member.public } } + end + + assert_redirected_to member_url(Member.last) + end + + test "should show member" do + get member_url(@member) + assert_response :success + end + + test "should get edit" do + get edit_member_url(@member) + assert_response :success + end + + test "should update member" do + patch member_url(@member), params: { member: { name: @member.name, public: @member.public } } + assert_redirected_to member_url(@member) + end + + test "should destroy member" do + assert_difference("Member.count", -1) do + delete member_url(@member) + end + + assert_redirected_to members_url + end +end diff --git a/test/fixtures/members.yml b/test/fixtures/members.yml new file mode 100644 index 0000000..5eef320 --- /dev/null +++ b/test/fixtures/members.yml @@ -0,0 +1,9 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + public: false + +two: + name: MyString + public: false diff --git a/test/models/member_test.rb b/test/models/member_test.rb new file mode 100644 index 0000000..4fec230 --- /dev/null +++ b/test/models/member_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class MemberTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/members_test.rb b/test/system/members_test.rb new file mode 100644 index 0000000..ed88c54 --- /dev/null +++ b/test/system/members_test.rb @@ -0,0 +1,43 @@ +require "application_system_test_case" + +class MembersTest < ApplicationSystemTestCase + setup do + @member = members(:one) + end + + test "visiting the index" do + visit members_url + assert_selector "h1", text: "Members" + end + + test "should create member" do + visit members_url + click_on "New member" + + fill_in "Name", with: @member.name + check "Public" if @member.public + click_on "Create Member" + + assert_text "Member was successfully created" + click_on "Back" + end + + test "should update Member" do + visit member_url(@member) + click_on "Edit this member", match: :first + + fill_in "Name", with: @member.name + check "Public" if @member.public + click_on "Update Member" + + assert_text "Member was successfully updated" + click_on "Back" + end + + test "should destroy Member" do + visit member_url(@member) + click_on "Destroy this member", match: :first + + assert_text "Member was successfully destroyed" + end +end